Inheritance: SmsStatus
コード例 #1
0
        public void SendSingleSmsNowQueuedThenSuccess()
        {
            var sendOneMessageNow = new SendOneMessageNow();

            var smsService = MockRepository.GenerateMock<ISmsService>();

            var smsQueued = new SmsQueued("12");
            var smsSent = new SmsSent(new SmsConfirmationData("r", DateTime.Now, .44m));
            smsService.Expect(s => s.Send(sendOneMessageNow)).Return(smsQueued);
            smsService.Expect(s => s.CheckStatus(smsQueued.Sid)).Return(smsSent);

            Test.Initialize();
            Test.Saga<SmsActioner>()
                .WithExternalDependencies(a => a.SmsService = smsService)
                    .ExpectTimeoutToBeSetIn<SmsPendingTimeout>((timeoutMessage, timespan) => timespan == TimeSpan.FromSeconds(10))
                .When(a => a.Handle(sendOneMessageNow))
                    .ExpectPublish<MessageSent>()
                .WhenSagaTimesOut()
                .AssertSagaCompletionIs(true);
        }
コード例 #2
0
        public void SendSingleSmsNowQueuedTwiceThenSuccess()
        {
            var sendOneMessageNow = new SendOneMessageNow();

            var smsService = MockRepository.GenerateMock<ISmsService>();

            const string sid = "12";
            var smsQueued = new SmsQueued(sid);
            var smsSuccess = new SmsSent(new SmsConfirmationData("r", DateTime.Now, 3.3m));
            smsService.Expect(s => s.Send(sendOneMessageNow)).Return(smsQueued);
            smsService.Expect(s => s.CheckStatus(smsQueued.Sid)).Repeat.Once().Return(smsQueued);
            smsService.Expect(s => s.CheckStatus(smsQueued.Sid)).Return(smsSuccess);

            Test.Initialize();
            Test.Saga<SmsActioner.SmsActioner>()
                .WithExternalDependencies(a => a.SmsService = smsService)
                    .ExpectTimeoutToBeSetIn<SmsPendingTimeout>((timeoutMessage, timespan) => timespan == TimeSpan.FromSeconds(10))
                .When(a => a.Handle(sendOneMessageNow))
                    .ExpectNotPublish<MessageSent>()
                    .ExpectTimeoutToBeSetIn<SmsPendingTimeout>((timeoutMessage, timespan) => timespan == TimeSpan.FromSeconds(10))
                .WhenSagaTimesOut()
                    .ExpectPublish<MessageSent>()
                    .ExpectReplyToOriginator<MessageSuccessfullyDelivered>()
                    .ExpectSendLocal<MessageSuccessfullyDelivered>()
                .WhenSagaTimesOut();
        }
コード例 #3
0
        public void SendSingleSmsNowSuccess()
        {
            var sendOneMessageNow = new SendOneMessageNow();

            var smsService = MockRepository.GenerateMock<ISmsService>();
            var smsSent = new SmsSent(new SmsConfirmationData("r", DateTime.Now, 0.44m));
            smsService.Expect(s => s.Send(sendOneMessageNow)).Return(smsSent);

            Test.Initialize();
            Test.Saga<SmsActioner.SmsActioner>()
                .WithExternalDependencies(a => a.SmsService = smsService)
                    .ExpectPublish<MessageSent>()
                    .ExpectReplyToOriginator<MessageSuccessfullyDelivered>()
                    .ExpectSendLocal<MessageSuccessfullyDelivered>()
                .When(a => a.Handle(sendOneMessageNow))
                .AssertSagaCompletionIs(true);
        }
コード例 #4
0
        public void SendSingleSmsNow_SendingThenQueuedThenSuccess()
        {
            var sendOneMessageNow = new SendOneMessageNow();

            var smsService = MockRepository.GenerateMock<ISmsService>();
            var timeoutCalculator = MockRepository.GenerateMock<ITimeoutCalculator>();

            const string sid = "12";
            var smsSending = new SmsSending(sid, 0.06m);
            var smsQueued = new SmsQueued(sid);
            var smsSuccess = new SmsSent("r", DateTime.Now);
            smsService.Expect(s => s.Send(sendOneMessageNow)).Return(smsSending);
            smsService.Expect(s => s.CheckStatus(smsQueued.Sid)).Repeat.Once().Return(smsQueued);
            smsService.Expect(s => s.CheckStatus(smsQueued.Sid)).Return(smsSuccess);
            var timeoutTimespan = new TimeSpan();
            timeoutCalculator.Expect(t => t.RequiredTimeout(Arg<int>.Is.Anything)).Return(timeoutTimespan);

            Test.Initialize();
            Test.Saga<SmsActioner.SmsActioner>()
                .WithExternalDependencies(a =>
                {
                    a.SmsService = smsService;
                    a.TimeoutCalculator = timeoutCalculator;
                })
                    .ExpectTimeoutToBeSetIn<SmsPendingTimeout>((timeoutMessage, timespan) => timespan == timeoutTimespan)
                .When(a => a.Handle(sendOneMessageNow))
                    .ExpectNotPublish<MessageSent>()
                    .ExpectTimeoutToBeSetIn<SmsPendingTimeout>((timeoutMessage, timespan) => timespan == timeoutTimespan)
                .WhenSagaTimesOut()
                    .ExpectPublish<MessageSent>()
                .WhenSagaTimesOut();
        }
コード例 #5
0
        public void SendSingleSmsNow_SuccessReturnedIsInvalid_HasNoDeliveryStatus()
        {
            var sendOneMessageNow = new SendOneMessageNow();

            var smsService = MockRepository.GenerateMock<ISmsService>();
            var smsSent = new SmsSent("r", DateTime.Now);
            smsService.Expect(s => s.Send(sendOneMessageNow)).Return(smsSent);

            Test.Initialize();
            Assert.That(() =>
            Test.Saga<SmsActioner.SmsActioner>()
                .WithExternalDependencies(a => a.SmsService = smsService)
                    .ExpectPublish<MessageSent>()
                .When(a => a.Handle(sendOneMessageNow)),
                Throws.Exception.With.Message.Contains("SmsSent type is invalid - followup is required to get delivery status")
            );
        }
コード例 #6
0
        public void TimeoutHandle_CheckStatus_SmsSent()
        {
            var timeout = new SmsPendingTimeout();
            var sendOneMessageNow = new SendOneMessageNow
                {
                    ConfirmationEmailAddress = "*****@*****.**",
                    CorrelationId = Guid.NewGuid(),
                    SmsData = new SmsData("mobile", "message"),
                    SmsMetaData = new SmsMetaData { Tags = new List<string> { "tag1", "tag2" }, Topic = "topic" }
                };
            var data = new SmsActionerData
            {
                Id = Guid.NewGuid(),
                OriginalMessage = sendOneMessageNow,
                Price = 0.06m,
                SmsRequestId = "123"
            };

            var smsService = MockRepository.GenerateMock<ISmsService>();
            var smsSent = new SmsSent("doesn't matter", DateTime.Now);

            smsService
                .Expect(s => s.CheckStatus(data.SmsRequestId))
                .Return(smsSent);

            Test.Initialize();
            Test.Saga<SmsActioner.SmsActioner>()
                .WithExternalDependencies(a =>
                    {
                        a.SmsService = smsService;
                        a.Data = data;
                    })
                .WhenReceivesMessageFrom("somewhere")
                    .ExpectPublish<MessageSent>(message =>
                        message.ConfirmationEmailAddress == sendOneMessageNow.ConfirmationEmailAddress &&
                        message.CorrelationId == sendOneMessageNow.CorrelationId &&
                        message.SmsData == sendOneMessageNow.SmsData &&
                        message.SmsMetaData == sendOneMessageNow.SmsMetaData &&
                        message.ConfirmationData.Price == data.Price &&
                        message.ConfirmationData.Receipt == data.SmsRequestId &&
                        message.ConfirmationData.SentAtUtc == smsSent.SentAtUtc
                    )
                .When(a => a.Timeout(timeout))
                .AssertSagaCompletionIs(true);

            smsService.VerifyAllExpectations();
        }
コード例 #7
0
        public void SendOneMessageNow_SmsSent_InvalidThrowsException()
        {
            var sendOneMessageNow = new SendOneMessageNow();

            var smsService = MockRepository.GenerateMock<ISmsService>();
            var smsSent = new SmsSent("r", DateTime.Now);

            smsService
                .Expect(s => s.Send(sendOneMessageNow))
                .Return(smsSent);

            var smsActioner = new SmsActioner.SmsActioner
                {
                    SmsService = smsService
                };

            Assert.That(() => smsActioner.Handle(sendOneMessageNow), Throws.Exception.With.Message.Contains("SmsSent type is invalid - followup is required to get delivery status"));
        }