public void SubsequentRequeuedMessagesAreScheduledForFiveMinutesHence()
        {
            var subscriber  = new CandidateUserUpdateSubscriberMock(ServiceBusMessageStates.Requeue);
            var subscribers = new List <IServiceBusSubscriber <CandidateUserUpdate> > {
                subscriber
            };
            var             topicClient        = new Mock <ITopicClient>();
            BrokeredMessage newBrokeredMessage = null;

            topicClient.Setup(c => c.Send(It.IsAny <BrokeredMessage>())).Callback <BrokeredMessage>(bm => newBrokeredMessage = bm);
            var subscriptionClient = new SubscriptionClientStub();
            var clientFactory      = new Mock <IClientFactory>();

            clientFactory.Setup(f => f.CreateFromConnectionString(It.IsAny <string>(), It.IsAny <string>())).Returns(topicClient.Object);
            clientFactory.Setup(f => f.CreateFromConnectionString(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ReceiveMode>())).Returns(subscriptionClient);
            var broker = new AzureServiceBusMessageBrokerBuilder <CandidateUserUpdate>().With(subscribers).With(clientFactory).Build();

            broker.Subscribe();

            var message = new Mock <IBrokeredMessage>();

            message.Setup(m => m.ScheduledEnqueueTimeUtc).Returns(DateTime.UtcNow);
            message.Setup(m => m.GetBody <string>()).Returns("");
            subscriptionClient.Send(message.Object);
            //Original messages is completed
            message.Verify(m => m.Complete(), Times.Once);
            //New message has been created and assigned a scheduled time 5 minutes in the future
            newBrokeredMessage.Should().NotBeNull();
            newBrokeredMessage.ScheduledEnqueueTimeUtc.Should().BeCloseTo(DateTime.UtcNow.AddSeconds(300), 1000);
        }
        public void MessagesAreCompletedByTheBroker()
        {
            var subscriber  = new CandidateUserUpdateSubscriberMock(ServiceBusMessageStates.Complete);
            var subscribers = new List <IServiceBusSubscriber <CandidateUserUpdate> > {
                subscriber
            };
            var topicClient        = new Mock <ITopicClient>();
            var subscriptionClient = new SubscriptionClientStub();
            var clientFactory      = new Mock <IClientFactory>();

            clientFactory.Setup(f => f.CreateFromConnectionString(It.IsAny <string>(), It.IsAny <string>())).Returns(topicClient.Object);
            clientFactory.Setup(f => f.CreateFromConnectionString(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <ReceiveMode>())).Returns(subscriptionClient);
            var broker = new AzureServiceBusMessageBrokerBuilder <CandidateUserUpdate>().With(subscribers).With(clientFactory).Build();

            broker.Subscribe();

            var message = new Mock <IBrokeredMessage>();

            message.Setup(m => m.GetBody <string>()).Returns("");
            subscriptionClient.Send(message.Object);
            message.Verify(m => m.Complete(), Times.Once);
        }