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", IsAvailable = true }; productViewModel.ShouldBeEquivalentTo(expected); }
private CatalogEntrySearchCriteria CreateCriteria(IContent currentContent, FilterOptionFormModel filterOptions) { var pageSize = filterOptions.PageSize > 0 ? filterOptions.PageSize : _defaultPageSize; 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); }
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); }
public void QuickSearch_WhenQueryIsEmpty_ShouldReturnEmptyList() { var filterOptions = new FilterOptionFormModel(); var result = _subject.QuickSearch(filterOptions); result.Should().BeEmpty(); }
public IEnumerable <ProductViewModel> QuickSearch(string query) { var filterOptions = new FilterOptionFormModel { Q = query, PageSize = 5, Sort = string.Empty }; return(QuickSearch(filterOptions)); }
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); }
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)); }
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 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)))); }
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 QuickSearch_WhenQueryContainsWaveCharacter_ShouldRemoveWaveCharacterFromQuery() { 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 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 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 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 Search_WhenQueryContainsSeparatorCharacter_ShouldRemoveSeparatorCharacterFromQuery() { 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_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); }
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 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]); } }
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); }
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 ActionResult Index(SearchPage currentPage, FilterOptionFormModel formModel) { var model = _viewModelFactory.Create(currentPage, formModel); return(View(model)); }
public ActionResult Index(FashionNode currentContent, FilterOptionFormModel formModel) { var model = _viewModelFactory.Create(currentContent, formModel); return(Request.IsAjaxRequest() ? PartialView(model) : (ActionResult)View(model)); }