public void GetPublicTutorialSummariesForBrand_calls_data_service_and_returns_expected_tutorials()
        {
            // Given
            var expectedTutorials = Builder <TutorialSummary> .CreateListOfSize(5).All().Build();

            A.CallTo(
                () => tutorialContentDataService.GetPublicTutorialSummariesByBrandId(1)
                ).Returns(expectedTutorials);

            // When
            var result = tutorialService.GetPublicTutorialSummariesForBrand(1);

            // Then
            result.Should().BeEquivalentTo(expectedTutorials);
        }
        public IActionResult Index(
            int brandId,
            int page                    = 1,
            string?sortBy               = null,
            string sortDirection        = GenericSortingHelper.Ascending,
            string?existingFilterString = null,
            string?newFilterToAdd       = null,
            bool clearFilters           = false
            )
        {
            var brand = brandsService.GetPublicBrandById(brandId);

            if (brand == null)
            {
                return(NotFound());
            }

            sortBy ??= DefaultSortByOptions.Name.PropertyName;
            existingFilterString = FilteringHelper.GetFilterString(
                existingFilterString,
                newFilterToAdd,
                clearFilters,
                Request,
                BrandCoursesFilterCookieName
                );

            var tutorials    = tutorialService.GetPublicTutorialSummariesForBrand(brandId);
            var applications = courseService.GetApplicationsThatHaveSectionsByBrandId(brandId).ToList();

            var categories       = applications.Select(x => x.CategoryName).Distinct().OrderBy(x => x).ToList();
            var topics           = applications.Select(x => x.CourseTopic).Distinct().OrderBy(x => x).ToList();
            var availableFilters = LearningContentViewModelFilterOptions
                                   .GetFilterOptions(categories, topics).ToList();

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

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

            var model = new LearningContentViewModel(result, availableFilters, brand, tutorials);

            Response.UpdateFilterCookie(BrandCoursesFilterCookieName, result.FilterString);

            return(View(model));
        }
Ejemplo n.º 3
0
        public void Index_returns_not_found_with_null_brand()
        {
            // Given
            A.CallTo(() => brandsService.GetPublicBrandById(A <int> ._)).Returns(null);

            // When
            var result = controller.Index(1);

            // Then
            using (new AssertionScope())
            {
                A.CallTo(() => tutorialService.GetPublicTutorialSummariesForBrand(A <int> ._)).MustNotHaveHappened();
                A.CallTo(() => courseService.GetApplicationsThatHaveSectionsByBrandId(A <int> ._)).MustNotHaveHappened();
                A.CallTo(
                    () => searchSortFilterPaginateService.SearchFilterSortAndPaginate(
                        A <IEnumerable <ApplicationWithSections> > ._,
                        A <SearchSortFilterAndPaginateOptions> ._
                        )
                    ).MustNotHaveHappened();
                result.Should().BeNotFoundResult();
            }
        }