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 MessagesAreNotAutoCompleted() { var subscriber = new CandidateUserUpdateSubscriberMock(ServiceBusMessageStates.Complete); var subscribers = new List <IServiceBusSubscriber <CandidateUserUpdate> > { subscriber }; var topicClient = new Mock <ITopicClient>(); var subscriptionClient = new Mock <ISubscriptionClient>(); 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.Object); var broker = new AzureServiceBusMessageBrokerBuilder <CandidateUserUpdate>().With(subscribers).With(clientFactory).Build(); broker.Subscribe(); //Subscription should be set up with AutoComplete = false subscriptionClient.Verify(c => c.OnMessage(It.IsAny <Action <IBrokeredMessage> >(), It.Is <OnMessageOptions>(o => !o.AutoComplete))); }
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); }