public async Task NullViewModelReturnsBadRequest() { AssessmentEmailPostRequest viewModel = null; var actionResponse = await AssessmentController.Email(viewModel).ConfigureAwait(false); Assert.IsType <BadRequestResult>(actionResponse); }
public async Task WhenSessionExistsReturnsView() { A.CallTo(() => Session.HasValidSession()).Returns(true); var actionResponse = await AssessmentController.Email().ConfigureAwait(false); Assert.IsType <ViewResult>(actionResponse); }
public async Task WhenSessionExistsAndModelStateIsNotValidReturnsView() { var assessmentEmailPostRequest = new AssessmentEmailPostRequest(); A.CallTo(() => Session.HasValidSession()).Returns(true); AssessmentController.ModelState.AddModelError("Key1", "Some Error"); var actionResponse = await AssessmentController.Email(assessmentEmailPostRequest).ConfigureAwait(false); Assert.IsType <ViewResult>(actionResponse); }
public async Task WhenSessionDoesNotExistRedirectsToRoot() { A.CallTo(() => Session.HasValidSession()).Returns(false); var actionResponse = await AssessmentController.Email().ConfigureAwait(false); Assert.IsType <RedirectResult>(actionResponse); var redirectResult = actionResponse as RedirectResult; Assert.Equal($"~/{RouteName.Prefix}/", redirectResult.Url); }
public async Task WhenModelStateIsInvalidRedirectsToView() { AssessmentController.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext(), }; var sendEmailResponse = new SendEmailResponse() { IsSuccess = false }; var viewModel = new AssessmentEmailPostRequest() { Email = "*****@*****.**" }; A.CallTo(() => ApiService.SendEmail(A <string> .Ignored, viewModel.Email)).Returns(sendEmailResponse); var actionResponse = await AssessmentController.Email(viewModel).ConfigureAwait(false); Assert.IsType <ViewResult>(actionResponse); }
public async Task WhenModelStateIsValidRedirectsToView() { AssessmentController.ControllerContext = new ControllerContext() { HttpContext = new DefaultHttpContext(), }; var sendEmailResponse = new SendEmailResponse() { IsSuccess = true }; var viewModel = new AssessmentEmailPostRequest() { Email = "*****@*****.**" }; A.CallTo(() => ApiService.SendEmail(A <string> .Ignored, viewModel.Email)).Returns(sendEmailResponse); var actionResponse = await AssessmentController.Email(viewModel).ConfigureAwait(false); Assert.IsType <RedirectResult>(actionResponse); var redirectResult = actionResponse as RedirectResult; Assert.Equal($"~/{RouteName.Prefix}/assessment/emailsent", redirectResult.Url); }