public async Task HowCanWeHelpControllerBodyPostReturnsSuccessForValidCategories(Category selectedCategory) { // Arrange string moreDetail = $"Some {selectedCategory} details"; string expectedRedirectUrl = $"/{RegistrationPath}/{EnterYourDetailsController.ThisViewCanonicalName}"; var fakeSessionStateModel = A.Fake <SessionStateModel <SessionDataModel> >(); var viewModel = new HowCanWeHelpBodyViewModel { SelectedCategory = selectedCategory, MoreDetail = moreDetail, }; var controller = BuildHowCanWeHelpController(MediaTypeNames.Text.Html); A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).Returns(fakeSessionStateModel); A.CallTo(() => FakeSessionStateService.SaveAsync(A <SessionStateModel <SessionDataModel> > .Ignored)).Returns(HttpStatusCode.OK); // Act var result = await controller.HowCanWeHelpBody(viewModel).ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeSessionStateService.SaveAsync(A <SessionStateModel <SessionDataModel> > .Ignored)).MustHaveHappenedOnceExactly(); var redirectResult = Assert.IsType <RedirectResult>(result); Assert.Equal(expectedRedirectUrl, redirectResult.Url); Assert.False(redirectResult.Permanent); controller.Dispose(); }
public async Task HomeControllerHomeViewPostRedirectsSuccessfully(HomeOption selectedOption, string expectedRedirectUrl) { // Arrange var fakeSessionStateModel = A.Fake <SessionStateModel <SessionDataModel> >(); var viewModel = new HomeBodyViewModel { SelectedOption = selectedOption, }; var controller = BuildHomeController(MediaTypeNames.Text.Html); if (selectedOption == HomeOption.SendAMessage || selectedOption == HomeOption.Callback) { A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).Returns(fakeSessionStateModel); A.CallTo(() => FakeSessionStateService.SaveAsync(A <SessionStateModel <SessionDataModel> > .Ignored)).Returns(HttpStatusCode.OK); } // Act var result = await controller.HomeView(viewModel).ConfigureAwait(false); // Assert if (selectedOption == HomeOption.SendAMessage || selectedOption == HomeOption.Callback) { A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeSessionStateService.SaveAsync(A <SessionStateModel <SessionDataModel> > .Ignored)).MustHaveHappenedOnceExactly(); } var redirectResult = Assert.IsType <RedirectResult>(result); Assert.Equal(expectedRedirectUrl, redirectResult.Url); Assert.False(redirectResult.Permanent); controller.Dispose(); }
public async Task HomeControllerBodyPostReturnsSuccess(string mediaTypeName) { // Arrange string expectedRedirectUrl = $"/{HomeController.RegistrationPath}/{HowCanWeHelpController.ThisViewCanonicalName}"; var fakeSessionStateModel = A.Fake <SessionStateModel <SessionDataModel> >(); var viewModel = new HomeBodyViewModel { SelectedOption = HomeOption.Callback, }; var controller = BuildHomeController(mediaTypeName); A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).Returns(fakeSessionStateModel); A.CallTo(() => FakeSessionStateService.SaveAsync(A <SessionStateModel <SessionDataModel> > .Ignored)).Returns(HttpStatusCode.OK); // Act var result = await controller.HomeBody(viewModel).ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); A.CallTo(() => FakeSessionStateService.SaveAsync(A <SessionStateModel <SessionDataModel> > .Ignored)).MustHaveHappenedOnceExactly(); var redirectResult = Assert.IsType <RedirectResult>(result); Assert.Equal(expectedRedirectUrl, redirectResult.Url); Assert.False(redirectResult.Permanent); controller.Dispose(); }
public async Task EnterYourDetailsControllerViewReturnsNotAcceptable(string mediaTypeName) { // Arrange var fakeSessionStateModel = A.Fake <SessionStateModel <SessionDataModel> >(); var controller = BuildEnterYourDetailsController(mediaTypeName); A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).Returns(fakeSessionStateModel); // Act var result = await controller.EnterYourDetailsView().ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var statusResult = Assert.IsType <StatusCodeResult>(result); A.Equals((int)HttpStatusCode.NotAcceptable, statusResult.StatusCode); controller.Dispose(); }
public async Task EnterYourDetailsControllersViewJsonReturnsSuccess(string mediaTypeName) { // Arrange var fakeSessionStateModel = A.Fake <SessionStateModel <SessionDataModel> >(); var controller = BuildEnterYourDetailsController(mediaTypeName); A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).Returns(fakeSessionStateModel); // Act var result = await controller.EnterYourDetailsView().ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).MustHaveHappenedOnceExactly(); var jsonResult = Assert.IsType <OkObjectResult>(result); _ = Assert.IsAssignableFrom <EnterYourDetailsViewModel>(jsonResult.Value); controller.Dispose(); }
public async Task HowCanWeHelpControllerViewHtmlReturnsSuccess(string mediaTypeName) { // Arrange var controller = BuildHowCanWeHelpController(mediaTypeName); var fakeSessionStateModel = A.Fake <SessionStateModel <SessionDataModel> >(); A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).Returns(fakeSessionStateModel); // Act var result = await controller.HowCanWeHelpView().ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).MustHaveHappened(); var viewResult = Assert.IsType <ViewResult>(result); _ = Assert.IsAssignableFrom <HowCanWeHelpViewModel>(viewResult.ViewData.Model); controller.Dispose(); }
public async Task HowCanWeHelpControllerBodyJsonReturnsSuccess(string mediaTypeName) { // Arrange var controller = BuildHowCanWeHelpController(mediaTypeName); var fakeSessionStateModel = A.Fake <SessionStateModel <SessionDataModel> >(); A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).Returns(fakeSessionStateModel); // Act var result = await controller.HowCanWeHelpBody().ConfigureAwait(false); // Assert A.CallTo(() => FakeSessionStateService.GetAsync(A <Guid> .Ignored)).MustHaveHappened(); var jsonResult = Assert.IsType <OkObjectResult>(result); Assert.NotNull(jsonResult.Value); controller.Dispose(); }