Exemple #1
0
        public void When_ackOnRead_is_Set_and_ack_fails_then_exception_is_thrown()
        {
            var brokeredMessageList = new List <IBrokeredMessageWrapper>();
            var message1            = new Mock <IBrokeredMessageWrapper>();
            var mockMessageReceiver = new Mock <IServiceBusReceiverProvider>();

            mockMessageReceiver.Setup(x => x.Get("topic", "subscription", ServiceBusReceiveMode.PeekLock)).Returns(_messageReceiver.Object);

            var lockToken = Guid.NewGuid().ToString();

            message1.Setup(x => x.MessageBodyValue).Returns((byte[])null);
            message1.Setup(m => m.ApplicationProperties).Returns(new Dictionary <string, object>()
            {
                { "MessageType", "MT_EVENT" }
            });
            message1.Setup(m => m.LockToken).Returns(lockToken);

            brokeredMessageList.Add(message1.Object);

            _messageReceiver.Setup(x => x.Receive(10, TimeSpan.FromMilliseconds(400))).Returns(Task.FromResult <IEnumerable <IBrokeredMessageWrapper> >(brokeredMessageList));
            _messageReceiver.Setup(x => x.Complete(lockToken)).Throws(new Exception());

            var azureServiceBusConsumer = new AzureServiceBusConsumer("topic", "subscription", _mockMessageProducer.Object,
                                                                      _nameSpaceManagerWrapper.Object, mockMessageReceiver.Object, makeChannels: OnMissingChannel.Create, receiveMode: ServiceBusReceiveMode.PeekLock);

            Message[] result = azureServiceBusConsumer.Receive(400);

            var msg = result.First();

            Assert.Throws <Exception>(() => azureServiceBusConsumer.Acknowledge(msg));
        }
Exemple #2
0
        public void When_acknowledge_is_called_the_complete_method_is_called_with_the_correct_lock_token()
        {
            var messageLockTokenOne = Guid.NewGuid().ToString();

            var messageHeader = new MessageHeader(Guid.NewGuid(), "topic", MessageType.MT_EVENT);

            var message = new Message(messageHeader, new MessageBody("body"));

            message.Header.Bag.Add("LockToken", messageLockTokenOne);

            _azureServiceBusConsumer.Acknowledge(message);

            _messageReceiver.Verify(x => x.Complete(messageLockTokenOne), Times.Once);
        }