public void GetSearchResult_ItemsWithDifferentProperties_ReturnItemsFulfillingPredicate( ISearchQueryElementProvider elementProvider, IIndexNameProvider indexNameProvider, ISearchQueryPredicateBuilder <TestIndexableEntity> predicateBuilder, ISearchIndex searchIndex, [Frozen] SearchProvider provider, Switcher <SearchProvider> switcher) { // Arrange elementProvider .GetSearchQueryElementRoot <TestIndexableEntity>() .Returns(new SearchQueryGrouping <TestIndexableEntity>(LogicalOperator.And)); indexNameProvider .IndexName .Returns("predicateTestIndex"); predicateBuilder .GetOutput() .Returns(x => x.Name.Contains("F")); var queryable = new QueryProviderStub <TestIndexableEntity>(new[] { CreateTestIndexableEntity("Faucet", paths: new List <ID> { ItemIDs.ContentRoot }), CreateTestIndexableEntity("Clamp", paths: new List <ID> { ItemIDs.ContentRoot }) }.AsQueryable()); searchIndex .CreateSearchContext() .GetQueryable <TestIndexableEntity>() .Returns(queryable); ContentSearchManager.SearchConfiguration.Indexes[indexNameProvider.IndexName] = searchIndex; var sut = new SearchResultRepository <TestIndexableEntity>(elementProvider, indexNameProvider, predicateBuilder); // Act var actual = sut.GetSearchResult(new SearchCriteria()); // Assert actual.TotalSearchResults.ShouldBeEquivalentTo(1); actual.Hits.First().Name.Should().Contain("F"); }
public void GetSearchResult_ItemsWithDiffentVersions_ReturnItemsWithLatestVersion( ISearchQueryElementProvider elementProvider, IIndexNameProvider indexNameProvider, ISearchQueryPredicateBuilder <TestIndexableEntity> predicateBuilder, ISearchIndex searchIndex, [Frozen] SearchProvider provider, Switcher <SearchProvider> switcher) { // Arrange indexNameProvider .IndexName .Returns("languageTestIndex"); predicateBuilder .GetOutput() .Returns(x => true); var queryable = new QueryProviderStub <TestIndexableEntity>(new[] { CreateTestIndexableEntity("Faucet", paths: new List <ID> { ItemIDs.ContentRoot }, latestVersion: true), CreateTestIndexableEntity("Fence", paths: new List <ID> { ItemIDs.ContentRoot }, latestVersion: false), }.AsQueryable()); searchIndex .CreateSearchContext() .GetQueryable <TestIndexableEntity>() .Returns(queryable); ContentSearchManager.SearchConfiguration.Indexes[indexNameProvider.IndexName] = searchIndex; var sut = new SearchResultRepository <TestIndexableEntity>(elementProvider, indexNameProvider, predicateBuilder); // Act var actual = sut.GetSearchResult(new SearchCriteria()); // Assert actual.TotalSearchResults.ShouldBeEquivalentTo(1); actual.Hits.First().Fields["_latestversion"].Should().Be("1"); }
public void GetSearchResult_ItemsBothContentAndNonContent_ReturnContentItems( ISearchQueryElementProvider elementProvider, IIndexNameProvider indexNameProvider, ISearchQueryPredicateBuilder <TestIndexableEntity> predicateBuilder, ISearchIndex searchIndex, [Frozen] SearchProvider provider, Switcher <SearchProvider> switcher) { // Arrange indexNameProvider .IndexName .Returns("contentItemTestIndex"); predicateBuilder .GetOutput() .Returns(x => true); var queryable = new QueryProviderStub <TestIndexableEntity>(new[] { CreateTestIndexableEntity("Faucet", paths: new List <ID> { ItemIDs.ContentRoot }), CreateTestIndexableEntity("Fence") }.AsQueryable()); searchIndex .CreateSearchContext() .GetQueryable <TestIndexableEntity>() .Returns(queryable); ContentSearchManager.SearchConfiguration.Indexes[indexNameProvider.IndexName] = searchIndex; var sut = new SearchResultRepository <TestIndexableEntity>(elementProvider, indexNameProvider, predicateBuilder); // Act var actual = sut.GetSearchResult(new SearchCriteria()); // Assert actual.TotalSearchResults.ShouldBeEquivalentTo(1); actual.Hits.First().Paths.Should().Contain(ItemIDs.ContentRoot); }