public void CourseSetupViewModel_filters_should_be_set() { // Given var categories = new[] { "Category 1", "Category 2" }; var topics = new[] { "Topic 1", "Topic 2" }; var expectedFilters = CourseStatisticsViewModelFilterOptions.GetFilterOptions(categories, topics); // When var model = new CourseSetupViewModel( courses, categories, topics, null, nameof(CourseStatistics.SearchableName), BaseSearchablePageViewModel.Ascending, null, 2 ); // Then model.Filters.Should().BeEquivalentTo(expectedFilters); model.Courses.First().CourseName.Should().BeEquivalentTo("K"); }
public IActionResult Index( string?searchString = null, string?sortBy = null, string sortDirection = GenericSortingHelper.Ascending, string?existingFilterString = null, string?newFilterToAdd = null, bool clearFilters = false, int page = 1, int?itemsPerPage = null ) { sortBy ??= DefaultSortByOptions.Name.PropertyName; existingFilterString = FilteringHelper.GetFilterString( existingFilterString, newFilterToAdd, clearFilters, Request, CourseFilterCookieName, CourseStatusFilterOptions.IsActive.FilterValue ); var centreId = User.GetCentreId(); var categoryId = User.GetAdminCourseCategoryFilter(); var details = courseService.GetCentreCourseDetails(centreId, categoryId); var availableFilters = CourseStatisticsViewModelFilterOptions .GetFilterOptions(categoryId.HasValue ? new string[] { } : details.Categories, details.Topics).ToList(); var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions( new SearchOptions(searchString), new SortOptions(sortBy, sortDirection), new FilterOptions( existingFilterString, availableFilters, CourseStatusFilterOptions.IsActive.FilterValue ), new PaginationOptions(page, itemsPerPage) ); var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate( details.Courses, searchSortPaginationOptions ); var model = new CourseSetupViewModel( result, availableFilters, config ); Response.UpdateFilterCookie(CourseFilterCookieName, result.FilterString); return(View(model)); }
public IActionResult Index( string?searchString = null, string?sortBy = null, string sortDirection = BaseSearchablePageViewModel.Ascending, string?filterBy = null, string?filterValue = null, int page = 1 ) { sortBy ??= DefaultSortByOptions.Name.PropertyName; filterBy = FilteringHelper.GetFilterBy( filterBy, filterValue, Request, CourseFilterCookieName, CourseStatusFilterOptions.IsActive.FilterValue ); var centreId = User.GetCentreId(); var categoryId = User.GetAdminCourseCategoryFilter(); var centreCourses = courseService.GetCentreSpecificCourseStatistics(centreId, categoryId); var categories = courseCategoriesDataService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId) .Select(c => c.CategoryName); var topics = courseTopicsDataService.GetCourseTopicsAvailableAtCentre(centreId).Select(c => c.CourseTopic); var model = new CourseSetupViewModel( centreCourses, categories, topics, searchString, sortBy, sortDirection, filterBy, page ); Response.UpdateOrDeleteFilterCookie(CourseFilterCookieName, filterBy); return(View(model)); }
public void CourseSetupViewModel_should_correctly_return_the_second_page_of_delegates() { // When var model = new CourseSetupViewModel( courses, new List <string>(), new List <string>(), null, nameof(CourseStatistics.SearchableName), BaseSearchablePageViewModel.Ascending, null, 2 ); // Then using (new AssertionScope()) { model.Courses.Count().Should().Be(5); model.Courses.First().CourseName.Should().BeEquivalentTo("K"); } }
public void CourseSetupViewModel_should_default_to_returning_the_first_page_worth_of_delegates() { // When var model = new CourseSetupViewModel( courses, new List <string>(), new List <string>(), null, nameof(CourseStatistics.SearchableName), BaseSearchablePageViewModel.Ascending, null, 1 ); // Then using (new AssertionScope()) { model.Courses.Count().Should().Be(BasePaginatedViewModel.DefaultItemsPerPage); model.Courses.Any(c => c.CourseName == "K").Should() .BeFalse(); } }