public void CoordinatorSeparatedByTimeSpanReturnsDetails() { var model = new CoordinatedSharedMessageModel { Numbers= "04040404040", Message = "Message", StartTime = DateTime.Now.AddHours(2), TimeSeparatorSeconds = 5000, Tags = "tag1, tag2", Topic = "New Feature!" }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); mapper.Expect(m => m.MapToTrickleSpacedByPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything)).Return(new TrickleSmsWithDefinedTimeBetweenEachMessage()); var trickleMessage = new TrickleSmsWithDefinedTimeBetweenEachMessage(); bus.Expect(b => b.Send(Arg<TrickleSmsWithDefinedTimeBetweenEachMessage>.Is.NotNull)) .WhenCalled(i => trickleMessage = (TrickleSmsWithDefinedTimeBetweenEachMessage) ((object[]) (i.Arguments[0]))[0]); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(trickleMessage.CoordinatorId, Is.Not.EqualTo(Guid.Empty)); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); }
public void TrickleThreeMessagesSpacedAMinuteApartPausedAfterFirstThenResumed() { var startTime = DateTime.Now.AddHours(3); var timeSpacing = new TimeSpan(0, 10, 0); var trickleMultipleMessages = new TrickleSmsWithDefinedTimeBetweenEachMessage { StartTimeUtc = startTime, Messages = new List<SmsData> { new SmsData("mobile#1", "message"), new SmsData("mobile#2", "message2"), new SmsData("mobile#3", "message3") }, TimeSpacing = timeSpacing }; var sagaData = new CoordinateSmsSchedulingData { Id = Guid.NewGuid(), Originator = "o", OriginalMessageId = "i" }; Test.Initialize(); Test.Saga<CoordinateSmsScheduler>() .WithExternalDependencies(d => d.Data = sagaData) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SmsData.Mobile == trickleMultipleMessages.Messages[0].Mobile) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SmsData.Mobile == trickleMultipleMessages.Messages[1].Mobile) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SmsData.Mobile == trickleMultipleMessages.Messages[2].Mobile) .When(s => s.Handle(trickleMultipleMessages)) .When(s => s.Handle(new ScheduledSmsSent { ConfirmationData = new SmsConfirmationData("r", DateTime.Now, 1m), ScheduledSmsId = sagaData.ScheduledMessageStatus[0].ScheduledSms.ScheduleMessageId })) .ExpectSend<PauseScheduledMessageIndefinitely>() .ExpectSend<PauseScheduledMessageIndefinitely>() .When(s => s.Handle(new PauseTrickledMessagesIndefinitely())) .When(s => s.Handle(new MessageSchedulePaused { ScheduleId = sagaData.ScheduledMessageStatus[1].ScheduledSms.ScheduleMessageId })) .When(s => s.Handle(new MessageSchedulePaused { ScheduleId = sagaData.ScheduledMessageStatus[2].ScheduledSms.ScheduleMessageId })) .ExpectSend<ResumeScheduledMessageWithOffset>() .ExpectSend<ResumeScheduledMessageWithOffset>() .When(s => s.Handle(new ResumeTrickledMessages())) .When(s => s.Handle(new ScheduledSmsSent { ConfirmationData = new SmsConfirmationData("r", DateTime.Now, 1m), ScheduledSmsId = sagaData.ScheduledMessageStatus[1].ScheduledSms.ScheduleMessageId })) .AssertSagaCompletionIs(false) .ExpectPublish<CoordinatorCompleted>() .When(s => s.Handle(new ScheduledSmsSent { ConfirmationData = new SmsConfirmationData("r", DateTime.Now, 1m), ScheduledSmsId = sagaData.ScheduledMessageStatus[2].ScheduledSms.ScheduleMessageId })) .AssertSagaCompletionIs(true); Assert.That(sagaData.MessagesScheduled, Is.EqualTo(3)); Assert.That(sagaData.MessagesConfirmedSentOrFailed, Is.EqualTo(3)); }
public void TrickleMessagesSpacedByTimespan_Data() { var messageList = new List<SmsData> { new SmsData("9384938", "3943lasdkf;j"), new SmsData("99999", "dj;alsdfkj") }; var trickleMessagesOverTime = new TrickleSmsWithDefinedTimeBetweenEachMessage { TimeSpacing = new TimeSpan(1000), Messages = messageList, StartTimeUtc = DateTime.Now }; var timingManager = MockRepository.GenerateMock<ICalculateSmsTiming>(); var sagaData = new CoordinateSmsSchedulingData { Originator = "originator", Id = Guid.NewGuid() }; Test.Initialize(); Test.Saga<CoordinateSmsScheduler>() .WithExternalDependencies(s => { s.TimingManager = timingManager; s.Data = sagaData; }) .ExpectSend<ScheduleSmsForSendingLater>(l => //l.Count == 2 && l.SendMessageAtUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.ToUniversalTime().Ticks && l.SmsData.Message == trickleMessagesOverTime.Messages[0].Message && l.SmsData.Mobile == trickleMessagesOverTime.Messages[0].Mobile && l.SmsMetaData == trickleMessagesOverTime.MetaData) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SendMessageAtUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.ToUniversalTime().Ticks + trickleMessagesOverTime.TimeSpacing.Ticks && l.SmsData.Message == trickleMessagesOverTime.Messages[1].Message && l.SmsData.Mobile == trickleMessagesOverTime.Messages[1].Mobile && l.SmsMetaData == trickleMessagesOverTime.MetaData) .ExpectPublish<CoordinatorCreated>(c => c.CoordinatorId == sagaData.Id && c.ScheduledMessages.Count == 2 && c.ScheduledMessages[0].Number == trickleMessagesOverTime.Messages[0].Mobile && c.ScheduledMessages[0].ScheduleMessageId == sagaData.ScheduledMessageStatus[0].ScheduledSms.ScheduleMessageId && c.ScheduledMessages[0].ScheduleMessageId != Guid.Empty && // HACK : Need to make this valid c.ScheduledMessages[0].ScheduledTimeUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.ToUniversalTime().Ticks && c.ScheduledMessages[1].Number == trickleMessagesOverTime.Messages[1].Mobile && c.ScheduledMessages[1].ScheduleMessageId == sagaData.ScheduledMessageStatus[1].ScheduledSms.ScheduleMessageId && c.ScheduledMessages[1].ScheduleMessageId != Guid.Empty && // HACK : Need to make this valid c.ScheduledMessages[1].ScheduledTimeUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.ToUniversalTime().Ticks + trickleMessagesOverTime.TimeSpacing.Ticks) .When(s => s.Handle(trickleMessagesOverTime)); Assert.That(sagaData.MessagesScheduled, Is.EqualTo(2)); Assert.That(sagaData.ScheduledMessageStatus[0].MessageStatus, Is.EqualTo(MessageStatus.WaitingForScheduling)); Assert.That(sagaData.ScheduledMessageStatus[1].MessageStatus, Is.EqualTo(MessageStatus.WaitingForScheduling)); timingManager.VerifyAllExpectations(); }
public void CreateSeparatedByTimeSpanReturnsDetails() { var model = new CoordinatedSharedMessageModel { Numbers= "04040404040, 04040402", Message = "Message", StartTime = DateTime.Now.AddHours(2), TimeSeparatorSeconds = 5000, Tags = "tag1, tag2", Topic = "New Feature!", UserTimeZone = "Australia/Sydney" }; var bus = MockRepository.GenerateMock<IBus>(); var mapper = MockRepository.GenerateMock<ICoordinatorModelToMessageMapping>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var docStore = MockRepository.GenerateMock<IDocumentStore>(); var docSession = MockRepository.GenerateMock<IDocumentSession>(); ravenDocStore.Expect(r => r.GetStore()).Return(docStore); docStore.Expect(d => d.OpenSession("Configuration")).Return(docSession); docSession.Expect(d => d.Load<CountryCodeReplacement>("CountryCodeConfig")).Return(new CountryCodeReplacement()); mapper .Expect(m => m.MapToTrickleSpacedByPeriod(Arg<CoordinatedSharedMessageModel>.Is.Anything, Arg<CountryCodeReplacement>.Is.Anything, Arg<List<string>>.Is.Anything)) .Return(new TrickleSmsWithDefinedTimeBetweenEachMessage()); var trickleMessage = new TrickleSmsWithDefinedTimeBetweenEachMessage(); bus.Expect(b => b.Send(Arg<TrickleSmsWithDefinedTimeBetweenEachMessage>.Is.NotNull)) .WhenCalled(i => trickleMessage = (TrickleSmsWithDefinedTimeBetweenEachMessage) ((object[]) (i.Arguments[0]))[0]); var controller = new CoordinatorController { ControllerContext = new ControllerContext(), Bus = bus, Mapper = mapper, RavenDocStore = ravenDocStore }; var actionResult = (RedirectToRouteResult)controller.Create(model); Assert.That(actionResult.RouteValues["action"], Is.EqualTo("Details")); Assert.That(trickleMessage.CoordinatorId, Is.Not.EqualTo(Guid.Empty)); bus.VerifyAllExpectations(); mapper.VerifyAllExpectations(); }
public void TrickleThreeMessagesSpacedAMinuteApartPausedAfterFirstThenResumed() { var coordinatorId = Guid.NewGuid(); var ravenScheduleDocuments = MockRepository.GenerateStrictMock<IRavenScheduleDocuments>(); ravenScheduleDocuments.Expect(r => r.SaveSchedules(Arg<List<ScheduleSmsForSendingLater>>.Is.Anything, Arg<Guid>.Is.Anything)); ravenScheduleDocuments.Expect(r => r.SaveCoordinator(Arg<CoordinatorCreated>.Is.Anything)); ravenScheduleDocuments.Expect(r => r.GetActiveScheduleTrackingData(coordinatorId)).Return(new List<ScheduleTrackingData> { new ScheduleTrackingData(), new ScheduleTrackingData() }); ravenScheduleDocuments.Expect(r => r.GetActiveScheduleTrackingData(coordinatorId)).Return(new List<ScheduleTrackingData> { new ScheduleTrackingData(), new ScheduleTrackingData() }); ravenScheduleDocuments.Expect(r => r.AreCoordinatedSchedulesComplete(coordinatorId)).Return(true); ravenScheduleDocuments.Expect(r => r.MarkCoordinatorAsComplete(Arg<Guid>.Is.Equal(coordinatorId), Arg<DateTime>.Is.Anything)); ravenScheduleDocuments.Expect(r => r.GetScheduleSummary(coordinatorId)).Return(new List<ScheduledMessagesStatusCountInCoordinatorIndex.ReduceResult>()); var startTime = DateTime.Now.AddHours(3); var timeSpacing = new TimeSpan(0, 10, 0); var trickleMultipleMessages = new TrickleSmsWithDefinedTimeBetweenEachMessage { StartTimeUtc = startTime, Messages = new List<SmsData> { new SmsData("mobile#1", "message"), new SmsData("mobile#2", "message2"), new SmsData("mobile#3", "message3") }, TimeSpacing = timeSpacing, CoordinatorId = coordinatorId, MetaData = new SmsMetaData() }; var sagaData = new CoordinateSmsSchedulingData { Id = Guid.NewGuid(), Originator = "o", OriginalMessageId = "i" }; Test.Initialize(); Test.Saga<CoordinateSmsScheduler>() .WithExternalDependencies(d => { d.Data = sagaData; d.RavenScheduleDocuments = ravenScheduleDocuments; }) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SmsData.Mobile == trickleMultipleMessages.Messages[0].Mobile) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SmsData.Mobile == trickleMultipleMessages.Messages[1].Mobile) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SmsData.Mobile == trickleMultipleMessages.Messages[2].Mobile) .ExpectTimeoutToBeSetAt<CoordinatorTimeout>((state, timeout) => true) .When(s => s.Handle(trickleMultipleMessages)) .ExpectSend<PauseScheduledMessageIndefinitely>() .ExpectSend<PauseScheduledMessageIndefinitely>() .When(s => s.Handle(new PauseTrickledMessagesIndefinitely())) .ExpectSend<ResumeScheduledMessageWithOffset>() .ExpectSend<ResumeScheduledMessageWithOffset>() .When(s => s.Handle(new ResumeTrickledMessages())) .AssertSagaCompletionIs(false) .ExpectPublish<CoordinatorCompleted>() .When(s => s.Timeout(new CoordinatorTimeout())) .AssertSagaCompletionIs(true); }
public void TrickleMessagesSpacedByTimespan_Data() { var messageList = new List<SmsData> { new SmsData("9384938", "3943lasdkf;j"), new SmsData("99999", "dj;alsdfkj") }; var trickleMessagesOverTime = new TrickleSmsWithDefinedTimeBetweenEachMessage { TimeSpacing = new TimeSpan(1000), Messages = messageList, StartTimeUtc = DateTime.Now, UserOlsenTimeZone = "timeZone", CoordinatorId = Guid.NewGuid(), MetaData = new SmsMetaData()}; var ravenScheduleDocuments = MockRepository.GenerateStrictMock<IRavenScheduleDocuments>(); var sendingMessages = new List<ScheduleSmsForSendingLater>(); ravenScheduleDocuments.Expect(r => r.SaveSchedules(Arg<List<ScheduleSmsForSendingLater>>.Is.NotNull, Arg<Guid>.Is.Equal(trickleMessagesOverTime.CoordinatorId))) .WhenCalled(r => sendingMessages = (List<ScheduleSmsForSendingLater>)r.Arguments[0]); ravenScheduleDocuments.Expect(r => r.SaveCoordinator(Arg<CoordinatorCreated>.Is.Anything)); var timingManager = MockRepository.GenerateMock<ICalculateSmsTiming>(); var sagaData = new CoordinateSmsSchedulingData { Originator = "originator", Id = Guid.NewGuid() }; Test.Initialize(); Test.Saga<CoordinateSmsScheduler>() .WithExternalDependencies(s => { s.TimingManager = timingManager; s.Data = sagaData; s.RavenScheduleDocuments = ravenScheduleDocuments; }) .ExpectSend<ScheduleSmsForSendingLater>(l => //l.Count == 2 && l.SendMessageAtUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.Ticks && l.SmsData.Message == trickleMessagesOverTime.Messages[0].Message && l.SmsData.Mobile == trickleMessagesOverTime.Messages[0].Mobile && l.SmsMetaData == trickleMessagesOverTime.MetaData) .ExpectSend<ScheduleSmsForSendingLater>(l => l.SendMessageAtUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.Ticks + trickleMessagesOverTime.TimeSpacing.Ticks && l.SmsData.Message == trickleMessagesOverTime.Messages[1].Message && l.SmsData.Mobile == trickleMessagesOverTime.Messages[1].Mobile && l.SmsMetaData == trickleMessagesOverTime.MetaData) .ExpectPublish<CoordinatorCreated>(c => c.CoordinatorId == trickleMessagesOverTime.CoordinatorId && c.ScheduledMessages.Count == 2 && c.ScheduledMessages[0].Number == trickleMessagesOverTime.Messages[0].Mobile && c.ScheduledMessages[0].ScheduleMessageId == sendingMessages[0].ScheduleMessageId && c.ScheduledMessages[0].ScheduleMessageId != Guid.Empty && // HACK : Need to make this valid c.ScheduledMessages[0].ScheduledTimeUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.Ticks && c.ScheduledMessages[1].Number == trickleMessagesOverTime.Messages[1].Mobile && c.ScheduledMessages[1].ScheduleMessageId == sendingMessages[1].ScheduleMessageId && c.ScheduledMessages[1].ScheduleMessageId != Guid.Empty && // HACK : Need to make this valid c.ScheduledMessages[1].ScheduledTimeUtc.Ticks == trickleMessagesOverTime.StartTimeUtc.Ticks + trickleMessagesOverTime.TimeSpacing.Ticks && c.UserOlsenTimeZone == trickleMessagesOverTime.UserOlsenTimeZone) .ExpectTimeoutToBeSetAt<CoordinatorTimeout>((state, timeout) => timeout == trickleMessagesOverTime.StartTimeUtc.Add(trickleMessagesOverTime.TimeSpacing).AddMinutes(2)) .When(s => s.Handle(trickleMessagesOverTime)); Assert.That(sendingMessages.Count, Is.EqualTo(2)); timingManager.VerifyAllExpectations(); ravenScheduleDocuments.VerifyAllExpectations(); }