public SmsTrackingData(MessageFailedSending message) { Status = MessageTrackedStatus.Failed; SmsFailureData = message.SmsFailed; CorrelationId = message.CorrelationId; SmsData = message.SmsData; SmsMetaData = message.SmsMetaData; ConfirmationEmailAddress = message.ConfirmationEmailAddress; }
public void MessageNotSentWithEmailDefaultFromNotSentThrowsException() { var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var session = MockRepository.GenerateMock<IDocumentSession>(); ravenDocStore.Expect(r => r.GetStore().OpenSession("Configuration")) .Return(session); var mailgunConfig = new MailgunConfiguration { ApiKey = "key", DomainName = "domain", DefaultFrom = string.Empty }; session.Expect(s => s.Load<MailgunConfiguration>("MailgunConfig")).Return(mailgunConfig); var emailService = new EmailService { RavenDocStore = ravenDocStore }; var messageFailedSending = new MessageFailedSending { ConfirmationEmailAddress = "*****@*****.**", SmsData = new SmsData("mobile", "message"), SmsMetaData = new SmsMetaData { Tags = new List<string> { "a" }, Topic = "topic" } }; Assert.That(() => emailService.Handle(messageFailedSending), Throws.Exception.With.Message.EqualTo("Could not find the default 'From' sender.")); }
public void HandleMessageNotSentNoConfirmationEmail() { var messageSent = new MessageFailedSending { CorrelationId = Guid.NewGuid(), SmsFailed = new SmsFailed("232", "code", "bad"), }; var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); ravenDocStore.Expect(r => r.GetStore()).Return(DocumentStore); var smsSentAuditor = new SmsSentTracker { RavenStore = ravenDocStore }; smsSentAuditor.Handle(messageSent); using (var session = DocumentStore.OpenSession()) { var savedMessage = session.Load<SmsTrackingData>(messageSent.CorrelationId.ToString()); Assert.That(savedMessage, Is.Not.Null); } }
public void MessageSentWithEmailSendsEmail() { var mailActioner = MockRepository.GenerateMock<IMailActioner>(); var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); var session = MockRepository.GenerateMock<IDocumentSession>(); ravenDocStore.Expect(r => r.GetStore().OpenSession("Configuration")) .Return(session); var mailgunConfig = new MailgunConfiguration {ApiKey = "key", DomainName = "domain", DefaultFrom = "*****@*****.**"}; session.Expect(s => s.Load<MailgunConfiguration>("MailgunConfig")).Return(mailgunConfig); var message = new MailMessage(); mailActioner.Expect(m => m.Send(Arg<MailgunConfiguration>.Is.Equal(mailgunConfig), Arg<MailMessage>.Is.NotNull)).WhenCalled(a => message = (MailMessage)(a.Arguments[1])); var emailService = new EmailService { MailActioner = mailActioner, RavenDocStore = ravenDocStore }; var messageFailedSending = new MessageFailedSending { ConfirmationEmailAddress = "*****@*****.**", SmsData = new SmsData("mobile", "message"), SmsMetaData = new SmsMetaData { Tags = new List<string> { "a" }, Topic = "topic"}, SmsFailed = new SmsFailed("sid", "code", "message", "moreinfo", "status")}; emailService.Handle(messageFailedSending); mailActioner.VerifyAllExpectations(); Assert.That(message.From.ToString(), Is.EqualTo(mailgunConfig.DefaultFrom)); Assert.That(message.To.ToString(), Is.EqualTo(messageFailedSending.ConfirmationEmailAddress)); }
public void ScheduleSmsForSendingLaterButFails() { var scheduleSmsForSendingLater = new ScheduleSmsForSendingLater { SendMessageAtUtc = DateTime.Now.AddDays(1) }; var sagaId = Guid.NewGuid(); var messageFailed = new MessageFailedSending { SmsData = new SmsData("1", "2"), SmsFailed = new SmsFailed(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty) }; var scheduledSmsData = new ScheduledSmsData { Id = sagaId, Originator = "place", OriginalMessageId = Guid.NewGuid().ToString(), OriginalMessage = new ScheduleSmsForSendingLater { SmsData = new SmsData("1", "msg"), SmsMetaData = new SmsMetaData() } }; Test.Initialize(); Test.Saga<ScheduleSms>() .WithExternalDependencies(a => a.Data = scheduledSmsData) .ExpectTimeoutToBeSetAt<ScheduleSmsTimeout>((state, timeout) => timeout == scheduleSmsForSendingLater.SendMessageAtUtc) //.ExpectSend<ScheduleCreated>() .When(s => s.Handle(scheduleSmsForSendingLater)) .ExpectSend<SendOneMessageNow>() .WhenSagaTimesOut() .ExpectPublish<ScheduledSmsFailed>() //.ExpectSend<ScheduleFailed>() .When(s => s.Handle(messageFailed)) .AssertSagaCompletionIs(true); }
public void MessageNotSentNoEmailNoAction() { var emailService = new EmailService(); var messageFailedSending = new MessageFailedSending(); emailService.Handle(messageFailedSending); }
public void ScheduleSmsForSendingLaterButFails() { var scheduleSmsForSendingLater = new ScheduleSmsForSendingLater { SendMessageAtUtc = DateTime.Now.AddDays(1), ScheduleMessageId = Guid.NewGuid()}; var sagaId = Guid.NewGuid(); var messageFailed = new MessageFailedSending { SmsData = new SmsData("1", "2"), SmsFailed = new SmsFailed(string.Empty, string.Empty, string.Empty) }; var ravenDocStore = MockRepository.GenerateMock<IRavenDocStore>(); ravenDocStore.Expect(r => r.GetStore().OpenSession("SmsTracking")).Return(DocumentStore.OpenSession()); StoreDocument(new ScheduleTrackingData { ScheduleId = scheduleSmsForSendingLater.ScheduleMessageId, MessageStatus = MessageStatus.WaitingForScheduling }, scheduleSmsForSendingLater.ScheduleMessageId.ToString()); var scheduledSmsData = new ScheduledSmsData { Id = sagaId, Originator = "place", OriginalMessageId = Guid.NewGuid().ToString(), OriginalMessage = new ScheduleSmsForSendingLater { SmsData = new SmsData("1", "msg"), SmsMetaData = new SmsMetaData() } }; Test.Initialize(); Test.Saga<ScheduleSms>() .WithExternalDependencies(a => { a.Data = scheduledSmsData; a.RavenDocStore = ravenDocStore; }) .ExpectTimeoutToBeSetAt<ScheduleSmsTimeout>((state, timeout) => timeout == scheduleSmsForSendingLater.SendMessageAtUtc) .When(s => s.Handle(scheduleSmsForSendingLater)) .ExpectSend<SendOneMessageNow>() .WhenSagaTimesOut() .ExpectPublish<ScheduledSmsFailed>() .When(s => s.Handle(messageFailed)) .AssertSagaCompletionIs(true); var scheduleTrackingData = GetSchedule(scheduleSmsForSendingLater.ScheduleMessageId.ToString()); Assert.That(scheduleTrackingData.MessageStatus, Is.EqualTo(MessageStatus.Failed)); }