public void HandleMessagePaused() { var scheduleId = Guid.NewGuid(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); ravenDocStore.Expect(r => r.GetStore()).Return(DocumentStore); var tracker = new ScheduleTracker { RavenStore = ravenDocStore }; using (var session = DocumentStore.OpenSession()) { session.Store(new ScheduleTrackingData { ScheduleId = scheduleId, MessageStatus = MessageStatus.Scheduled }, scheduleId.ToString()); session.SaveChanges(); } var schedulePaused = new MessageSchedulePaused{ ScheduleId = scheduleId }; tracker.Handle(schedulePaused); using (var session = DocumentStore.OpenSession()) { var scheduleTracking = session.Load<ScheduleTrackingData>(scheduleId.ToString()); Assert.That(scheduleTracking.MessageStatus, Is.EqualTo(MessageStatus.Paused)); } }
public void CoordinateMessagesOneMessageScheduled() { var coordinatorId = Guid.NewGuid(); const string updatedNumber = "04040044"; using (var session = DocumentStore.OpenSession()) { var message = new CoordinatorCreated { CoordinatorId = coordinatorId, ScheduledMessages = new List<MessageSchedule> { new MessageSchedule { Number = updatedNumber, ScheduledTimeUtc = DateTime.Now.AddMinutes(5)}, new MessageSchedule { Number = "07777777", ScheduledTimeUtc = DateTime.Now.AddMinutes(10)} } }; var coordinatorTrackingData = new CoordinatorTrackingData { CoordinatorId = message.CoordinatorId, MessageStatuses = message.ScheduledMessages .Select(s => new MessageSendingStatus { Number = s.Number, ScheduledSendingTimeUtc = s.ScheduledTimeUtc }). ToList() }; session.Store(coordinatorTrackingData, message.CoordinatorId.ToString()); session.SaveChanges(); } var smsScheduled = new SmsScheduled { CoordinatorId = coordinatorId, ScheduleSendingTimeUtc = DateTime.UtcNow }; var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); ravenDocStore.Expect(r => r.GetStore()).Return(DocumentStore); var coordinatorTracker = new ScheduleTracker { RavenStore = ravenDocStore }; coordinatorTracker.Handle(smsScheduled); using (var session = DocumentStore.OpenSession()) { var trackingData = session.Load<CoordinatorTrackingData>(coordinatorId.ToString()); var updatedMessageData = trackingData.MessageStatuses.First(m => m.Number == updatedNumber); Assert.That(updatedMessageData.Status, Is.EqualTo(MessageStatusTracking.Scheduled)); Assert.That(updatedMessageData.ScheduledSendingTimeUtc, Is.EqualTo(smsScheduled.ScheduleSendingTimeUtc)); Assert.That(updatedMessageData.ActualSentTimeUtc, Is.Null); Assert.That(updatedMessageData.Cost, Is.Null); } }
public void CoordinateMessagesOneMessagePausedCurrentStatusSentThrowsException() { var coordinatorId = Guid.NewGuid(); const string updatedNumber = "04040044"; using (var session = DocumentStore.OpenSession()) { var message = new CoordinatorCreated { CoordinatorId = coordinatorId, ScheduledMessages = new List<MessageSchedule> { new MessageSchedule { Number = updatedNumber, ScheduledTimeUtc = DateTime.Now.AddMinutes(5)}, new MessageSchedule { Number = "07777777", ScheduledTimeUtc = DateTime.Now.AddMinutes(10)} } }; var coordinatorTrackingData = new CoordinatorTrackingData { CoordinatorId = message.CoordinatorId, MessageStatuses = message.ScheduledMessages .Select(s => new MessageSendingStatus { Number = s.Number, ScheduledSendingTimeUtc = s.ScheduledTimeUtc, Status = MessageStatusTracking.CompletedSuccess }). ToList() }; session.Store(coordinatorTrackingData, message.CoordinatorId.ToString()); session.SaveChanges(); } var messagePaused = new MessageSchedulePaused { CoordinatorId = coordinatorId }; var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); ravenDocStore.Expect(r => r.GetStore()).Return(DocumentStore); var coordinatorTracker = new ScheduleTracker { RavenStore = ravenDocStore }; Assert.That(() => coordinatorTracker.Handle(messagePaused), Throws.Exception.With.Message.EqualTo("Cannot record pausing of message - it is already recorded as complete.")); }
public void HandleMessageScheduled() { var scheduleId = Guid.NewGuid(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); ravenDocStore.Expect(r => r.GetStore()).Return(DocumentStore); var tracker = new ScheduleTracker { RavenStore = ravenDocStore }; var scheduleCreated = new SmsScheduled {ScheduleMessageId = scheduleId}; tracker.Handle(scheduleCreated); using (var session = DocumentStore.OpenSession()) { var scheduleTracking = session.Load<ScheduleTrackingData>(scheduleId.ToString()); Assert.That(scheduleTracking.SmsData, Is.EqualTo(scheduleCreated.SmsData)); Assert.That(scheduleTracking.SmsMetaData, Is.EqualTo(scheduleCreated.SmsMetaData)); Assert.That(scheduleTracking.ScheduleId, Is.EqualTo(scheduleCreated.ScheduleMessageId)); Assert.That(scheduleTracking.MessageStatus, Is.EqualTo(MessageStatus.Scheduled)); } }