public void SendSingleSmsNow_SendingThenFail() { 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 smsFailed = new SmsFailed(sid, "c", "m"); smsService.Expect(s => s.Send(sendOneMessageNow)).Return(smsSending); smsService.Expect(s => s.CheckStatus(smsSending.Sid)).Return(smsFailed); 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>() .WhenSagaTimesOut() .AssertSagaCompletionIs(true); }
public void SendOneMessageNow_SmsSendingSetsPriceAndId() { var sendOneMessageNow = new SendOneMessageNow(); var smsService = MockRepository.GenerateMock<ISmsService>(); var timeoutCalculator = MockRepository.GenerateMock<ITimeoutCalculator>(); var smsSending = new SmsSending("id", 0.06m); var data = new SmsActionerData(); smsService .Expect(s => s.Send(sendOneMessageNow)) .Return(smsSending); var timeoutRequested = new TimeSpan(); timeoutCalculator.Expect(t => t.RequiredTimeout(data.NumberOfTimeoutRequests)).Return(timeoutRequested); Test.Initialize(); Test.Saga<SmsActioner.SmsActioner>() .WithExternalDependencies(a => { a.SmsService = smsService; a.Data = data; a.TimeoutCalculator = timeoutCalculator; }) .WhenReceivesMessageFrom("somewhere") .ExpectTimeoutToBeSetIn<SmsPendingTimeout>((timeoutMessage, timespan) => timespan == timeoutRequested) .When(a => a.Handle(sendOneMessageNow)); Assert.That(data.SmsRequestId, Is.EqualTo(smsSending.Sid)); Assert.That(data.Price, Is.EqualTo(smsSending.Price)); Assert.That(data.OriginalMessage, Is.EqualTo(sendOneMessageNow)); Assert.That(data.NumberOfTimeoutRequests, Is.EqualTo(1)); smsService.VerifyAllExpectations(); timeoutCalculator.VerifyAllExpectations(); }