Skip to content

Commit 447ed39

Browse files
author
Emile Joubert
committed
Add tests and simple queue and exchange delete methods
1 parent 2291e4e commit 447ed39

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

projects/client/RabbitMQ.Client/src/client/api/IModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ void ExchangeDelete(string exchange,
181181
[AmqpNowaitArgument(null)]
182182
bool nowait);
183183

184+
///<summary>(Spec method) Delete an exchange.</summary>
185+
[AmqpMethodDoNotImplement(null)]
186+
void ExchangeDelete(string exchange);
187+
184188
///<summary>(Spec method) Declare a queue.</summary>
185189
///<remarks>
186190
///The queue is declared non-passive, non-durable,
@@ -260,6 +264,15 @@ uint QueueDelete(string queue,
260264
[AmqpNowaitArgument(null, "0xFFFFFFFF")]
261265
bool nowait);
262266

267+
///<summary>(Spec method) Delete a queue.</summary>
268+
///<remarks>
269+
///Returns the number of messages purged during queue
270+
///deletion.
271+
///</remarks>
272+
[AmqpMethodDoNotImplement(null)]
273+
[return: AmqpFieldMapping(null, "messageCount")]
274+
uint QueueDelete(string queue);
275+
263276
///<summary>Start a Basic content-class consumer.</summary>
264277
///<remarks>
265278
///The consumer is started with noAck=false (i.e. BasicAck is required),

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ public abstract void ExchangeDelete(string exchange,
533533
bool ifUnused,
534534
bool nowait);
535535

536+
public void ExchangeDelete(string exchange)
537+
{
538+
ExchangeDelete(exchange, false, false);
539+
}
540+
536541
//TODO: Mark these as virtual, maybe the model has an optimized way
537542
// of dealing with missing parameters.
538543
public string QueueDeclare()
@@ -542,7 +547,7 @@ public string QueueDeclare()
542547

543548
public string QueueDeclare(string queue)
544549
{
545-
return _Private_QueueDeclare(queue, true, false, false, false, false, null);
550+
return _Private_QueueDeclare(queue, false, false, false, false, false, null);
546551
}
547552

548553
public string QueueDeclarePassive(string queue)
@@ -588,6 +593,11 @@ public abstract uint QueueDelete(string queue,
588593
bool ifEmpty,
589594
bool nowait);
590595

596+
public uint QueueDelete(string queue)
597+
{
598+
return QueueDelete(queue, false, false, false);
599+
}
600+
591601
public string BasicConsume(string queue,
592602
IDictionary filter,
593603
IBasicConsumer consumer)

projects/client/Unit/src/unit/TestPassiveDeclare.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
// Contributor(s): ______________________________________.
5555
//
5656
//---------------------------------------------------------------------------
57+
using System.Collections;
5758
using NUnit.Framework;
5859
using RabbitMQ.Client;
5960
using RabbitMQ.Client.Exceptions;
@@ -92,6 +93,21 @@ public void TestExchangePassiveDeclare()
9293
catch (OperationInterruptedException) { }
9394
}
9495

96+
[Test]
97+
public void TestExchangePassiveDeclareBeforeAndAfterDelete()
98+
{
99+
string exchangeName = GetType().FullName;
100+
ch.ExchangeDeclare(exchangeName, "direct", true);
101+
ch.ExchangeDeclarePassive(exchangeName);
102+
ch.ExchangeDelete(exchangeName);
103+
try
104+
{
105+
ch.ExchangeDeclarePassive(exchangeName);
106+
Assert.Fail("Passive declare of a deleted exchange should fail");
107+
}
108+
catch (OperationInterruptedException) { }
109+
}
110+
95111
[Test]
96112
public void TestQueuePassiveDeclare()
97113
{
@@ -102,5 +118,35 @@ public void TestQueuePassiveDeclare()
102118
}
103119
catch (OperationInterruptedException) { }
104120
}
121+
122+
[Test]
123+
public void TestServerNamedQueueDeclare()
124+
{
125+
string queueName = ch.QueueDeclare();
126+
Assert.AreEqual(queueName, ch.QueueDeclarePassive(queueName));
127+
}
128+
129+
[Test]
130+
public void TestQueueDeclare()
131+
{
132+
string queueName = GetType().FullName;
133+
string queueNameServer = ch.QueueDeclare(
134+
queueName, true, true, true, new Hashtable());
135+
Assert.AreEqual(queueName, queueNameServer);
136+
Assert.AreEqual(queueName, ch.QueueDeclarePassive(queueName));
137+
}
138+
139+
[Test]
140+
public void TestQueueDeclareAfterDelete()
141+
{
142+
try
143+
{
144+
string queueName = ch.QueueDeclare();
145+
Assert.AreEqual(0, ch.QueueDelete(queueName));
146+
ch.QueueDeclarePassive(queueName);
147+
Assert.Fail("Passive declare of an unknown queue should fail");
148+
}
149+
catch (OperationInterruptedException) { }
150+
}
105151
}
106152
}

0 commit comments

Comments
 (0)