public TestIndex(ILoggerFactory loggerFactory, string name, Directory luceneDirectory, string[] fieldNames)
     : base(
         loggerFactory,
         name,
         IndexInitializer.GetOptions(name, new LuceneDirectoryIndexOptions
 {
     DirectoryFactory = new GenericDirectoryFactory(s => luceneDirectory)
 }))
 {
     _fieldNames = fieldNames;
 }
Пример #2
0
        public void GivenEmptyIndex_WhenUsingWithContentAndMediaPopulators_ThenIndexPopulated()
        {
            var mediaRebuilder = IndexInitializer.GetMediaIndexRebuilder(IndexInitializer.GetMockMediaService());

            using (GetSynchronousContentIndex(false, out UmbracoContentIndex index, out ContentIndexPopulator contentRebuilder, out _, null))
            {
                //create the whole thing
                contentRebuilder.Populate(index);
                mediaRebuilder.Populate(index);

                var result = index.Searcher.CreateQuery().All().Execute();

                Assert.AreEqual(29, result.TotalItemCount);
            }
        }
Пример #3
0
        /// <summary>
        /// Used to create and manage a testable index
        /// </summary>
        /// <param name="publishedValuesOnly"></param>
        /// <param name="index"></param>
        /// <param name="contentRebuilder"></param>
        /// <param name="contentValueSetBuilder"></param>
        /// <param name="parentId"></param>
        /// <returns></returns>
        protected IDisposable GetSynchronousContentIndex(
            bool publishedValuesOnly,
            out UmbracoContentIndex index,
            out ContentIndexPopulator contentRebuilder,
            out ContentValueSetBuilder contentValueSetBuilder,
            int?parentId = null,
            IContentService contentService = null)
        {
            contentValueSetBuilder = IndexInitializer.GetContentValueSetBuilder(publishedValuesOnly);

            ISqlContext             sqlContext = Mock.Of <ISqlContext>(x => x.Query <IContent>() == Mock.Of <IQuery <IContent> >());
            IUmbracoDatabaseFactory dbFactory  = Mock.Of <IUmbracoDatabaseFactory>(x => x.SqlContext == sqlContext);

            if (contentService == null)
            {
                contentService = IndexInitializer.GetMockContentService();
            }

            contentRebuilder = IndexInitializer.GetContentIndexRebuilder(contentService, publishedValuesOnly, dbFactory);

            var luceneDir = new RandomIdRAMDirectory();

            ContentValueSetValidator validator;

            // if only published values then we'll change the validator for tests to
            // ensure we don't support protected nodes and that we
            // mock the public access service for the special protected node.
            if (publishedValuesOnly)
            {
                var publicAccessServiceMock = new Mock <IPublicAccessService>();
                publicAccessServiceMock.Setup(x => x.IsProtected(It.IsAny <string>()))
                .Returns((string path) =>
                {
                    if (path.EndsWith("," + ExamineDemoDataContentService.ProtectedNode))
                    {
                        return(Attempt <PublicAccessEntry> .Succeed());
                    }
                    return(Attempt <PublicAccessEntry> .Fail());
                });

                var scopeProviderMock = new Mock <IScopeProvider>();
                scopeProviderMock.Setup(x => x.CreateScope(
                                            It.IsAny <IsolationLevel>(),
                                            It.IsAny <RepositoryCacheMode>(),
                                            It.IsAny <IEventDispatcher>(),
                                            It.IsAny <IScopedNotificationPublisher>(),
                                            It.IsAny <bool?>(),
                                            It.IsAny <bool>(),
                                            It.IsAny <bool>()))
                .Returns(Mock.Of <IScope>);

                validator = new ContentValueSetValidator(
                    publishedValuesOnly,
                    false,
                    publicAccessServiceMock.Object,
                    scopeProviderMock.Object,
                    parentId);
            }
            else
            {
                validator = new ContentValueSetValidator(publishedValuesOnly, parentId);
            }

            index = IndexInitializer.GetUmbracoIndexer(
                HostingEnvironment,
                RunningRuntimeState,
                luceneDir,
                validator: validator);

            IDisposable syncMode = index.WithThreadingMode(IndexThreadingMode.Synchronous);

            return(new DisposableWrapper(syncMode, index, luceneDir));
        }