public async Task EnterYourDetailsControllerBodyPostReturnsSuccess(string mediaTypeName) { // Arrange const bool expectedSendEmailResult = true; string expectedRedirectUrl = $"/{RegistrationPath}/{HomeController.ThankyouForContactingUsCanonicalName}"; var viewModel = ValidModelBuilders.BuildValidEnterYourDetailsBodyViewModel(); var controller = BuildEnterYourDetailsController(mediaTypeName); A.CallTo(() => FakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).Returns(A.Dummy <string>()); A.CallTo(() => FakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).Returns(A.Fake <ContactUsEmailRequestModel>()); A.CallTo(() => FakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).Returns(expectedSendEmailResult); A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).Returns(true); // Act var result = await controller.EnterYourDetailsBody(viewModel).ConfigureAwait(false); // Assert A.CallTo(() => FakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var redirectResult = Assert.IsType <RedirectResult>(result); Assert.Equal(expectedRedirectUrl, redirectResult.Url); Assert.False(redirectResult.Permanent); controller.Dispose(); }
public async Task HomeControllerBodyReturnsNotAcceptable(string mediaTypeName) { // Arrange var controller = BuildHomeController(mediaTypeName); A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).Returns(true); // Act var result = await controller.HomeBody().ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappened(); var statusResult = Assert.IsType <StatusCodeResult>(result); A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode); controller.Dispose(); }
public async Task HomeControllerBodyJsonReturnsSuccess(string mediaTypeName) { // Arrange var controller = BuildHomeController(mediaTypeName); A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).Returns(true); // Act var result = await controller.HomeBody().ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappened(); var jsonResult = Assert.IsType <OkObjectResult>(result); Assert.NotNull(jsonResult.Value); controller.Dispose(); }
public async Task HomeControllerBodyHtmlReturnsSuccess(string mediaTypeName) { // Arrange var controller = BuildHomeController(mediaTypeName); A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).Returns(true); // Act var result = await controller.HomeBody().ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).MustHaveHappened(); var viewResult = Assert.IsType <ViewResult>(result); _ = Assert.IsAssignableFrom <HomeBodyViewModel>(viewResult.ViewData.Model); controller.Dispose(); }
public async Task EnterYourDetailsControllerBodyPostReturnsNotAcceptable(string mediaTypeName) { // Arrange var viewModel = new EnterYourDetailsBodyViewModel(); var controller = BuildEnterYourDetailsController(mediaTypeName); controller.ModelState.AddModelError(nameof(EnterYourDetailsBodyViewModel.FirstName), "Fake error"); // Act var result = await controller.EnterYourDetailsBody(viewModel).ConfigureAwait(false); // Assert A.CallTo(() => FakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).MustNotHaveHappened(); A.CallTo(() => FakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).MustNotHaveHappened(); A.CallTo(() => FakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).MustNotHaveHappened(); A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened(); var statusResult = Assert.IsType <StatusCodeResult>(result); A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode); controller.Dispose(); }
public async Task EnterYourDetailsControllerBodyPostReturnsSameViewForInvalidModel() { // Arrange var viewModel = new EnterYourDetailsBodyViewModel(); var controller = BuildEnterYourDetailsController(MediaTypeNames.Text.Html); controller.ModelState.AddModelError(nameof(EnterYourDetailsBodyViewModel.TermsAndConditionsAccepted), "Fake error"); // Act var result = await controller.EnterYourDetailsBody(viewModel).ConfigureAwait(false); // Assert A.CallTo(() => FakeRoutingService.GetEmailToSendTo(A <string> .Ignored, A <Category> .Ignored)).MustNotHaveHappened(); A.CallTo(() => FakeMapper.Map <ContactUsEmailRequestModel>(A <EnterYourDetailsBodyViewModel> .Ignored)).MustNotHaveHappened(); A.CallTo(() => FakeNotifyEmailService.SendEmailAsync(A <ContactUsEmailRequestModel> .Ignored)).MustNotHaveHappened(); A.CallTo(() => FakeSessionStateService.DeleteAsync(A <Guid> .Ignored)).MustNotHaveHappened(); var viewResult = Assert.IsType <ViewResult>(result); _ = Assert.IsAssignableFrom <EnterYourDetailsBodyViewModel>(viewResult.ViewData.Model); controller.Dispose(); }