コード例 #1
0
        public void WithNullInputStr_ShouldThrowException()
        {
            var minKeywordLength = 1;

            Assert.Throws <NullReferenceException>(() =>
                                                   ParameterParser.ParseSearchKeyWordsParameter(null, minKeywordLength));
        }
コード例 #2
0
        public void WithEmptyInputStr_ShouldReturnEmptyCollection()
        {
            var keyInputStr      = "";
            var minKeywordLength = 1;

            var result = ParameterParser.ParseSearchKeyWordsParameter(keyInputStr, minKeywordLength);

            Assert.Empty(result);
        }
コード例 #3
0
        public void WithKeyWordAndSeriesKeyWord_ShouldReturnCombineSeriesWithKeyWordBehind()
        {
            var keyInputStr      = "3 series";
            var minKeywordLength = 2;

            var result = ParameterParser.ParseSearchKeyWordsParameter(keyInputStr, minKeywordLength);

            Assert.Single(result);
            Assert.Equal(keyInputStr, result.First());
        }
コード例 #4
0
        public void WithKeyWords_ShouldFilterKeyWordsByMinKeywordLength()
        {
            var keyWordWithAboveMinLength = "333";
            var keyInputStr      = $"1 22 22 {keyWordWithAboveMinLength}";
            var minKeywordLength = 3;

            var result = ParameterParser.ParseSearchKeyWordsParameter(keyInputStr, minKeywordLength);

            Assert.Single(result);
            Assert.Equal(keyWordWithAboveMinLength, result.First());
        }
コード例 #5
0
        public async Task <IActionResult> Index(SearchBindingModel model)
        {
            var cookie = this.HttpContext.Request.Cookies;

            var sortDirectionKey = WebConstants.CookieUserSearchCarsSortDirectionKey;
            var sortDirection    = this.cookiesService.GetValueOrDefault <SortStrategyDirection>(cookie, sortDirectionKey);

            var sortTypeKey = WebConstants.CookieUserSearchCarsSortTypeKey;
            var sortType    = this.cookiesService.GetValueOrDefault <BaseCarSortStrategyType>(cookie, sortTypeKey);

            var sortStrategy = BaseCarSortStrategyFactory
                               .GetStrategy <BaseCar>(sortType, sortDirection);

            var splitedKeyWords = ParameterParser
                                  .ParseSearchKeyWordsParameter(model.KeyWords, WebConstants.MinSearchKeyWordLength)
                                  .Distinct()
                                  .ToArray();
            var filterStrategies = CarSearchFilterStrategyFactory.GetStrategies(splitedKeyWords);

            IEnumerable <CarInventoryConciseViewModel> carViewModels = new List <CarInventoryConciseViewModel>();
            int totalPagesCount = 0;

            if (filterStrategies.Count > 0)
            {
                var filteredCars          = this.carsService.GetFiltered <BaseCar>(filterStrategies.ToArray());
                var filteredAndSortedCars = sortStrategy.Sort(filteredCars);

                carViewModels = await(await this.carTestDriveService
                                      .GetCarTestDriveModelAsync <CarConciseTestDriveServiceModel>(filteredAndSortedCars, this.User, model.PageNumber))
                                .To <CarInventoryConciseViewModel>()
                                .ToArrayAsync();

                totalPagesCount = await PaginationHelper.CountTotalPagesCountAsync(filteredCars);
            }

            var searchModel = new CarSearchViewModel()
            {
                Cars = carViewModels,
                SortStrategyDirection = sortDirection,
                SortStrategyType      = sortType,
                CurrentPage           = model.PageNumber,
                TotalPagesCount       = totalPagesCount,
                KeyWords = splitedKeyWords
            };

            return(View(searchModel));
        }