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();
        }
Beispiel #2
0
        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();
        }