public void Should_call_ack_on_nested_subscriptions_with_all_delivery_tag() { // Arrange var channel = Substitute.For <IModel>(); channel.IsOpen.Returns(true); var subs = new CompositeSubscription(); var subscription = new Subscription { ConsumerTag = "ConsumerTag", QueueName = "QueueName", SubscriptionName = "SubscriptionName" }; subscription.SetChannel(channel); subs.AddSubscription(subscription); // Action Subscription.OutstandingDeliveryTags["ConsumerTag"] = new List <ulong>(); Subscription.OutstandingDeliveryTags["ConsumerTag"].AddRange(new ulong[] { 1, 2, 3, 4, 5 }); subs.Ack("ConsumerTag", new[] { (ulong)1, (ulong)2, (ulong)3, (ulong)4, (ulong)5 }); // Assert channel.Received().BasicAck(5, true); }
public void Should_call_Nack_on_nested_subscriptions_with_all_delivery_tag() { // Arrange var channel = Substitute.For <IModel>(); channel.IsOpen.Returns(true); var subs = new CompositeSubscription(); var subscription = new Subscription { ConsumerTag = "ConsumerTag", QueueName = "QueueName", SubscriptionName = "SubscriptionName" }; subscription.SetChannel(channel); subs.AddSubscription(subscription); // Action subs.Nack("ConsumerTag", new[] { (ulong)1, (ulong)2, (ulong)3, (ulong)4, (ulong)5 }, false); // Assert channel.Received().BasicNack(1, false, false); channel.Received().BasicNack(2, false, false); channel.Received().BasicNack(3, false, false); channel.Received().BasicNack(4, false, false); channel.Received().BasicNack(5, false, false); }
public void Should_not_ack_if_not_auto_ack() { // Arrange var waitHandler = new ManualResetEvent(false); var queue = Substitute.For <IInMemoryPriorityQueue <GenericPriorityMessage <BasicDeliverEventArgs> > >(); queue.When(x => x.Dequeue()).Do(callInfo => waitHandler.WaitOne()); var model = Substitute.For <IModel>(); model.IsOpen.Returns(true); var handler = Substitute.For <IMessageHandler>(); var subscription = new CompositeSubscription(); subscription.AddSubscription(new Subscription(model) { ConsumerTag = "ConsumerTag" }); var consumer = new PriorityBurrowConsumer(model, handler, Substitute.For <IRabbitWatcher>(), false, 1); consumer.Init(queue, subscription, 1, Guid.NewGuid().ToString()); consumer.Ready(); // Action handler.HandlingComplete += Raise.Event <MessageHandlingEvent>(new BasicDeliverEventArgs { ConsumerTag = "ConsumerTag" }); // Assert model.DidNotReceive().BasicAck(Arg.Any <ulong>(), Arg.Any <bool>()); waitHandler.Set(); consumer.Dispose(); }
// ReSharper disable InconsistentNaming public void Should_throw_exception_if_privided_null_object() // ReSharper restore InconsistentNaming { // Arrange var subs = new CompositeSubscription(); // Action subs.AddSubscription(null); // Assert }
public void Should_return_subscription_by_consumer_tag() { // Arrange var subs = new CompositeSubscription(); var subscription = new Subscription { ConsumerTag = "ConsumerTag", QueueName = "QueueName", SubscriptionName = "SubscriptionName" }; subs.AddSubscription(subscription); // Action & Assert Assert.AreSame(subscription, subs.GetByConsumerTag("ConsumerTag")); Assert.IsNull(subs.GetByConsumerTag("ConsumerTag2")); }
public void Should_throw_SubscriptionNotFoundException_if_subscription_not_found() { // Arrange var channel = Substitute.For <IModel>(); channel.IsOpen.Returns(true); var subs = new CompositeSubscription(); var subscription = new Subscription { ConsumerTag = "ConsumerTag", QueueName = "QueueName", SubscriptionName = "SubscriptionName" }; subscription.SetChannel(channel); subs.AddSubscription(subscription); // Action subs.NackAllOutstandingMessages("ConsumerTagNotFound", true); }
public void Should_call_Nack_on_nested_subscriptions() { // Arrange var channel = Substitute.For <IModel>(); channel.IsOpen.Returns(true); var subs = new CompositeSubscription(); var subscription = new Subscription { ConsumerTag = "ConsumerTag", QueueName = "QueueName", SubscriptionName = "SubscriptionName" }; subscription.SetChannel(channel); subs.AddSubscription(subscription); // Action subs.Nack("ConsumerTag", 1, false); // Assert channel.Received().BasicNack(1, false, false); }
public void Should_Nack_with_provided_delivery_tag_with_multiple_flag() { // Arrange var channel = Substitute.For <IModel>(); channel.IsOpen.Returns(true); var subs = new CompositeSubscription(); var subscription = new Subscription { ConsumerTag = "ConsumerTag", QueueName = "QueueName", SubscriptionName = "SubscriptionName" }; subscription.SetChannel(channel); subs.AddSubscription(subscription); // Action subs.NackAllUpTo("ConsumerTag", 10, false); // Assert channel.Received(1).BasicNack(10, true, false); }
public void Should_call_AckAllOutstandingMessages_on_nested_subscription() { // Arrange var channel = Substitute.For <IModel>(); channel.IsOpen.Returns(true); var subs = new CompositeSubscription(); var subscription = new Subscription { ConsumerTag = "ConsumerTag", QueueName = "QueueName", SubscriptionName = "SubscriptionName" }; subscription.SetChannel(channel); subs.AddSubscription(subscription); // Action subs.AckAllOutstandingMessages("ConsumerTag"); // Assert channel.Received().BasicAck(0, true); }