Пример #1
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);
        }
Пример #2
0
        public virtual async Task <CategoryBrowsingViewModel> GetCategoryBrowsingViewModelAsync(GetCategoryBrowsingViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CategoryId == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CategoryId)), nameof(param));
            }
            if (param.SelectedFacets == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.SelectedFacets)), nameof(param));
            }

            var node = await GetCurrentCategoryNodeAsync(param).ConfigureAwait(false);

            var landingPageUrls = GetLandingPageUrls(node, param);

            var viewModel = new CategoryBrowsingViewModel
            {
                CategoryId           = param.CategoryId,
                CategoryName         = param.CategoryName,
                SelectedFacets       = await GetSelectedFacetsAsync(param).ConfigureAwait(false),
                ProductSearchResults = await GetProductSearchResultsAsync(param).ConfigureAwait(false),
                ChildCategories      = await GetChildCategoriesAsync(param).ConfigureAwait(false),
                LandingPageUrls      = landingPageUrls
            };

            return(viewModel);
        }
Пример #3
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();
        }
Пример #4
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);
        }
Пример #5
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();
        }
Пример #6
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);
        }
Пример #7
0
        public async Task <CategoryBrowsingViewModel> GetCategoryBrowsingViewModelAsync(GetCategoryBrowsingViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (param.CategoryId == null)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CategoryId"));
            }
            if (param.SelectedFacets == null)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("SelectedFacets"));
            }

            var viewModel = new CategoryBrowsingViewModel
            {
                CategoryId           = param.CategoryId,
                CategoryName         = param.CategoryName,
                SelectedFacets       = await GetSelectedFacetsAsync(param).ConfigureAwait(false),
                ProductSearchResults = await GetProductSearchResultsAsync(param).ConfigureAwait(false),
                ChildCategories      = await GetChildCategoriesAsync(param).ConfigureAwait(false)
            };

            viewModel.Context["ProductSearchResults"] = viewModel.ProductSearchResults;
            viewModel.Context["ListName"]             = "Category Browsing";

            return(viewModel);
        }
Пример #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
 protected virtual void ExtendSpecificViewsWithContext(string viewName, CategoryBrowsingViewModel model)
 {
     model.Context["SearchResults"]         = model.ProductSearchResults.SearchResults;
     model.Context["Keywords"]              = model.ProductSearchResults.Keywords;
     model.Context["TotalCount"]            = model.ProductSearchResults.TotalCount;
     model.Context["MaxItemsPerPage"]       = model.MaxItemsPerPage;
     model.Context["ListName"]              = model.ListName;
     model.Context["PaginationCurrentPage"] = model.ProductSearchResults.Pagination.Pages.FirstOrDefault(p => p.IsCurrentPage);
 }
Пример #10
0
 static BrowsingCategoriesBaseController()
 {
     EmptyCategoryBrowsingContainer = new CategoryBrowsingViewModel
     {
         ProductSearchResults = new ProductSearchResultsViewModel {
             Keywords = string.Empty
         }
     };
 }
Пример #11
0
        public virtual async Task <CategoryBrowsingViewModel> GetCategoryBrowsingViewModelAsync(GetCategoryBrowsingViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CategoryId == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CategoryId)), nameof(param));
            }
            if (param.SelectedFacets == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.SelectedFacets)), nameof(param));
            }

            var node = await GetCurrentCategoryNodeAsync(param).ConfigureAwait(false);

            var landingPageUrls = GetLandingPageUrls(node, param);

            var viewModel = new CategoryBrowsingViewModel
            {
                CategoryId    = param.CategoryId,
                CategoryName  = param.CategoryName,
                FacetSettings = new FacetSettingsViewModel()
                {
                    SelectedFacets = await GetSelectedFacetsAsync(param).ConfigureAwait(false),
                },
                ProductSearchResults = await GetProductSearchResultsAsync(param).ConfigureAwait(false),
                LandingPageUrls      = landingPageUrls,
                ListName             = "Category Browsing"
            };

            viewModel.FacetSettings.CategoryFacetValuesTree = await BuildCategoryFacetValuesTree(viewModel.ProductSearchResults.Facets,
                                                                                                 viewModel.FacetSettings.SelectedFacets,
                                                                                                 viewModel.ProductSearchResults.CategoryFacetCounts).ConfigureAwait(false);

            if (viewModel.FacetSettings.CategoryFacetValuesTree != null)
            {
                var categoryRoot = CategoryRootNode(viewModel.FacetSettings.CategoryFacetValuesTree.ChildNodes, param.CategoryId);
                viewModel.FacetSettings.CategoryFacetValuesTree.TotalCount = categoryRoot != null ? categoryRoot.Quantity : 0;
                viewModel.FacetSettings.CategoryFacetValuesTree.ChildNodes = categoryRoot?.ChildNodes;
                viewModel.FacetSettings.CategoryFacetValuesTree.ChildNodes?.ForEach(childNode => BuildCategoryUrlsForTreeNode(param, childNode));
                viewModel.FacetSettings.CategoryFacetValuesTree.ChildNodes?.ForEach(childNode => CleanSiblingFacets(param, childNode));
                viewModel.FacetSettings.Context["CategoryFacetValuesTree"] = viewModel.FacetSettings.CategoryFacetValuesTree;
            }

            // Json context for Facets
            viewModel.FacetSettings.Context["SelectedFacets"]      = viewModel.FacetSettings.SelectedFacets;
            viewModel.FacetSettings.Context["Facets"]              = viewModel.ProductSearchResults.Facets.Where(f => !f.FieldName.StartsWith(SearchConfiguration.CategoryFacetFiledNamePrefix));
            viewModel.FacetSettings.Context["PromotedFacetValues"] = viewModel.ProductSearchResults.PromotedFacetValues;

            return(viewModel);
        }
Пример #12
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);
        }
Пример #13
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();
        }
Пример #14
0
 static BrowsingCategoriesBaseController()
 {
     EmptyCategoryBrowsingContainer = new CategoryBrowsingViewModel
     {
         SelectedFacets = new SelectedFacets {
             Facets = new List <SelectedFacet>()
         },
         ProductSearchResults = new ProductSearchResultsViewModel {
             Keywords = string.Empty
         },
         ChildCategories = new List <ChildCategoryViewModel>()
     };
 }
Пример #15
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"));
        }
Пример #16
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();
        }