예제 #1
0
        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");
        }
예제 #2
0
        public override void Initialize()
        {
            base.Initialize();
            using (var productRepository = new ProductRepository())
                using (var searchResultRepository = new SearchResultRepository())
                    using (var searchWordRepository = new SearchWordRepository())
                    {
                        var product1 = productRepository.Create("TestProduct1", new DateTime(2001, 1, 1));
                        var product2 = productRepository.Create("TestProduct2", new DateTime(2002, 2, 2));


                        var searchWord2 = searchWordRepository.Create(product2, "SearchWord1");
                        searchResultRepository.Create(searchWord2, product2, 100, new DateTime(2010, 1, 1));
                        searchResultRepository.Create(searchWord2, product2, 200, new DateTime(2010, 1, 2));

                        var product3 = productRepository.Create("TestProduct3", new DateTime(2003, 3, 3));
                    }
        }
예제 #3
0
        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 async Task Add_SuccessfulAdded()
        {
            var name       = "Add_SuccessfulAdded";
            var options    = GetTestContextOptions(name);
            var engineName = "TestEngine";

            using (var context = new SearchContext(options))
            {
                var service = new SearchResultRepository(context);
                await service.Add(GetTestSearchResutVM(name, "Query", engineName));
            }
            using (var context = new SearchContext(options))
            {
                Assert.Equal(1, context.SearchResults.Count());
                Assert.Equal($"{ name }+{ engineName }", context.SearchResults.Single().EngineName);
                Assert.Equal(2, context.FoundItems.Count());
                Assert.Equal(2, context.FoundItems.Where(i => i.Title.Contains("title")).Count());
            }
        }
예제 #5
0
        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);
        }
        public async Task Contains_Successful()
        {
            var excpected = 10;
            var options   = GetTestContextOptions("Contains_Successful");

            using (var context = new SearchContext(options))
            {
                var range = Enumerable
                            .Range(100, excpected)
                            .Select(i => GetTestSearchResut(i.ToString(),
                                                            "aBccDD", "TestEngine"));
                context.SearchResults.AddRange(range);
                context.SaveChanges();
            }
            using (var context = new SearchContext(options))
            {
                var service = new SearchResultRepository(context);
                var result  = await service.Contains("BccD");

                Assert.Equal(excpected, result.Count());
            }
        }