Пример #1
0
        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,
                DelegateGroupsFilterCookieName
                );

            var centreId = User.GetCentreId();
            var groups   = groupsService.GetGroupsForCentre(centreId).ToList();

            var model = new DelegateGroupsViewModel(
                groups,
                GetRegistrationPromptsWithSetOptions(centreId),
                searchString,
                sortBy,
                sortDirection,
                filterBy,
                page
                );

            Response.UpdateOrDeleteFilterCookie(DelegateGroupsFilterCookieName, filterBy);

            return(View(model));
        }
Пример #2
0
        public void Setup()
        {
            centreCustomPromptsService = A.Fake <ICentreCustomPromptsService>();
            groupsService = A.Fake <IGroupsService>();
            userService   = A.Fake <IUserService>();
            courseService = A.Fake <ICourseService>();

            A.CallTo(() => groupsService.GetGroupsForCentre(A <int> ._)).Returns(new List <Group>());
            A.CallTo(() => centreCustomPromptsService.GetCustomPromptsForCentreByCentreId(A <int> ._))
            .Returns(prompts);

            httpRequest  = A.Fake <HttpRequest>();
            httpResponse = A.Fake <HttpResponse>();
            const string cookieName  = "DelegateGroupsFilter";
            const string cookieValue = "LinkedToField|LinkedToField|0";

            delegateGroupsController = new DelegateGroupsController(
                centreCustomPromptsService,
                groupsService,
                userService,
                courseService
                )
                                       .WithMockHttpContext(httpRequest, cookieName, cookieValue, httpResponse)
                                       .WithMockUser(true)
                                       .WithMockServices()
                                       .WithMockTempData();
        }
Пример #3
0
        public void Index_calls_expected_methods_and_returns_view()
        {
            // When
            var result = delegateGroupsController.Index();

            // Then
            using (new AssertionScope())
            {
                A.CallTo(() => groupsService.GetGroupsForCentre(A <int> ._)).MustHaveHappened();
                A.CallTo(
                    () => searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                        A <IEnumerable <Group> > ._,
                        A <SearchSortFilterAndPaginateOptions> ._
                        )
                    ).MustHaveHappened();
                A.CallTo(
                    () => httpResponse.Cookies.Append(
                        CookieName,
                        A <string> ._,
                        A <CookieOptions> ._
                        )
                    )
                .MustHaveHappened();
                result.Should().BeViewResult().WithDefaultViewName();
            }
        }
Пример #4
0
        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
            )
        {
            sortBy ??= DefaultSortByOptions.Name.PropertyName;
            existingFilterString = FilteringHelper.GetFilterString(
                existingFilterString,
                newFilterToAdd,
                clearFilters,
                Request,
                DelegateGroupsFilterCookieName
                );

            var centreId            = User.GetCentreId();
            var groups              = groupsService.GetGroupsForCentre(centreId).ToList();
            var registrationPrompts = GetRegistrationPromptsWithSetOptions(centreId);
            var availableFilters    = DelegateGroupsViewModelFilterOptions
                                      .GetDelegateGroupFilterModels(groups, registrationPrompts).ToList();

            var searchSortPaginationOptions = new SearchSortFilterAndPaginateOptions(
                new SearchOptions(searchString),
                new SortOptions(sortBy, sortDirection),
                new FilterOptions(existingFilterString, availableFilters),
                new PaginationOptions(page)
                );

            var result = searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                groups,
                searchSortPaginationOptions
                );

            var model = new DelegateGroupsViewModel(
                result,
                availableFilters
                );

            Response.UpdateFilterCookie(DelegateGroupsFilterCookieName, result.FilterString);

            return(View(model));
        }
Пример #5
0
        public void GetGroupsForCentre_returns_expected_groups()
        {
            // Given
            const int centreId = 1;
            var       groups   = Builder <Group> .CreateListOfSize(10).Build();

            A.CallTo(() => groupsDataService.GetGroupsForCentre(centreId)).Returns(groups);

            // When
            var result = groupsService.GetGroupsForCentre(centreId).ToList();

            // Then
            result.Should().HaveCount(10);
            result.Should().BeEquivalentTo(groups);
        }
Пример #6
0
        public void Setup()
        {
            groupsService = A.Fake <IGroupsService>();
            userService   = A.Fake <IUserService>();
            courseService = A.Fake <ICourseService>();
            searchSortFilterPaginateService = A.Fake <ISearchSortFilterPaginateService>();

            A.CallTo(() => groupsService.GetGroupsForCentre(A <int> ._)).Returns(new List <Group>());

            httpRequest  = A.Fake <HttpRequest>();
            httpResponse = A.Fake <HttpResponse>();
            const string cookieValue = "CategoryName|CategoryName|Category";

            groupCoursesController = new GroupCoursesController(
                userService,
                courseService,
                groupsService,
                searchSortFilterPaginateService
                )
                                     .WithMockHttpContext(httpRequest, CookieName, cookieValue, httpResponse)
                                     .WithMockUser(true)
                                     .WithMockServices()
                                     .WithMockTempData();
        }