public void ExecuteFullTest() { var operation = new AddExchangeOperation() .SetName("bar") .SetType(ExchangeType.Topic) .SetAutoDelete(true) .SetDurable(true) .AddArgument("foo", "foo-bar") .AddExchangeBind("foo", "#"); var server = new RabbitServer(); var connectionFactory = new FakeConnectionFactory(server); using (var connection = connectionFactory.CreateConnection()) { operation.Execute(connection, string.Empty); } Assert.AreEqual(1, server.Exchanges.Count); var exchange = server.Exchanges.Values.First(); Assert.AreEqual("bar", exchange.Name); Assert.AreEqual(ExchangeType.Topic, exchange.Type); Assert.IsTrue(exchange.IsAutoDelete); Assert.IsTrue(exchange.IsDurable); Assert.AreEqual(1, exchange.Arguments.Count); Assert.IsTrue(exchange.Arguments.Contains("foo")); Assert.AreEqual("foo-bar", exchange.Arguments["foo"]); Assert.AreEqual(0, exchange.Bindings.Count); //Exchange-to-exchange bindings not supported in fakes... }
public void ExecuteTest() { var addBarQueueOperation = new AddQueueOperation() .SetName("bar"); var addFooExchangeOperation = new AddExchangeOperation() .SetName("foo"); var addTstQueueOperation = new AddQueueOperation() .SetName("tst") .AddQueueBind("foo", "bar"); var moveDataOperation = new MoveDataToExchangeOperation() .SetSourceQueueName("bar") .SetDestinationExchangeName("foo"); var server = new RabbitServer(); var connectionFactory = new FakeConnectionFactory(server); using (var connection = connectionFactory.CreateConnection()) { addBarQueueOperation.Execute(connection, string.Empty); addFooExchangeOperation.Execute(connection, string.Empty); addTstQueueOperation.Execute(connection, string.Empty); using (var channel = connection.CreateModel()) { channel.ExchangeDeclare("", ExchangeType.Direct, true); channel.QueueBind("bar", "", "bar", null); for (int i = 0; i < 10; i++) { var props = channel.CreateBasicProperties(); props.Headers = new Dictionary <string, object>(); channel.BasicPublish("", "bar", false, props, Encoding.UTF8.GetBytes($"message{i}")); } } Assert.AreEqual(10, server.Queues.Values.First(x => x.Name == "bar").Messages.Count); Assert.AreEqual(0, server.Queues.Values.First(x => x.Name == "tst").Messages.Count); moveDataOperation.Execute(connection, string.Empty); Assert.AreEqual(0, server.Queues.Values.First(x => x.Name == "bar").Messages.Count); Assert.AreEqual(10, server.Queues.Values.First(x => x.Name == "tst").Messages.Count); } }
public void ExecuteTest() { var addOperation = new AddExchangeOperation() .SetName("bar") .SetType(ExchangeType.Topic); var delOperation = new DeleteExchangeOperation() .SetName("bar"); var server = new RabbitServer(); var connectionFactory = new FakeConnectionFactory(server); using (var connection = connectionFactory.CreateConnection()) { addOperation.Execute(connection, string.Empty); delOperation.Execute(connection, string.Empty); } Assert.AreEqual(0, server.Exchanges.Count); }
public void ExecuteFullTest() { var exchangeOperation = new AddExchangeOperation() .SetName("foo") .SetType(ExchangeType.Topic); var operation = new AddQueueOperation() .SetName("bar") .SetAutoDelete() .SetDurable(true) .SetExclusive() .AddArgument("foo", "foo-bar") .AddQueueBind("foo", "#"); var server = new RabbitServer(); var connectionFactory = new FakeConnectionFactory(server); using (var connection = connectionFactory.CreateConnection()) { exchangeOperation.Execute(connection, string.Empty); operation.Execute(connection, string.Empty); } Assert.AreEqual(1, server.Queues.Count); var queue = server.Queues.Values.First(); Assert.AreEqual("bar", queue.Name); Assert.IsTrue(queue.IsAutoDelete); Assert.IsTrue(queue.IsDurable); Assert.IsTrue(queue.IsExclusive); Assert.AreEqual(1, queue.Arguments.Count); Assert.IsTrue(queue.Arguments.ContainsKey("foo")); Assert.AreEqual("foo-bar", queue.Arguments["foo"]); Assert.AreEqual(1, queue.Bindings.Count); var binding = queue.Bindings.First(); Assert.AreEqual("foo", binding.Value.Exchange.Name); Assert.AreEqual("bar", binding.Value.Queue.Name); Assert.AreEqual("#", binding.Value.RoutingKey); }