public void IndexPostTests(string filterCourseByText, string pageTitle, string courseSearchResultsPage, string courseDetailsPage, CourseSearchResultsViewModel viewModel) { // Assign var controller = new CourseSearchResultsController(fakeApplicationLogger, fakeCourseSearchService, asyncHelper, fakeCourseSearchViewModelService, fakeBuildQueryStringService) { FilterCourseByText = filterCourseByText, PageTitle = pageTitle, CourseSearchResultsPage = courseSearchResultsPage, CourseDetailsPage = courseDetailsPage }; // Act var controllerResult = controller.WithCallTo(contrl => contrl.Index(viewModel)); // Assert if (!string.IsNullOrWhiteSpace(viewModel.SearchTerm)) { controllerResult.ShouldRedirectTo( fakeBuildQueryStringService.BuildRedirectPathAndQueryString(controller.CourseSearchResultsPage, viewModel.SearchTerm, viewModel.CourseFiltersModel)); } else { controllerResult.ShouldRenderView("SearchResults").WithModel <CourseSearchResultsViewModel>( vm => { vm.PageTitle.Should().BeEquivalentTo(controller.PageTitle); vm.FilterCourseByText.Should().BeEquivalentTo(controller.FilterCourseByText); }); } }
public void SearchTermIsHTMLEncodedWhenReturnedToUser() { var courseSearchResponse = new CourseSearchResult { Courses = GetCourses(0), ResultProperties = new CourseSearchResultProperties { Page = 1, TotalPages = 1, TotalResultCount = 0 } }; var searchFilter = new CourseFiltersViewModel() { Location = null, SearchTerm = "<script>alert('here')</script>" }; // setupFakes A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <CourseSearchProperties> ._)).Returns(courseSearchResponse); var searchProperties = new CourseSearchProperties { }; // Assign var controller = new CourseSearchResultsController(fakeApplicationLogger, fakeCourseSearchService, asyncHelper, fakeCourseSearchViewModelService, fakeWebAppContext, mapperCfg) { }; // Act var controllerResult = controller.WithCallTo(contrl => contrl.Index(searchFilter, searchProperties)); // Assert controllerResult.ShouldRenderView("SearchResults").WithModel <CourseSearchResultsViewModel>( vm => { vm.NoTrainingCoursesFoundText.Should().Contain(HttpUtility.HtmlEncode(searchFilter.SearchTerm)); }); }
public void LocationToPostcodeTest(string location, string expectedPostCode, string expectedTown) { var courseSearchResponse = new CourseSearchResult { Courses = GetCourses(1), ResultProperties = new CourseSearchResultProperties { Page = 1, TotalPages = 1, TotalResultCount = 1 } }; var searchProperties = new CourseSearchProperties(); var searchFilter = new CourseFiltersViewModel() { Location = location, SearchTerm = "AnySearchTerm" }; // setupFakes A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <CourseSearchProperties> ._)).Returns(courseSearchResponse); // Assign var controller = new CourseSearchResultsController(fakeApplicationLogger, fakeCourseSearchService, asyncHelper, fakeCourseSearchViewModelService, fakeWebAppContext, mapperCfg) { }; // Act var controllerResult = controller.WithCallTo(contrl => contrl.Index(searchFilter, searchProperties)); // Assert controllerResult.ShouldRenderView("SearchResults").WithModel <CourseSearchResultsViewModel>( vm => { vm.CourseFiltersModel.Postcode.Should().BeEquivalentTo(expectedPostCode); vm.CourseFiltersModel.Town.Should().BeEquivalentTo(expectedTown); }); }
public void OrderByDistanceWithNoPostcodeTest() { var courseSearchResponse = new CourseSearchResult { Courses = GetCourses(2), ResultProperties = new CourseSearchResultProperties { Page = 1, TotalPages = 1, TotalResultCount = 2 } }; var searchFilter = new CourseFiltersViewModel() { Location = null, SearchTerm = "AnySearchTerm" }; // setupFakes A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <CourseSearchProperties> ._)).Returns(courseSearchResponse); var searchProperties = new CourseSearchProperties { OrderedBy = CourseSearchOrderBy.Distance }; // Assign var controller = new CourseSearchResultsController(fakeApplicationLogger, fakeCourseSearchService, asyncHelper, fakeCourseSearchViewModelService, fakeWebAppContext, mapperCfg) { }; // Act var controllerResult = controller.WithCallTo(contrl => contrl.Index(searchFilter, searchProperties)); // Assert controllerResult.ShouldRenderView("SearchResults").WithModel <CourseSearchResultsViewModel>(); A.CallTo(() => fakeCourseSearchViewModelService.GetOrderByLinks(A <string> ._, CourseSearchOrderBy.Distance)).MustHaveHappened(); }
public void IndexTests(CourseFiltersViewModel searchFilter, string resetFilterText, string pageTitle, string courseSearchResultsPage, string courseDetailsPage, CourseSearchOrderBy orderBy, CourseSearchResult courseSearchResponse) { courseSearchResponse = courseSearchResponse ?? new CourseSearchResult(); searchFilter = searchFilter ?? new CourseFiltersViewModel(); // setupFakes A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <CourseSearchProperties> ._)).Returns(courseSearchResponse); var searchProperties = new CourseSearchProperties { OrderedBy = orderBy }; // Assign var controller = new CourseSearchResultsController(fakeApplicationLogger, fakeCourseSearchService, asyncHelper, fakeCourseSearchViewModelService, fakeWebAppContext, mapperCfg) { ResetFilterText = resetFilterText, PageTitle = pageTitle, CourseSearchResultsPage = courseSearchResultsPage, CourseDetailsPage = courseDetailsPage, RecordsPerPage = 40, AdvancedLoanProviderLabel = nameof(CourseSearchResultsController.AdvancedLoanProviderLabel), LocationLabel = nameof(CourseSearchResultsController.LocationLabel), ProviderLabel = nameof(CourseSearchResultsController.ProviderLabel), StartDateLabel = nameof(CourseSearchResultsController.StartDateLabel), OrderByText = nameof(CourseSearchResultsController.OrderByText), StartDateOrderByText = nameof(CourseSearchResultsController.StartDateOrderByText), DistanceOrderByText = nameof(CourseSearchResultsController.DistanceOrderByText), RelevanceOrderByText = nameof(CourseSearchResultsController.RelevanceOrderByText), NoTrainingCoursesFoundText = nameof(CourseSearchResultsController.NoTrainingCoursesFoundText), ApplyFiltersText = nameof(CourseSearchResultsController.ApplyFiltersText), CourseTypeSectionText = nameof(CourseSearchResultsController.CourseTypeSectionText), CourseHoursSectionText = nameof(CourseSearchResultsController.CourseHoursSectionText), StartDateSectionText = nameof(CourseSearchResultsController.StartDateSectionText), SearchForCourseNameText = nameof(CourseSearchResultsController.SearchForCourseNameText), WithinText = nameof(CourseSearchResultsController.WithinText), Only1619CoursesText = nameof(CourseSearchResultsController.Only1619CoursesText), StartDateExampleText = nameof(CourseSearchResultsController.StartDateExampleText) }; // Act var controllerResult = controller.WithCallTo(contrl => contrl.Index( searchFilter, searchProperties)); // Assert controllerResult.ShouldRenderView("SearchResults").WithModel <CourseSearchResultsViewModel>( vm => { vm.PageTitle.Should().BeEquivalentTo(controller.PageTitle); vm.ResetFiltersText.Should().BeEquivalentTo(controller.ResetFilterText); vm.ResetFilterUrl.OriginalString.Should().NotBeEmpty(); }); if (!string.IsNullOrWhiteSpace(searchFilter.SearchTerm)) { A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <CourseSearchProperties> ._)).MustHaveHappened(); if (courseSearchResponse.Courses.Any()) { A.CallTo(() => fakeCourseSearchViewModelService.GetOrderByLinks(A <string> ._, A <CourseSearchOrderBy> ._)).MustHaveHappened(); A.CallTo(() => fakeCourseSearchViewModelService.SetupViewModelPaging(A <CourseSearchResultsViewModel> ._, A <CourseSearchResult> ._, A <string> ._, A <int> ._)).MustHaveHappened(); } } else { A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <CourseSearchProperties> ._)).MustNotHaveHappened(); A.CallTo(() => fakeCourseSearchViewModelService.GetOrderByLinks(A <string> ._, A <CourseSearchOrderBy> ._)).MustNotHaveHappened(); A.CallTo(() => fakeCourseSearchViewModelService.SetupViewModelPaging(A <CourseSearchResultsViewModel> ._, A <CourseSearchResult> ._, A <string> ._, A <int> ._)).MustNotHaveHappened(); } }
public void IndexTests(string searchTerm, string filterCourseByText, string pageTitle, string courseSearchResultsPage, string courseDetailsPage, string sortBy, CourseSearchResult courseSearchResponse) { // setupFakes A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <string> ._, A <CourseSearchProperties> ._)).Returns(courseSearchResponse); // Assign var controller = new CourseSearchResultsController(fakeApplicationLogger, fakeCourseSearchService, asyncHelper, fakeCourseSearchViewModelService, fakeBuildQueryStringService) { FilterCourseByText = filterCourseByText, PageTitle = pageTitle, CourseSearchResultsPage = courseSearchResultsPage, CourseDetailsPage = courseDetailsPage, LocationRegex = nameof(CourseSearchResultsController.LocationRegex), RecordsPerPage = 40, AdvancedLoanProviderLabel = nameof(CourseSearchResultsController.AdvancedLoanProviderLabel), LocationLabel = nameof(CourseSearchResultsController.LocationLabel), ProviderLabel = nameof(CourseSearchResultsController.ProviderLabel), StartDateLabel = nameof(CourseSearchResultsController.StartDateLabel), OrderByText = nameof(CourseSearchResultsController.OrderByText), StartDateOrderByText = nameof(CourseSearchResultsController.StartDateOrderByText), DistanceOrderByText = nameof(CourseSearchResultsController.DistanceOrderByText), RelevanceOrderByText = nameof(CourseSearchResultsController.RelevanceOrderByText), NoTrainingCoursesFoundText = nameof(CourseSearchResultsController.NoTrainingCoursesFoundText) }; // Act var controllerResult = controller.WithCallTo(contrl => contrl.Index( searchTerm, string.Empty, string.Empty, string.Empty, string.Empty, sortBy, string.Empty, string.Empty, false, 1)); // Assert controllerResult.ShouldRenderView("SearchResults").WithModel <CourseSearchResultsViewModel>( vm => { vm.PageTitle.Should().BeEquivalentTo(controller.PageTitle); vm.FilterCourseByText.Should().BeEquivalentTo(controller.FilterCourseByText); }); if (!string.IsNullOrWhiteSpace(searchTerm)) { A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <string> ._, A <CourseSearchProperties> ._)).MustHaveHappened(); if (courseSearchResponse.Courses.Any()) { A.CallTo(() => fakeCourseSearchViewModelService.GetOrderByLinks(A <string> ._, A <CourseSearchOrderBy> ._)).MustHaveHappened(); A.CallTo(() => fakeCourseSearchViewModelService.SetupPaging(A <CourseSearchResultsViewModel> ._, A <CourseSearchResult> ._, A <string> ._, A <int> ._, A <string> ._)).MustHaveHappened(); } } else { A.CallTo(() => fakeCourseSearchService.SearchCoursesAsync(A <string> ._, A <CourseSearchProperties> ._)).MustNotHaveHappened(); A.CallTo(() => fakeCourseSearchViewModelService.GetOrderByLinks(A <string> ._, A <CourseSearchOrderBy> ._)).MustNotHaveHappened(); A.CallTo(() => fakeCourseSearchViewModelService.SetupPaging(A <CourseSearchResultsViewModel> ._, A <CourseSearchResult> ._, A <string> ._, A <int> ._, A <string> ._)).MustNotHaveHappened(); } }