Example #1
0
        public void Index_Move_Media_From_Non_Indexable_To_Indexable_ParentID()
        {
            using (var luceneDir = new RandomIdRAMDirectory())
                using (var writer = new IndexWriter(luceneDir, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), IndexWriter.MaxFieldLength.LIMITED))
                    using (var indexer = IndexInitializer.GetUmbracoIndexer(writer))
                        using (var searcher = IndexInitializer.GetUmbracoSearcher(writer))
                        {
                            indexer.RebuildIndex();

                            var mediaService = new TestMediaService();

                            //change parent id to 1116
                            var existingCriteria = indexer.IndexerData;
                            indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes,
                                                                    1116);

                            //rebuild so it excludes children unless they are under 1116
                            indexer.RebuildIndex();

                            //ensure that node 2112 doesn't exist
                            var results = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
                            Assert.AreEqual(0, results.TotalItemCount);

                            //get a node from the data repo (this one exists underneath 2222)
                            var node = mediaService.GetLatestMediaByXpath("//*[string-length(@id)>0 and number(@id)>0]")
                                       .Root
                                       .Elements()
                                       .First(x => (int)x.Attribute("id") == 2112);

                            var currPath = (string)node.Attribute("path"); //should be : -1,1111,2222,2112
                            Assert.AreEqual("-1,1111,2222,2112", currPath);

                            //now mimic moving 2112 to 1116
                            //node.SetAttributeValue("path", currPath.Replace("2222", "1116"));
                            node.SetAttributeValue("path", "-1,1116,2112");
                            node.SetAttributeValue("parentID", "1116");

                            //now reindex the node, this should first delete it and then WILL add it because of the parent id constraint
                            indexer.ReIndexNode(node, IndexTypes.Media);

                            //RESET the parent id
                            existingCriteria    = ((IndexCriteria)indexer.IndexerData);
                            indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes,
                                                                    null);

                            //now ensure it's deleted
                            var newResults = searcher.Search(searcher.CreateSearchCriteria().Id(2112).Compile());
                            Assert.AreEqual(1, newResults.TotalItemCount);
                        }
        }
		public TestDataService()
		{
			ContentService = new TestContentService();
			LogService = new TestLogService();
			MediaService = new TestMediaService();
		}
 public TestDataService()
 {
     ContentService = new TestContentService();
     LogService     = new TestLogService();
     MediaService   = new TestMediaService();
 }