Ejemplo n.º 1
0
        public void FilterOrResetFilterToDefault_returns_expected_default_filtered_items_with_invalid_filter()
        {
            // Given
            var          expectedItems = new[] { ItemA1, ItemA3 }.AsQueryable();
            const string defaultFilterString = "Name|Name|a";
            const string invalidFilterString = "Name|INVALID|a";
            var          availableFilters    = new List <FilterModel>
            {
                new FilterModel(
                    "Name",
                    "Name",
                    new List <FilterOptionModel> {
                    new FilterOptionModel("A", "Name|Name|A", FilterStatus.Default)
                }
                    ),
            };
            var filterOptions = new FilterOptions(invalidFilterString, availableFilters, defaultFilterString);

            // When
            var(resultItems, resultString) = FilteringHelper.FilterOrResetFilterToDefault(InputItems, filterOptions);

            // Then
            resultItems.Should().BeEquivalentTo(expectedItems);
            resultString.Should().BeEquivalentTo(defaultFilterString);
        }
Ejemplo n.º 2
0
        public SearchSortFilterPaginationResult <T> SearchFilterSortAndPaginate <T>(
            IEnumerable <T> items,
            SearchSortFilterAndPaginateOptions searchSortFilterAndPaginateOptions
            ) where T : BaseSearchableItem
        {
            var    allItems            = items.ToList();
            var    itemsToReturn       = allItems;
            string?appliedFilterString = null;
            var    javascriptSearchSortFilterPaginateShouldBeEnabled =
                allItems.Count <= configuration.GetJavascriptSearchSortFilterPaginateItemLimit();

            if (searchSortFilterAndPaginateOptions.SearchOptions != null)
            {
                itemsToReturn = (searchSortFilterAndPaginateOptions.SearchOptions.UseTokeniseScorer
                    ? GenericSearchHelper.SearchItemsUsingTokeniseScorer(
                                     itemsToReturn,
                                     searchSortFilterAndPaginateOptions.SearchOptions.SearchString,
                                     searchSortFilterAndPaginateOptions.SearchOptions.SearchMatchCutoff
                                     )
                    : GenericSearchHelper.SearchItems(
                                     itemsToReturn,
                                     searchSortFilterAndPaginateOptions.SearchOptions.SearchString,
                                     searchSortFilterAndPaginateOptions.SearchOptions.SearchMatchCutoff
                                     )).ToList();
            }

            if (searchSortFilterAndPaginateOptions.FilterOptions != null)
            {
                var filteringReturnTuple = FilteringHelper.FilterOrResetFilterToDefault(
                    itemsToReturn,
                    searchSortFilterAndPaginateOptions.FilterOptions
                    );
                itemsToReturn       = filteringReturnTuple.filteredItems.ToList();
                appliedFilterString = filteringReturnTuple.appliedFilterString;
            }

            if (searchSortFilterAndPaginateOptions.SortOptions != null)
            {
                itemsToReturn = GenericSortingHelper.SortAllItems(
                    itemsToReturn.AsQueryable(),
                    searchSortFilterAndPaginateOptions.SortOptions.SortBy,
                    searchSortFilterAndPaginateOptions.SortOptions.SortDirection
                    ).ToList();
            }

            var paginateResult = PaginateItems(
                itemsToReturn,
                searchSortFilterAndPaginateOptions.PaginationOptions,
                javascriptSearchSortFilterPaginateShouldBeEnabled
                );

            return(new SearchSortFilterPaginationResult <T>(
                       paginateResult,
                       searchSortFilterAndPaginateOptions.SearchOptions?.SearchString,
                       searchSortFilterAndPaginateOptions.SortOptions?.SortBy,
                       searchSortFilterAndPaginateOptions.SortOptions?.SortDirection,
                       appliedFilterString
                       ));
        }
Ejemplo n.º 3
0
        public void FilterOrResetFilterToDefault_returns_expected_unfiltered_items_with_invalid_filter_and_no_default()
        {
            // Given
            const string invalidFilterString = "Name|INVALID|a";
            var          availableFilters    = new List <FilterModel>
            {
                new FilterModel(
                    "Name",
                    "Name",
                    new List <FilterOptionModel> {
                    new FilterOptionModel("A", "Name|Name|A", FilterStatus.Default)
                }
                    ),
            };
            var filterOptions = new FilterOptions(invalidFilterString, availableFilters);

            // When
            var(resultItems, resultString) = FilteringHelper.FilterOrResetFilterToDefault(InputItems, filterOptions);

            // Then
            resultItems.Should().BeEquivalentTo(InputItems);
            resultString.Should().BeNull();
        }