public async Task Index_ReturnsBadRequestResult_WhenFromIsWhitespace() { var sut = new SmsResponseController(null, null); var result = await sut.Index(" ", It.IsAny <string>()); result.ShouldBeOfType(typeof(BadRequestResult)); }
public void Index_HttpPostAttributeHasCorrectTemplate() { var sut = new SmsResponseController(null, null); var attribute = sut.GetAttributesOn(x => x.Index(It.IsAny <string>(), It.IsAny <string>())).OfType <HttpPostAttribute>().SingleOrDefault(); attribute.Template.ShouldBe("smsresponse"); }
public void Index_HasAllowAnonymousAttribute() { var sut = new SmsResponseController(null, null); var attribute = sut.GetAttributesOn(x => x.Index(It.IsAny <string>(), It.IsAny <string>())).OfType <AllowAnonymousAttribute>().SingleOrDefault(); attribute.ShouldNotBeNull(); }
public async Task Index_SendsChangeRequestStatusCommand_WithExpectedValues_WhenLowercaseRejectBodyPosted() { var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(RequestGuid); var sut = new SmsResponseController(mediatr.Object, Mock.Of <ISmsSender>()); await sut.Index(GoodPhoneNumber, LowercaseReject); mediatr.Verify(x => x.SendAsync(It.Is <ChangeRequestStatusCommand>(y => y.RequestId == RequestGuid && y.NewStatus == RequestStatus.Unassigned)), Times.Once); }
public async Task Index_SendFindRequestIdByPhoneNumberQuery_Once_WhenThePhoneNumberIsNotNullOrWhitespace() { var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(Guid.Empty) .Verifiable(); var sut = new SmsResponseController(mediatr.Object, null); var result = await sut.Index(GoodPhoneNumber, It.IsAny <string>()); mediatr.Verify(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>()), Times.Once); }
public async Task Index_ReturnsOkResult_WhenRequestIdQueryReturnsEmptyGuid() { var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(Guid.Empty) .Verifiable(); var sut = new SmsResponseController(mediatr.Object, null); var result = await sut.Index(GoodPhoneNumber, It.IsAny <string>()); result.ShouldBeOfType(typeof(OkResult)); }
public async Task Index_DoesNotSendChangeRequestStatusCommand_WhenBodyDoesNotMatchAcceptedOrRejectedStrings() { var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(RequestGuid); mediatr.Setup(x => x.SendAsync(It.IsAny <ChangeRequestStatusCommand>())) .Verifiable(); var sut = new SmsResponseController(mediatr.Object, Mock.Of <ISmsSender>()); await sut.Index(GoodPhoneNumber, InvalidResponse); mediatr.Verify(x => x.SendAsync(It.IsAny <ChangeRequestStatusCommand>()), Times.Never); }
public async Task Index_SendsSmsSendAsync_WithExpectedPhoneNumber_WhenUppercaseRejectBodyPosted() { var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(RequestGuid); var smsSender = new Mock <ISmsSender>(); var sut = new SmsResponseController(mediatr.Object, smsSender.Object); await sut.Index(GoodPhoneNumber, UppercaseReject); smsSender.Verify(x => x.SendSmsAsync(GoodPhoneNumber, "We have canceled your request and once it is rescheduled you will receive further communication."), Times.Once); }
public async Task Index_InvokesSmsSendAsync_WithExpectedPhoneNumber_WhenUppercaseConfirmBodyPosted() { var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(RequestGuid); var smsSender = new Mock <ISmsSender>(); var sut = new SmsResponseController(mediatr.Object, smsSender.Object); await sut.Index(GoodPhoneNumber, UppercaseConfirm); smsSender.Verify(x => x.SendSmsAsync(GoodPhoneNumber, "Thank you for confirming your availability."), Times.Once); }
public async Task Index_Returns500StatusCode_IfAnExceptionIsThrown() { var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(RequestGuid); mediatr.Setup(x => x.SendAsync(It.IsAny <ChangeRequestStatusCommand>())) .Throws(new Exception()); var sut = new SmsResponseController(mediatr.Object, Mock.Of <ISmsSender>()); var result = await sut.Index(GoodPhoneNumber, UppercaseConfirm) as StatusCodeResult; result.ShouldNotBeNull(); result.StatusCode.ShouldBe(500); }
public async Task Index_SendsFindRequestIdByPhoneNumberQuery_WithCorrectPhoneNumber() { FindRequestIdByPhoneNumberQuery query = null; var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(Guid.Empty) .Callback <FindRequestIdByPhoneNumberQuery>(x => query = x) .Verifiable(); var sut = new SmsResponseController(mediatr.Object, null); var result = await sut.Index(GoodPhoneNumber, It.IsAny <string>()); query.PhoneNumber.ShouldBe(GoodPhoneNumber); }
public async Task Index_SendsChangeRequestStatusCommand_WithExpectedValues_WhenLowercaseRejectBodyPosted() { ChangeRequestStatusCommand cmd = null; var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(RequestGuid); mediatr.Setup(x => x.SendAsync(It.IsAny <ChangeRequestStatusCommand>())) .Returns(Task.FromResult(Unit.Value)) .Callback <ChangeRequestStatusCommand>(x => cmd = x) .Verifiable(); var sut = new SmsResponseController(mediatr.Object, Mock.Of <ISmsSender>()); await sut.Index(GoodPhoneNumber, LowercaseReject); mediatr.Verify(x => x.SendAsync(It.IsAny <ChangeRequestStatusCommand>()), Times.Once); cmd.RequestId.ShouldBe(RequestGuid); cmd.NewStatus.ShouldBe(RequestStatus.Unassigned); }
public async Task Index_SendsSmsSendAsync_WithExpectedPhoneNumber_WhenUppercaseRejectBodyPosted() { string smsTo = null; var mediatr = new Mock <IMediator>(); mediatr.Setup(x => x.SendAsync(It.IsAny <FindRequestIdByPhoneNumberQuery>())) .ReturnsAsync(RequestGuid); var smsSender = new Mock <ISmsSender>(); smsSender.Setup(x => x.SendSmsAsync(It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult <object>(null)) .Callback <string, string>((x, y) => smsTo = x) .Verifiable(); var sut = new SmsResponseController(mediatr.Object, smsSender.Object); await sut.Index(GoodPhoneNumber, UppercaseReject); smsSender.Verify(x => x.SendSmsAsync(It.IsAny <string>(), It.IsAny <string>()), Times.Once); smsTo.ShouldBe(GoodPhoneNumber); }