public void Search_ShouldReturnPopulatedFacetGroupOption()
        {
            var content = new NodeContent();
            var filterOptions = new FilterOptionFormModel { FacetGroups = new List<FacetGroupOption>() };

            var result = _subject.Search(content, filterOptions);

            var facetGroupOption = result.FacetGroups.First();

            var expected = new FacetGroupOption
            {
                GroupName = "FacetGroupName",
                GroupFieldName = "FacetGroupFieldName",
                Facets = new List<FacetOption>
                {
                    new FacetOption
                    {
                        Name = _facet.Name,
                        Key = _facet.Key,
                        Selected = _facet.IsSelected,
                        Count = _facet.Count
                    }
                }
            };

            facetGroupOption.ShouldBeEquivalentTo(expected);
        }
Exemple #2
0
 protected virtual void SetupModel(FilterOptionFormModel model, string q, string sort, string facets, IContent content)
 {
     EnsurePage(model);
     EnsureQ(model, q);
     EnsureSort(model, sort);
     EnsureFacets(model, facets, content);
 }
Exemple #3
0
        public virtual SearchViewModel <T> Create <T>(T currentContent, FilterOptionFormModel formModel) where T : IContent
        {
            if (formModel.Q != null && (formModel.Q.StartsWith("*") || formModel.Q.StartsWith("?")))
            {
                return(new SearchViewModel <T>
                {
                    CurrentContent = currentContent,
                    FormModel = formModel,
                    HasError = true,
                    ErrorMessage = _localizationService.GetString("/Search/BadFirstCharacter")
                });
            }

            var customSearchResult = _searchService.Search(currentContent, formModel);

            formModel.TotalCount  = customSearchResult.SearchResult != null ? customSearchResult.SearchResult.TotalCount : 0;
            formModel.FacetGroups = customSearchResult.FacetGroups.ToList();

            formModel.Sorting = _searchService.GetSortOrder().Select(x => new SelectListItem
            {
                Text     = _localizationService.GetString("/Category/Sort/" + x.Name),
                Value    = x.Name.ToString(),
                Selected = string.Equals(x.Name.ToString(), formModel.Sort)
            });

            return(new SearchViewModel <T>
            {
                CurrentContent = currentContent,
                ProductViewModels = customSearchResult.ProductViewModels,
                Facets = customSearchResult.SearchResult != null ? customSearchResult.SearchResult.FacetGroups : new ISearchFacetGroup[0],
                FormModel = formModel
            });
        }
Exemple #4
0
 protected virtual void EnsureSort(FilterOptionFormModel model, string sort)
 {
     if (string.IsNullOrEmpty(model.Sort))
     {
         model.Sort = sort;
     }
 }
Exemple #5
0
 protected virtual void EnsureQ(FilterOptionFormModel model, string q)
 {
     if (string.IsNullOrEmpty(model.Q))
     {
         model.Q = q;
     }
 }
Exemple #6
0
 protected virtual void EnsureFacets(FilterOptionFormModel model, string facets, IContent content)
 {
     if (model.FacetGroups == null)
     {
         model.FacetGroups = CreateFacetGroups(facets, content);
     }
 }
Exemple #7
0
 protected virtual void EnsurePage(FilterOptionFormModel model)
 {
     if (model.Page < 1)
     {
         model.Page = 1;
     }
 }
 protected virtual void EnsurePage(FilterOptionFormModel model)
 {
     if (model.Page < 1)
     {
         model.Page = 1;
     }
 }
 protected virtual void SetupModel(FilterOptionFormModel model, string q, string sort, string facets, IContent content)
 {
     EnsurePage(model);
     EnsureQ(model, q);
     EnsureSort(model, sort);
     EnsureFacets(model, facets, content);
 }
 protected virtual void EnsureQ(FilterOptionFormModel model, string q)
 {
     if (string.IsNullOrEmpty(model.Q))
     {
         model.Q = q;
     }
 }
 protected virtual void EnsureSort(FilterOptionFormModel model, string sort)
 {
     if (string.IsNullOrEmpty(model.Sort))
     {
         model.Sort = sort;
     }
 }
        public void Search_ShouldReturnSameSearchResult()
        {
            var content = new NodeContent();
            var filterOptions = new FilterOptionFormModel { FacetGroups = new List<FacetGroupOption>() };

            var result = _subject.Search(content, filterOptions);

            result.SearchResult.ShouldBeEquivalentTo(_searchResultsMock.Object);
        }
Exemple #13
0
 public IEnumerable<ProductViewModel> QuickSearch(string query)
 {
     var filterOptions = new FilterOptionFormModel
     {
         Q = query,
         PageSize = 5,
         Sort = string.Empty
     };
     return QuickSearch(filterOptions);
 }
        public void Create_WhenPassingFormModel_ShouldUseItAsFormModel()
        {
            // Arrange
            var formModel = new FilterOptionFormModel() { Q = "query" };

            // Act
            var result = _subject.Create<IContent>(null, formModel);

            // Assert
            Assert.AreEqual<FilterOptionFormModel>(formModel, result.FormModel);
        }
        public void Create_WhenQStartsWithStar_ShouldReportAsError()
        {
            // Arrange
            var formModel = new FilterOptionFormModel() { Q = "*query" };
            
            // Act
            var result = _subject.Create<IContent>(null, formModel);

            // Assert
            Assert.IsTrue(result.HasError);
        }
        public void Index_WhenPassingFormModel_ShouldPassItOnToFactory()
        {
            // Arrange
            var formModel = new FilterOptionFormModel();

            // Act
            _subject.Index(null, formModel);

            // Assert
            _viewModelFactoryMock.Verify(v => v.Create(It.IsAny<FashionNode>(), formModel));
        }
Exemple #17
0
        public CustomSearchResult Search(IContent currentContent, FilterOptionFormModel filterOptions)
        {
            if (filterOptions == null)
            {
                return CreateEmptyResult();
            }

            var criteria = CreateCriteria(currentContent, filterOptions);
            AddFacets(filterOptions.FacetGroups, criteria, currentContent);
            return Search(criteria, currentContent);
        }
        public void Create_WhenPassingContent_ShouldUseItAsCurrentContent()
        {
            // Arrange
            var formModel = new FilterOptionFormModel() { Q = "query" };
            var content = new Mock<IContent>().Object;

            // Act
            var result = _subject.Create<IContent>(content, formModel);

            // Assert
            Assert.AreEqual<IContent>(content, result.CurrentContent);
        }
Exemple #19
0
        public IEnumerable<ProductViewModel> QuickSearch(FilterOptionFormModel filterOptions)
        {
            if (String.IsNullOrEmpty(filterOptions.Q))
            {
                return Enumerable.Empty<ProductViewModel>();
            }

            var criteria = CreateCriteriaForQuickSearch(filterOptions);

            try
            {
                var searchResult = _search.Search(criteria);
                return CreateProductViewModels(searchResult);
            }
            catch (ParseException)
            {
                return new ProductViewModel[0];
            }
        }
        public void Search_ShouldReturnPopulatedProductViewModel()
        {
            var content = new NodeContent();
            var filterOptions = new FilterOptionFormModel { FacetGroups = new List<FacetGroupOption>() };

            var result = _subject.Search(content, filterOptions);

            var productViewModel = result.ProductViewModels.First();

            var expected = new ProductViewModel
            {
                DisplayName = "DisplayName",
                PlacedPrice = new Money(1, _currentCurrency),
                ExtendedPrice = new Money(1, _currentCurrency),
                ImageUrl = "/image.jpg",
                Url = "http://domain.com",
                Code = "Code",
                Brand = "Brand"
            };

            productViewModel.ShouldBeEquivalentTo(expected);
        }
        public void Create_WhenSearching_ShouldGetFacetsFromSearchResult()
        {
            // Arrange
            var formModel = new FilterOptionFormModel() { Q = "query" };

            // Act
            var result = _subject.Create<IContent>(null, formModel);

            // Assert
            Assert.AreEqual<ISearchFacetGroup[]>(_facetGroups, result.Facets);
        }
        public void QuickSearch_ShouldReturnPopulatedProductViewModel()
        {
            var filterOptions = new FilterOptionFormModel();
            filterOptions.Q = "query";

            var result = _subject.QuickSearch(filterOptions);

            var productViewModel = result.First();

            var expected = new ProductViewModel
            {
                DisplayName = "DisplayName",
                PlacedPrice = new Money(1, _currentCurrency),
                ExtendedPrice = new Money(1, _currentCurrency),
                ImageUrl = "/image.jpg",
                Url = "http://domain.com",
                Brand = "Brand",
                Code = "Code"
            };

            productViewModel.ShouldBeEquivalentTo(expected);
        }
        public void QuickSearch_ShouldFilterByCurrentMarket()
        {
            var filterOptions = new FilterOptionFormModel { Q = "query" };
            _subject.QuickSearch(filterOptions);

            var expected = _currentMarketMock.Object.GetCurrentMarket().MarketId;

            _searchFacadeMock.Verify(x => x.Search(It.Is<CatalogEntrySearchCriteria>(y => y.MarketId.Equals(expected))));
        }
Exemple #24
0
        private CatalogEntrySearchCriteria CreateCriteria(IContent currentContent, FilterOptionFormModel filterOptions)
        {
            var pageSize = filterOptions.PageSize > 0 ? filterOptions.PageSize : 20;
            var sortOrder = GetSortOrder().FirstOrDefault(x => x.Name.ToString() == filterOptions.Sort) ?? GetSortOrder().First();
            var market = _currentMarket.GetCurrentMarket();

            var criteria = new CatalogEntrySearchCriteria
            {
                ClassTypes = new StringCollection { "product" },
                Locale = _preferredCulture.Name,
                MarketId = market.MarketId,
                StartingRecord = pageSize * (filterOptions.Page - 1),
                RecordsToRetrieve = pageSize,
                Sort = new SearchSort(new SearchSortField(sortOrder.Key, sortOrder.SortDirection == SortDirection.Descending))
            };
            
            var nodeContent = currentContent as NodeContent;
            if (nodeContent != null)
            {
                criteria.Outlines = _search.GetOutlinesForNode(nodeContent.Code);
            }
            if (!string.IsNullOrEmpty(filterOptions.Q))
            {
                criteria.SearchPhrase = GetEscapedSearchPhrase(filterOptions.Q);
            }

            return criteria;
        }
Exemple #25
0
        private CatalogEntrySearchCriteria CreateCriteriaForQuickSearch(FilterOptionFormModel filterOptions)
        {
            var sortOrder = GetSortOrder().FirstOrDefault(x => x.Name.ToString() == filterOptions.Sort) ?? GetSortOrder().First();
            var market = _currentMarket.GetCurrentMarket();

            var criteria = new CatalogEntrySearchCriteria
            {
                ClassTypes = new StringCollection { "product" },
                Locale = _preferredCulture.Name,
                MarketId = market.MarketId,
                StartingRecord = 0,
                RecordsToRetrieve = filterOptions.PageSize,
                Sort = new SearchSort(new SearchSortField(sortOrder.Key, sortOrder.SortDirection == SortDirection.Descending)),
                SearchPhrase = GetEscapedSearchPhrase(filterOptions.Q)
            };

            return criteria;
        }
 protected virtual void EnsureFacets(FilterOptionFormModel model, string facets, IContent content)
 {
     if (model.FacetGroups == null)
     {
         model.FacetGroups = CreateFacetGroups(facets, content);
     }
 }
        public void QuickSearch_WhenQueryContainsSeparatorCharacter_ShouldRemoveSeparatorCharacterFromQuery()
        {
            const string searchQuery = "start|end";
            const string expectedResult = "startend*";

            var filterOptions = new FilterOptionFormModel { Q = searchQuery };
            _subject.QuickSearch(filterOptions);

            _searchFacadeMock.Verify(x => x.Search(It.Is<CatalogEntrySearchCriteria>(y => y.SearchPhrase.Equals(expectedResult))));
        }
        public void Search_ShouldFilterByCurrentMarket()
        {
            var filterOptions = new FilterOptionFormModel { Q = "query", FacetGroups = new List<FacetGroupOption>() };
            var content = new NodeContent();
            _subject.Search(content, filterOptions);

            var expected = _currentMarketMock.Object.GetCurrentMarket().MarketId;

            _searchFacadeMock.Verify(x => x.Search(It.Is<CatalogEntrySearchCriteria>(y => y.MarketId.Equals(expected))));
        }
        public void Search_WhenQueryContainsWaveCharacter_ShouldRemoveWaveCharacterFromQuery()
        {
            const string searchQuery = "start~end";
            const string expectedResult = "startend*";

            var content = new NodeContent();
            var filterOptions = new FilterOptionFormModel { Q = searchQuery, FacetGroups = new List<FacetGroupOption>() };
            _subject.Search(content, filterOptions);

            _searchFacadeMock.Verify(x => x.Search(It.Is<CatalogEntrySearchCriteria>(y => y.SearchPhrase.Equals(expectedResult))));
        }
        public void Create_WhenSearching_ShouldSetTotalCountOnFormModel()
        {
            // Arrange
            var formModel = new FilterOptionFormModel() { Q = "query" };
            _searchResultsMock
                .Setup(s => s.TotalCount)
                .Returns(666);

            // Act
            var result = _subject.Create<IContent>(null, formModel);

            // Assert
            Assert.AreEqual<int>(666, result.FormModel.TotalCount);
        }
        public void Create_WhenSearching_ShouldGetProductViewModelsFromSearchResult()
        {
            // Arrange
            var formModel = new FilterOptionFormModel() { Q = "query" };

            // Act
            var result = _subject.Create<IContent>(null, formModel);

            // Assert
            Assert.AreEqual<IEnumerable<ProductViewModel>>(_productViewModels, result.ProductViewModels);
        }
        public void QuickSearch_WhenQueryIsEmpty_ShouldReturnEmptyList()
        {
            var filterOptions = new FilterOptionFormModel();

            var result = _subject.QuickSearch(filterOptions);

            result.Should().BeEmpty();
        }