public async Task PageReturnsSuccess(string town) { // arrange var controller = BuildCourseController(MediaTypeNames.Text.Html); var paramValues = new ParamValues { Town = town, CourseType = "Online", CourseHours = "Full time", CourseStudyTime = "Daytime", }; var returnedCourseData = new CourseSearchResult { Courses = new List <Course> { new Course { Title = "Maths", CourseId = "1", AttendancePattern = "Online", Description = "This is a test description - over 220 chars" + new string(' ', 220) }, }, }; A.CallTo(() => FakeFindACoursesService.GetFilteredData(A <CourseSearchFilters> .Ignored, CourseSearchOrderBy.Relevance, 1)).Returns(returnedCourseData); // act var result = await controller.Page(paramValues, true).ConfigureAwait(false); // assert var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <BodyViewModel>(viewResult.ViewData.Model); Assert.NotNull(model.Results); controller.Dispose(); }
public void SetupPaging(CourseSearchResultsViewModel viewModel, CourseSearchResult response, string pathQuery, int recordsPerPage, string courseSearchResultsPage) { if (viewModel != null && response != null) { viewModel.Count = recordsPerPage; viewModel.Page = response.ResultProperties.Page; viewModel.ResultProperties = response.ResultProperties; if (viewModel.ResultProperties.TotalPages > 1 && viewModel.ResultProperties.TotalPages >= viewModel.ResultProperties.Page) { viewModel.PaginationViewModel.HasPreviousPage = viewModel.ResultProperties.Page > 1; viewModel.PaginationViewModel.HasNextPage = viewModel.ResultProperties.Page < viewModel.ResultProperties.TotalPages; viewModel.PaginationViewModel.NextPageUrl = new Uri( $"{pathQuery}&page={viewModel.ResultProperties.Page + 1}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.NextPageText = $"{viewModel.ResultProperties.Page + 1} of {viewModel.ResultProperties.TotalPages}"; if (viewModel.ResultProperties.Page > 1) { viewModel.PaginationViewModel.PreviousPageUrl = new Uri( $"{pathQuery}{(viewModel.ResultProperties.Page == 2 ? string.Empty : $"&page={viewModel.ResultProperties.Page - 1}")}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.PreviousPageText = $"{viewModel.ResultProperties.Page - 1} of {viewModel.ResultProperties.TotalPages}"; } } }
public async Task <CourseSearchResult> SearchCoursesAsync(CourseSearchProperties courseSearchProperties) { if (string.IsNullOrWhiteSpace(courseSearchProperties.Filters.SearchTerm)) { return(await Task.FromResult <CourseSearchResult>(null)); } var response = new CourseSearchResult(); var request = buildTribalMessage.GetCourseSearchInput(courseSearchProperties); auditRepository.CreateAudit(request); var apiResult = await serviceHelper.UseAsync <ServiceInterface, CourseListOutput>(async x => await tolerancePolicy.ExecuteAsync(() => x.CourseListAsync(request), Constants.CourseSearchEndpointConfigName, FaultToleranceType.CircuitBreaker), Constants.CourseSearchEndpointConfigName); auditRepository.CreateAudit(apiResult); response.ResultProperties.TotalPages = Convert.ToInt32(apiResult?.CourseListResponse?.ResultInfo?.NoOfPages); response.ResultProperties.TotalResultCount = Convert.ToInt32(apiResult?.CourseListResponse?.ResultInfo?.NoOfRecords); response.ResultProperties.Page = Convert.ToInt32(apiResult?.CourseListResponse?.ResultInfo?.PageNo); response.Courses = apiResult?.ConvertToSearchCourse(); response.ResultProperties.OrderedBy = courseSearchProperties.OrderedBy; return(response); }
public static void Main(string[] args) { string abbr = args.Length > 0 ? args[0] : "uoft_courses"; InvertedWordIndex index = InvertedWordIndex.Read(abbr + ".idx"); DefaultIIndexableCollection <Course> school = DefaultIIndexableCollection <Course> .ReadBin(abbr + ".bin"); CourseSearchPresenter searchEngine = new CourseSearchPresenter(index, school); while (true) { Console.Write("Please input a query: "); string query = Console.ReadLine(); CourseSearchResult result = searchEngine.GetItemList(query) as CourseSearchResult; Console.WriteLine(result.CodeNameMatches); //CourseSearchResult result = searchEngine.GetCourseList(query); //if (result.CodeNameMatches.Count > 0) //{ // Console.WriteLine("\nCourse:"); // Console.WriteLine(result.CodeNameMatches.First<Course>().ToString()); //} //foreach (IIndexable item in result.RawMatches) //{ // Course course = item as Course; // Console.WriteLine("{0}: {1}", course.Abbr, course.Name); //} //if (result.RawMatches.Count > 0) Console.WriteLine("\nRelevant:"); //foreach (IIndexable item in result.RawMatches) //{ // Course course = item as Course; // Console.WriteLine("{0}: {1}", course.Abbr, course.Name); //} //Console.WriteLine(); } }
public void SetupViewModelPaging(CourseSearchResultsViewModel viewModel, CourseSearchResult response, string resultsPage, int recordsPerPage) { if (viewModel != null && response != null) { if (response.ResultProperties.Page == 0) { response.ResultProperties.Page = 1; } viewModel.Count = recordsPerPage; viewModel.Page = response.ResultProperties.Page; viewModel.ResultProperties = response.ResultProperties; if (viewModel.ResultProperties.TotalPages > 1 && viewModel.ResultProperties.TotalPages >= viewModel.ResultProperties.Page) { var partialQueryString = context.GetQueryStringExcluding(new[] { $"{nameof(CourseSearchProperties.Page)}" }); viewModel.PaginationViewModel.HasPreviousPage = viewModel.ResultProperties.Page > 1; viewModel.PaginationViewModel.HasNextPage = viewModel.ResultProperties.Page < viewModel.ResultProperties.TotalPages; viewModel.PaginationViewModel.NextPageUrl = new Uri($"{resultsPage}?{partialQueryString}&{nameof(CourseSearchProperties.Page)}={viewModel.ResultProperties.Page + 1}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.NextPageText = $"{viewModel.ResultProperties.Page + 1} of {viewModel.ResultProperties.TotalPages}"; if (viewModel.ResultProperties.Page > 1) { viewModel.PaginationViewModel.PreviousPageUrl = new Uri($"{resultsPage}?{partialQueryString}&{nameof(CourseSearchProperties.Page)}={viewModel.ResultProperties.Page - 1}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.PreviousPageText = $"{viewModel.ResultProperties.Page - 1} of {viewModel.ResultProperties.TotalPages}"; } } } }
private void SetupResultsViewModel(CourseSearchResultsViewModel viewModel, CourseSearchResult response) { courseSearchResultsViewModelBuilder.SetupViewModelPaging( viewModel, response, CourseSearchResultsPage, RecordsPerPage); viewModel.OrderByLinks = courseSearchResultsViewModelBuilder.GetOrderByLinks(CourseSearchResultsPage, response.ResultProperties.OrderedBy); }
public async Task CourseControllerFilterResultsReturnsSuccess(string mediaTypeName) { var controller = BuildCourseController(mediaTypeName); var bodyViewModel = new BodyViewModel { CurrentSearchTerm = "Maths", SideBar = new SideBarViewModel { DistanceValue = "15 miles", CourseType = new FiltersListViewModel { SelectedIds = new List <string> { "Online" }, }, CourseHours = new FiltersListViewModel { SelectedIds = new List <string> { "Full time" }, }, CourseStudyTime = new FiltersListViewModel { SelectedIds = new List <string> { "Daytime" }, }, QualificationLevels = new FiltersListViewModel { SelectedIds = new List <string> { "1" }, }, }, IsTest = true, }; var returnedCourseData = new CourseSearchResult { Courses = new List <Course> { new Course { Title = "Maths", CourseId = "1", AttendancePattern = "Online", Description = "This is a test description - over 220 chars" + new string(' ', 220) }, }, }; A.CallTo(() => FakeFindACoursesService.GetFilteredData(A <CourseSearchFilters> .Ignored, CourseSearchOrderBy.Relevance, 1)).Returns(returnedCourseData); var result = await controller.FilterResults(bodyViewModel, string.Empty).ConfigureAwait(false); Assert.IsType <ViewResult>(result); controller.Dispose(); }
public void CheckIfFilteredDataReturnsData() { //Arrange var repository = A.Fake <IFindACourseRepository>(); var courseProperties = new CourseSearchProperties { Page = 1, }; courseProperties.Filters.SearchTerm = "Maths"; courseProperties.Filters.CourseType = new List <CourseType> { CourseType.All }; courseProperties.Filters.CourseHours = new List <CourseHours> { CourseHours.All }; var courseSearchFilters = new CourseSearchFilters { SearchTerm = "Maths", CourseType = new List <CourseType> { CourseType.All }, CourseHours = new List <CourseHours> { CourseHours.All }, }; var returnedCourseData = new CourseSearchResult { Courses = new List <Course> { new Course { Title = "Maths", CourseId = "1", AttendancePattern = "Online", }, }, }; var findACourseService = new FindACourseService(repository); A.CallTo(() => repository.RetrieveData(A <CourseSearchProperties> .Ignored)).Returns(returnedCourseData); //Act var result = findACourseService.GetFilteredData(courseSearchFilters, CourseSearchOrderBy.Relevance, 1).Result; //Assert A.CallTo(() => repository.RetrieveData(A <CourseSearchProperties> .Ignored)).MustHaveHappenedOnceExactly(); Assert.Equal(returnedCourseData, result); }
public async Task AjaxChangedReturnAutoLocationSuggestions(string townOrPostcode, string coordinates, bool expectAutoLocationSuggest) { // arrange var controller = BuildCourseController(MediaTypeNames.Text.Html); var paramValues = new ParamValues { Town = townOrPostcode, Coordinates = coordinates, }; var appdata = System.Text.Json.JsonSerializer.Serialize(paramValues); var returnedCourseData = new CourseSearchResult { ResultProperties = new CourseSearchResultProperties { Page = 1, TotalResultCount = 1, TotalPages = 1, }, Courses = new List <Course> { new Course { Title = "Maths", CourseId = "1", AttendancePattern = "Online", Description = "This is a test description - over 220 chars" + new string(' ', 220) }, }, }; A.CallTo(() => FakeLocationsService.GetSuggestedLocationsAsync(A <string> .Ignored)).Returns(GetTestSuggestedLocations()); A.CallTo(() => FakeFindACoursesService.GetFilteredData(A <CourseSearchFilters> .Ignored, A <CourseSearchOrderBy> .Ignored, A <int> .Ignored)).Returns(returnedCourseData); A.CallTo(() => FakeViewHelper.RenderViewAsync(A <CourseController> .Ignored, A <string> .Ignored, A <BodyViewModel> .Ignored, A <bool> .Ignored)).Returns("<p>some markup</p>"); // act var result = await controller.AjaxChanged(appdata).ConfigureAwait(false); // assert if (expectAutoLocationSuggest) { A.CallTo(() => FakeLocationsService.GetSuggestedLocationsAsync(A <string> .Ignored)).MustHaveHappenedOnceExactly(); result.AutoSuggestedTown.Should().Be("LN1 (LAN1)"); result.UsingAutoSuggestedLocation.Should().BeTrue(); result.DidYouMeanLocations.Count.Should().Be(1); } else { A.CallTo(() => FakeLocationsService.GetSuggestedLocationsAsync(A <string> .Ignored)).MustNotHaveHappened(); result.UsingAutoSuggestedLocation.Should().BeFalse(); } controller.Dispose(); }
public void SetupPagingTest(CourseSearchResultsViewModel viewModel, CourseSearchResult response, string pathQuery, int recordsPerPage, string courseSearchResultsPage, CourseSearchResultsViewModel expectedViewModel) { //Assign var courseSearchConverter = new CourseSearchViewModelService(); //Act courseSearchConverter.SetupPaging(viewModel, response, pathQuery, recordsPerPage, courseSearchResultsPage); //Assert viewModel.PaginationViewModel.NextPageUrl.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.NextPageUrl); viewModel.PaginationViewModel.NextPageText.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.NextPageText); viewModel.PaginationViewModel.PreviousPageUrl.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.PreviousPageUrl); viewModel.PaginationViewModel.PreviousPageText.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.PreviousPageText); viewModel.PaginationViewModel.HasPreviousPage.Should().Be(expectedViewModel.PaginationViewModel.HasPreviousPage); viewModel.PaginationViewModel.HasNextPage.Should().Be(expectedViewModel.PaginationViewModel.HasNextPage); }
public async Task AjaxChangedReturnsSuccessWithCorrectStates(string townOrPostcode, string coordinates, bool expectedShowDistance) { // arrange var controller = BuildCourseController(MediaTypeNames.Text.Html); var paramValues = new ParamValues { Town = townOrPostcode, Coordinates = coordinates, CourseType = "Online", CourseHours = "Full time", CourseStudyTime = "Daytime", }; var appdata = System.Text.Json.JsonSerializer.Serialize(paramValues); var returnedCourseData = new CourseSearchResult { ResultProperties = new CourseSearchResultProperties { Page = 1, TotalResultCount = 1, TotalPages = 1, }, Courses = new List <Course> { new Course { Title = "Maths", CourseId = "1", AttendancePattern = "Online", Description = "This is a test description - over 220 chars" + new string(' ', 220) }, }, }; A.CallTo(() => FakeFindACoursesService.GetFilteredData(A <CourseSearchFilters> .Ignored, A <CourseSearchOrderBy> .Ignored, A <int> .Ignored)).Returns(returnedCourseData); A.CallTo(() => FakeViewHelper.RenderViewAsync(A <CourseController> .Ignored, A <string> .Ignored, A <BodyViewModel> .Ignored, A <bool> .Ignored)).Returns("<p>some markup</p>"); // act var result = await controller.AjaxChanged(appdata).ConfigureAwait(false); // assert Assert.False(string.IsNullOrWhiteSpace(result.HTML)); Assert.Equal(returnedCourseData.Courses.ToList().Count, result.Count); result.ShowDistanceSelector.Should().Be(expectedShowDistance); controller.Dispose(); }
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 SetupPagingTest(CourseSearchResultsViewModel viewModel, CourseSearchResult response, string pathQuery, int recordsPerPage, CourseSearchResultsViewModel expectedViewModel) { viewModel = viewModel ?? new CourseSearchResultsViewModel(); expectedViewModel = expectedViewModel ?? new CourseSearchResultsViewModel(); //Assign var fakeWebAppContext = A.Fake <IWebAppContext>(); var courseSearchConverter = new CourseSearchResultsViewModelBullder(fakeWebAppContext); A.CallTo(() => fakeWebAppContext.GetQueryStringExcluding(A <IEnumerable <string> > ._)).Returns("a=b"); //Act courseSearchConverter.SetupViewModelPaging(viewModel, response, pathQuery, recordsPerPage); //Assert viewModel.PaginationViewModel.NextPageUrl.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.NextPageUrl); viewModel.PaginationViewModel.NextPageText.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.NextPageText); viewModel.PaginationViewModel.PreviousPageUrl.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.PreviousPageUrl); viewModel.PaginationViewModel.PreviousPageText.Should().BeEquivalentTo(expectedViewModel.PaginationViewModel.PreviousPageText); viewModel.PaginationViewModel.HasPreviousPage.Should().Be(expectedViewModel.PaginationViewModel.HasPreviousPage); viewModel.PaginationViewModel.HasNextPage.Should().Be(expectedViewModel.PaginationViewModel.HasNextPage); }
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(); }
/// <summary> /// Search a query and get a list of html-formatted results defined by CourseSearchResult /// </summary> /// <param name="query">Search query</param> /// <returns></returns> public override SearchResult GetItemList(string query) { CourseSearchResult result = new CourseSearchResult(); HashSet <uint> rawMatches = GetIDMatches(query, null); HashSet <uint> codeMatches = GetIDMatches(query, "code:"); HashSet <uint> nameMatches = GetIDMatches(query, "name:"); if (codeMatches.Count == 0 && nameMatches.Count == 0) { codeMatches.UnionWith(rawMatches); } rawMatches.ExceptWith(codeMatches); rawMatches.ExceptWith(nameMatches); nameMatches.ExceptWith(codeMatches); if (codeMatches.Count < 5) { HashSet <uint> desMatches, depMatches, preqMatches, postMatches; result.DescriptionMatches = FormatList(GetItemsFromIDs(desMatches = GetIDMatches(query, "des:"))); result.DepartmentMatches = FormatList(GetItemsFromIDs(depMatches = GetIDMatches(query, "dep:"))); result.PrerequisiteMatches = FormatList(GetItemsFromIDs(preqMatches = GetIDMatches(query, "preq:"))); result.PostrequisiteMatches = FormatList(GetItemsFromIDs(postMatches = GetIDMatches(query, "post:"))); rawMatches.ExceptWith(desMatches); rawMatches.ExceptWith(depMatches); rawMatches.ExceptWith(preqMatches); rawMatches.ExceptWith(postMatches); result.RawMatches = FormatList(GetItemsFromIDs(rawMatches)); } result.CodeNameMatches = FormatList(GetItemsFromIDs(codeMatches.Concat(nameMatches).Take(20))); return(result); }
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(); } }
/// <summary> /// Creates a repeater friendly CourseSearchResult object from the response. /// </summary> /// <param name="course">The CourseStructure response from the search.</param> /// <returns>A populated CourseSearchResult object.</returns> private CourseSearchResult CreateResult(CourseStructure course) { CourseSearchResult result = new CourseSearchResult(); if (course != null && course.Course != null) { // COURSE result.CourseID = HttpUtility.HtmlEncode(course.Course.CourseID); result.CourseName = HttpUtility.HtmlEncode(course.Course.CourseTitle); result.CourseSummary = HttpUtility.HtmlEncode(course.Course.CourseSummary); result.CourseDfEFunded = course.Opportunity.DFE1619Funded; result.LDCS1 = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode1.LDCSCode); result.LDCS1Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode1.LDCSDesc); result.LDCS2 = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode2.LDCSCode); result.LDCS2Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode2.LDCSDesc); result.LDCS3 = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode3.LDCSCode); result.LDCS3Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode3.LDCSDesc); result.LDCS4 = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode4.LDCSCode); result.LDCS4Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode4.LDCSDesc); result.LDCS5 = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode5.LDCSCode); result.LDCS5Description = HttpUtility.HtmlEncode(course.Course.LDCS.CatCode5.LDCSDesc); result.NumberOfOpportunities = HttpUtility.HtmlEncode(course.Course.NoOfOpps); result.QualificationLevel = HttpUtility.HtmlEncode(course.Course.QualificationLevel); result.QualificationType = HttpUtility.HtmlEncode(course.Course.QualificationType); // OPPORTUNITY if (course.Opportunity != null) { result.OpportunityID = HttpUtility.HtmlEncode(course.Opportunity.OpportunityId); result.AttendanceMode = HttpUtility.HtmlEncode(course.Opportunity.AttendanceMode); result.AttendancePattern = HttpUtility.HtmlEncode(course.Opportunity.AttendancePattern); if (course.Opportunity.Duration != null) { result.DurationDescription = HttpUtility.HtmlEncode(course.Opportunity.Duration.DurationDescription); result.DurationUnit = HttpUtility.HtmlEncode(course.Opportunity.Duration.DurationUnit); result.DurationValue = HttpUtility.HtmlEncode(course.Opportunity.Duration.DurationValue); } if (course.Opportunity.Item != null) { // could be VenueInfo or a Region name if (course.Opportunity.Item.GetType() == typeof(VenueInfo)) { VenueInfo venueInfo = course.Opportunity.Item as VenueInfo; if (venueInfo != null) { result.Venue = venueInfo.VenueName; result.Distance = venueInfo.Distance.ToString(); if (venueInfo.VenueAddress != null) { result.AddressLine1 = venueInfo.VenueAddress.Address_line_1; result.AddressLine2 = venueInfo.VenueAddress.Address_line_2; result.Town = venueInfo.VenueAddress.Town; result.County = venueInfo.VenueAddress.County; result.Postcode = venueInfo.VenueAddress.PostCode; result.Latitude = venueInfo.VenueAddress.Latitude; result.Longitude = venueInfo.VenueAddress.Longitude; } } } else if (course.Opportunity.Item is String) { result.RegionName = course.Opportunity.Item.ToString(); } } if (course.Opportunity.StartDate.ItemElementName.ToString() == "Date") { if (course.Opportunity.StartDate.Item != null) { result.StartDate = course.Opportunity.StartDate.Item; } } else { result.StartDateDescription = course.Opportunity.StartDate.Item; } result.StudyMode = HttpUtility.HtmlEncode(course.Opportunity.StudyMode); } result.OpportunityID = HttpUtility.HtmlEncode(course.Opportunity.OpportunityId); // PROVIDER result.ProviderName = HttpUtility.HtmlEncode(course.Provider.ProviderName); result.TFPlusLoans = course.Provider.TFPlusLoans; result.ProviderDfEFunded = course.Provider.DFE1619Funded; result.FEChoices_LearnerDestination = course.Provider.FEChoices_LearnerDestinationSpecified ? course.Provider.FEChoices_LearnerDestination : (Double?)null; result.FEChoices_LearnerSatisfaction = course.Provider.FEChoices_LearnerSatisfactionSpecified ? course.Provider.FEChoices_LearnerSatisfaction : (Double?)null; result.FEChoices_EmployerSatisfaction = course.Provider.FEChoices_EmployerSatisfactionSpecified ? course.Provider.FEChoices_EmployerSatisfaction : (Double?)null; } return(result); }
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(); } }