コード例 #1
0
 public SmsTrackingData(MessageFailedSending message)
 {
     Status = MessageTrackedStatus.Failed;
     SmsFailureData = message.SmsFailed;
     CorrelationId = message.CorrelationId;
     SmsData = message.SmsData;
     SmsMetaData = message.SmsMetaData;
     ConfirmationEmailAddress = message.ConfirmationEmailAddress;
 }
コード例 #2
0
        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."));
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public void MessageNotSentNoEmailNoAction()
 {
     var emailService = new EmailService();
     var messageFailedSending = new MessageFailedSending();
     emailService.Handle(messageFailedSending);
 }
コード例 #7
0
        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));
        }