예제 #1
0
        public virtual async Task <IHttpActionResult> GetCategoryFacets(GetCategoryFacetsRequest request)
        {
            var param = new GetCategoryBrowsingViewModelParam
            {
                CategoryId           = request.CategoryId,
                CategoryName         = string.Empty,
                BaseUrl              = RequestUtils.GetBaseUrl(Request).ToString(),
                IsAllProducts        = false,
                NumberOfItemsPerPage = 0,
                Page                 = 1,
                SortBy               = "score",
                SortDirection        = "desc",
                InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false),
                CultureInfo          = ComposerContext.CultureInfo
            };

            if (!string.IsNullOrEmpty(request.QueryString))
            {
                var queryString = HttpUtility.ParseQueryString(request.QueryString);
                param.SelectedFacets = SearchUrlProvider.BuildSelectedFacets(queryString).ToList();
            }

            var viewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(param).ConfigureAwait(false);

            viewModel.ProductSearchResults.Facets = viewModel.ProductSearchResults.Facets.Where(f => !f.FieldName.StartsWith(SearchConfiguration.CategoryFacetFiledNamePrefix)).ToList();

            return(Ok(viewModel));
        }
예제 #2
0
        public virtual async Task <CategoryBrowsingViewModel> GetViewModelAsync()
        {
            if (_viewModel != null)
            {
                return(_viewModel);
            }
            var categoryId = CategoryMetaContext.GetCategoryId();

            _viewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId           = categoryId,
                CategoryName         = await GetCategoryNameAsync(categoryId).ConfigureAwait(false),
                BaseUrl              = RequestUtils.GetBaseUrl(Request).ToString(),
                IsAllProducts        = CategoryMetaContext.GetIsAllProductPage(),
                NumberOfItemsPerPage = SearchConfiguration.MaxItemsPerPage,
                Page                 = CurrentPage,
                SortBy               = SortBy,
                SortDirection        = SortDirection,
                InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false),
                SelectedFacets       = SearchUrlProvider.BuildSelectedFacets(Request.QueryString).ToList(),
                CultureInfo          = ComposerContext.CultureInfo,
            }).ConfigureAwait(false);

            return(_viewModel);
        }
예제 #3
0
        public async Task <CategoryBrowsingViewModel> GetCategoryAvailableProductsAsync(GetBrowseCategoryParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }

            if (ViewModel != null)
            {
                return(ViewModel);
            }

            ViewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId           = param.CategoryId,
                CategoryName         = await GetCategoryNameAsync(param.CategoryId),
                BaseUrl              = RequestUtils.GetBaseUrl(param.Request).ToString(),
                IsAllProducts        = CategoryMetaContext.GetIsAllProductPage(),
                Page                 = param.Page,
                SortBy               = param.SortBy,
                SortDirection        = param.SortDirection,
                InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync(),
                SelectedFacets       = SearchUrlProvider.BuildSelectedFacets(param.Request.QueryString).ToList(),
                CultureInfo          = ComposerContext.CultureInfo,
            }).ConfigureAwait(false);

            return(ViewModel);
        }
예제 #4
0
        public async Task WHEN_category_is_found_SHOULD_facet_is_not_removable()
        {
            // Arrange
            var categories = new List <Category>
            {
                new Category
                {
                    Id          = GetRandom.String(1),
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act
            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = categories[0].Id,
                SelectedFacets = new List <SearchFilter>()
            });

            // Assert
            model.SelectedFacets.Facets.First().IsRemovable.Should().BeFalse();
            model.SelectedFacets.IsAllRemovable.Should().BeFalse();
        }
예제 #5
0
        public async Task WHEN_category_has_no_child_SHOULD_view_model_contain_no_child_category()
        {
            // Arrange
            var categories = new List <Category>
            {
                new Category
                {
                    Id          = GetRandom.String(10),
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act
            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = categories[0].Id,
                SelectedFacets = new List <SearchFilter>()
            });

            // Assert
            model.ChildCategories.Count.Should().Be(0);
        }
예제 #6
0
        public async Task WHEN_category_id_found_SHOULD_have_landing_page_url()
        {
            // Arrange
            var categories = new List <Category>
            {
                new Category
                {
                    Id          = GetRandom.String(10),
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act
            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = categories[0].Id,
                SelectedFacets = new List <SearchFilter>()
            });

            // Assert
            model.LandingPageUrls.Should().BeNullOrEmpty();
        }
예제 #7
0
        public void WHEN_param_is_null_SHOULD_throw_argument_null_exception()
        {
            // Arrange
            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act & Assert
            Assert.ThrowsAsync <ArgumentNullException>(() => service.GetCategoryBrowsingViewModelAsync(null));
        }
예제 #8
0
        public async Task WHEN_category_has_children_SHOULD_view_model_contain_child_categories_with_correct_title()
        {
            // Arrange
            var parentId = GetRandom.String(10);

            var categories = new List <Category>
            {
                new Category
                {
                    Id          = parentId,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                },
                new Category
                {
                    Id          = GetRandom.String(10),
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level2_0" }
                    }),
                    PrimaryParentCategoryId = parentId
                },
                new Category
                {
                    Id          = GetRandom.String(10),
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level2_1" }
                    }),
                    PrimaryParentCategoryId = parentId
                },
                new Category
                {
                    Id          = GetRandom.String(10),
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level2_2" }
                    }),
                    PrimaryParentCategoryId = parentId
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act
            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = parentId,
                SelectedFacets = new List <SearchFilter>()
            });

            // Assert
            model.ChildCategories[0].Title.Should().Be(categories[1].DisplayName.GetLocalizedValue(CultureName));
            model.ChildCategories[1].Title.Should().Be(categories[2].DisplayName.GetLocalizedValue(CultureName));
            model.ChildCategories[2].Title.Should().Be(categories[3].DisplayName.GetLocalizedValue(CultureName));
        }
예제 #9
0
        public async Task WHEN_selected_category_is_children_SHOULD_return_filled_landingPageUrls()
        {
            // Arrange
            var level1Id = "level1";
            var level2Id = "level2";
            var level3Id = "level3";

            var categories = new List <Category>
            {
                new Category
                {
                    Id          = level1Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                },
                new Category
                {
                    Id          = level2Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level2_0" }
                    }),
                    PrimaryParentCategoryId = level1Id
                },
                new Category
                {
                    Id          = level3Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level3_0" }
                    }),
                    PrimaryParentCategoryId = level2Id
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act
            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = level3Id,
                SelectedFacets = new List <SearchFilter>()
            });

            //Assert
            model.Should().NotBeNull();
            model.LandingPageUrls.Should().NotBeNullOrEmpty();
            model.LandingPageUrls.Should().HaveCount(2);
            model.LandingPageUrls[0].Should().EndWith(level1Id);
            model.LandingPageUrls[1].Should().EndWith(level2Id);
        }
예제 #10
0
        public async Task WHEN_category_with_ancestors_is_found_SHOULD_facets_are_not_all_removable()
        {
            // Arrange
            var level1Id = GetRandom.String(10);
            var level2Id = GetRandom.String(10);
            var level3Id = GetRandom.String(10);

            var categories = new List <Category>
            {
                new Category
                {
                    Id          = level1Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                },
                new Category
                {
                    Id          = level2Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level2_0" }
                    }),
                    PrimaryParentCategoryId = level1Id
                },
                new Category
                {
                    Id          = level3Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level3_0" }
                    }),
                    PrimaryParentCategoryId = level2Id
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act
            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = level3Id,
                SelectedFacets = new List <SearchFilter>()
            });

            // Assert
            model.FacetSettings.SelectedFacets.Facets[0].IsRemovable.Should().BeFalse();
            model.FacetSettings.SelectedFacets.Facets[1].IsRemovable.Should().BeFalse();
            model.FacetSettings.SelectedFacets.Facets[2].IsRemovable.Should().BeFalse();

            model.FacetSettings.SelectedFacets.IsAllRemovable.Should().BeFalse();
        }
예제 #11
0
        public void WHEN_selected_facets_is_null_SHOULD_throw_argument_exception()
        {
            // Arrange
            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act & Assert
            Assert.ThrowsAsync <ArgumentException>(() => service.GetCategoryBrowsingViewModelAsync(
                                                       new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = GetRandom.String(1),
                SelectedFacets = null
            }
                                                       ));
        }
예제 #12
0
        public async Task WHEN_category_is_found_SHOULD_selected_facets_contain_self_and_all_ancestors_whose_field_name_ends_with_Facet()
        {
            // Arrange
            var level1Id = GetRandom.String(10);
            var level2Id = GetRandom.String(10);
            var level3Id = GetRandom.String(10);

            var categories = new List <Category>
            {
                new Category
                {
                    Id          = level1Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                },
                new Category
                {
                    Id          = level2Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level2_0" }
                    }),
                    PrimaryParentCategoryId = level1Id
                },
                new Category
                {
                    Id          = level3Id,
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level3_0" }
                    }),
                    PrimaryParentCategoryId = level2Id
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act
            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = level3Id,
                SelectedFacets = new List <SearchFilter>()
            });

            // Assert
            model.SelectedFacets.Facets.Should().OnlyContain(facet => facet.FieldName.EndsWith("_Facet"));
        }
예제 #13
0
        public void WHEN_category_id_not_found_SHOULD_throw_invalid_operation_exception()
        {
            // Arrange
            SetupCategoryRepository();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            // Act & Assert
            Assert.ThrowsAsync <InvalidOperationException>(() => service.GetCategoryBrowsingViewModelAsync(
                                                               new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = GetRandom.String(1),
                SelectedFacets = new List <SearchFilter>()
            }
                                                               ));
        }
예제 #14
0
        public virtual async Task <IHttpActionResult> GetSearchResults(GetSearchResultsRequest request)
        {
            var queryString    = HttpUtility.ParseQueryString(request.QueryString ?? "");
            var SelectedFacets = SearchUrlProvider.BuildSelectedFacets(queryString).ToList();
            var CurrentPage    = int.TryParse(queryString[SearchRequestParams.Page], out int page) && page > 0 ? page : 1;
            var SortDirection  = queryString[SearchRequestParams.SortDirection] ?? SearchRequestParams.DefaultSortDirection;
            var SortBy         = queryString[SearchRequestParams.SortBy] ?? SearchRequestParams.DefaultSortBy;
            var BaseUrl        = RequestUtils.GetBaseUrl(Request).ToString();
            var Keywords       = queryString[SearchRequestParams.Keywords];
            BaseSearchViewModel viewModel;

            if (!string.IsNullOrEmpty(request.CategoryId))
            {
                var param = new GetCategoryBrowsingViewModelParam
                {
                    CategoryId           = request.CategoryId,
                    CategoryName         = string.Empty,
                    BaseUrl              = BaseUrl,
                    IsAllProducts        = false,
                    NumberOfItemsPerPage = SearchConfiguration.MaxItemsPerPage,
                    Page                 = CurrentPage,
                    SortBy               = SortBy,
                    SortDirection        = SortDirection,
                    InventoryLocationIds = await InventoryLocationProvider.GetInventoryLocationIdsForSearchAsync().ConfigureAwait(false),
                    SelectedFacets       = SelectedFacets,
                    CultureInfo          = ComposerContext.CultureInfo,
                };

                viewModel = await CategoryBrowsingViewService.GetCategoryBrowsingViewModelAsync(param).ConfigureAwait(false);
            }
            else
            {
                var searchCriteria = await BaseSearchCriteriaProvider.GetSearchCriteriaAsync(Keywords, BaseUrl, true, CurrentPage).ConfigureAwait(false);

                searchCriteria.SortBy        = SortBy;
                searchCriteria.SortDirection = SortDirection;
                searchCriteria.SelectedFacets.AddRange(SelectedFacets);

                viewModel = await SearchViewService.GetSearchViewModelAsync(searchCriteria).ConfigureAwait(false);
            }

            viewModel.ProductSearchResults.Facets = viewModel.ProductSearchResults.Facets.Where(f => !f.FieldName.StartsWith(SearchConfiguration.CategoryFacetFiledNamePrefix)).ToList();
            return(Ok(viewModel));
        }
예제 #15
0
        public async Task WHEN_param_contains_system_facet_SHOULD_facet_is_not_removable()
        {
            // Arrange
            var categories = new List <Category>
            {
                new Category
                {
                    Id          = GetRandom.String(1),
                    DisplayName = new LocalizedString(new Dictionary <string, string> {
                        { CultureName, "level1_0" }
                    })
                }
            };

            SetupCategoryRepository(categories);
            SetupCategoryUrlProvider();

            CategoryBrowsingViewService service = _container.CreateInstance <CategoryBrowsingViewService>();

            var facetName = GetRandom.String(5);

            SetupFacets(new FacetSetting(facetName));

            // Act
            var expectedFacet = new SearchFilter
            {
                Name     = facetName,
                IsSystem = true
            };

            CategoryBrowsingViewModel model = await service.GetCategoryBrowsingViewModelAsync(new GetCategoryBrowsingViewModelParam
            {
                CategoryId     = categories[0].Id,
                SelectedFacets = new List <SearchFilter> {
                    expectedFacet
                }
            });

            // Assert
            model.SelectedFacets.Facets.First(facet => facet.FieldName == expectedFacet.Name).IsRemovable.Should().BeFalse();
        }