public void Ensure_Children_Sorted_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx = GetUmbracoContext("/test", 1234);
                var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(1111);
                var rootChildren = publishedMedia.Children().ToArray();
                var currSort = 0;
                for (var i = 0; i < rootChildren.Count(); i++)
                {
                    Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                    currSort = rootChildren[i].SortOrder;
                }
            }

            



        }
 /// <summary>
 /// Shared with PublishMediaStoreTests
 /// </summary>
 /// <param name="id"></param>
 /// <param name="umbracoContext"></param>
 /// <returns></returns>
 internal static IPublishedContent GetNode(int id, UmbracoContext umbracoContext)
 {
     var ctx = umbracoContext;
     var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
     var doc = cache.GetById(id);
     Assert.IsNotNull(doc);
     return doc;
 }
        /// <summary>
        /// Shared with PublishMediaStoreTests
        /// </summary>
        /// <param name="id"></param>
        /// <param name="umbracoContext"></param>
        /// <returns></returns>
        internal static IPublishedContent GetNode(int id, UmbracoContext umbracoContext)
        {
            var ctx   = umbracoContext;
            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application), ctx);
            var doc   = cache.GetById(id);

            Assert.IsNotNull(doc);
            return(doc);
        }
 /// <summary>
 /// Constructor used to return results from the caches
 /// </summary>
 /// <param name="contentCache"></param>
 /// <param name="mediaCache"></param>
 public PublishedContentQuery(ContextualPublishedContentCache contentCache, ContextualPublishedMediaCache mediaCache)
 {
     if (contentCache == null)
     {
         throw new ArgumentNullException("contentCache");
     }
     if (mediaCache == null)
     {
         throw new ArgumentNullException("mediaCache");
     }
     _contentCache = contentCache;
     _mediaCache   = mediaCache;
 }
        public void AncestorsOrSelf_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var ctx      = GetUmbracoContext("/test", 1234);
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var cache    = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(3113);
                var ancestors      = publishedMedia.AncestorsOrSelf();
                Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
            }
        }
Beispiel #6
0
        public void Get_Root_Docs()
        {
            var user    = new User(0);
            var mType   = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
            var mRoot1  = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot1", mType, user, -1);
            var mRoot2  = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot2", mType, user, -1);
            var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot1.Id);
            var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot2.Id);

            var ctx   = GetUmbracoContext("/test", 1234);
            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
            var roots = cache.GetAtRoot();

            Assert.AreEqual(2, roots.Count());
            Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] { mRoot1.Id, mRoot2.Id }));
        }
		public void Get_Root_Docs()
		{
			var user = new User(0);
			var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
			var mRoot1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot1", mType, user, -1);
			var mRoot2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot2", mType, user, -1);
			var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot1.Id);
			var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot2.Id);
			
			var ctx = GetUmbracoContext("/test", 1234);
            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(), ctx);
			var roots = cache.GetAtRoot();
			Assert.AreEqual(2, roots.Count());
			Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));

		}
        public void AncestorsOrSelf_With_Examine()
        {
            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))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();
                            var ctx = GetUmbracoContext("/test", 1234);
                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);

                            //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                            var publishedMedia = cache.GetById(3113);
                            var ancestors      = publishedMedia.AncestorsOrSelf();
                            Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
                        }
        }
        public void DescendantsOrSelf_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx      = GetUmbracoContext("/test", 1234);
                var cache    = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia  = cache.GetById(1111);
                var rootDescendants = publishedMedia.DescendantsOrSelf();
                Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 1111, 2112, 2222, 1113, 1114, 1115, 1116 }));

                var publishedChild1 = cache.GetById(2222);
                var subDescendants  = publishedChild1.DescendantsOrSelf();
                Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2222, 2112, 3113 }));
            }
        }
Beispiel #10
0
        public void Ensure_Children_Sorted_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx      = GetUmbracoContext("/test", 1234);
                var cache    = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(1111);
                var rootChildren   = publishedMedia.Children().ToArray();
                var currSort       = 0;
                for (var i = 0; i < rootChildren.Count(); i++)
                {
                    Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                    currSort = rootChildren[i].SortOrder;
                }
            }
        }
        public void Do_Not_Find_In_Recycle_Bin()
        {
            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))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();
                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var ctx   = GetUmbracoContext("/test", 1234);
                            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);

                            //ensure it is found
                            var publishedMedia = cache.GetById(3113);
                            Assert.IsNotNull(publishedMedia);

                            //move item to recycle bin
                            var newXml = XElement.Parse(@"<node id='3113' version='5b3e46ab-3e37-4cfa-ab70-014234b5bd33' parentID='-21' level='1' writerID='0' nodeType='1032' template='0' sortOrder='2' createDate='2010-05-19T17:32:46' updateDate='2010-05-19T17:32:46' nodeName='Another Umbraco Image' urlName='acnestressscrub' writerName='Administrator' nodeTypeAlias='Image' path='-1,-21,3113'>
					<data alias='umbracoFile'><![CDATA[/media/1234/blah.pdf]]></data>
					<data alias='umbracoWidth'>115</data>
					<data alias='umbracoHeight'>268</data>
					<data alias='umbracoBytes'>10726</data>
					<data alias='umbracoExtension'>jpg</data>
				</node>"                );
                            indexer.ReIndexNode(newXml, "media");

                            //ensure it still exists in the index (raw examine search)
                            var criteria = searcher.CreateSearchCriteria();
                            var filter   = criteria.Id(3113);
                            var found    = searcher.Search(filter.Compile());
                            Assert.IsNotNull(found);
                            Assert.AreEqual(1, found.TotalItemCount);

                            //ensure it does not show up in the published media store
                            var recycledMedia = cache.GetById(3113);
                            Assert.IsNull(recycledMedia);
                        }
        }
        public void Ensure_Children_Sorted_With_Examine()
        {
            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))
                        {
                            //var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                            indexer.RebuildIndex();
                            //var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                            var ctx   = GetUmbracoContext("/test", 1234);
                            var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx);

                            //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                            var publishedMedia = cache.GetById(1111);
                            var rootChildren   = publishedMedia.Children().ToArray();
                            var currSort       = 0;
                            for (var i = 0; i < rootChildren.Count(); i++)
                            {
                                Assert.GreaterOrEqual(rootChildren[i].SortOrder, currSort);
                                currSort = rootChildren[i].SortOrder;
                            }
                        }
        }
 public PublishedMediaStore(ContextualPublishedMediaCache mediaCache)
 {
     _mediaCache = mediaCache;
 }
        public void AncestorsOrSelf_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var ctx = GetUmbracoContext("/test", 1234);
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(3113);
                var ancestors = publishedMedia.AncestorsOrSelf();
                Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
            }
        }
        public void DescendantsOrSelf_With_Examine()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx = GetUmbracoContext("/test", 1234);
                var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
                var publishedMedia = cache.GetById(1111);
                var rootDescendants = publishedMedia.DescendantsOrSelf();
                Assert.IsTrue(rootDescendants.Select(x => x.Id).ContainsAll(new[] { 1111, 2112, 2222, 1113, 1114, 1115, 1116 }));

                var publishedChild1 = cache.GetById(2222);
                var subDescendants = publishedChild1.DescendantsOrSelf();
                Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { 2222, 2112, 3113 }));
            }
        }
        public void Do_Not_Find_In_Recycle_Bin()
        {
            using (var luceneDir = new RAMDirectory())
            {
                var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
                indexer.RebuildIndex();
                var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
                var ctx = GetUmbracoContext("/test", 1234);
                var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(searcher, indexer), ctx);

                //ensure it is found
                var publishedMedia = cache.GetById(3113);
                Assert.IsNotNull(publishedMedia);

                //move item to recycle bin
                var newXml = XElement.Parse(@"<node id='3113' version='5b3e46ab-3e37-4cfa-ab70-014234b5bd33' parentID='-21' level='1' writerID='0' nodeType='1032' template='0' sortOrder='2' createDate='2010-05-19T17:32:46' updateDate='2010-05-19T17:32:46' nodeName='Another Umbraco Image' urlName='acnestressscrub' writerName='Administrator' nodeTypeAlias='Image' path='-1,-21,3113'>
					<data alias='umbracoFile'><![CDATA[/media/1234/blah.pdf]]></data>
					<data alias='umbracoWidth'>115</data>
					<data alias='umbracoHeight'>268</data>
					<data alias='umbracoBytes'>10726</data>
					<data alias='umbracoExtension'>jpg</data>
				</node>");
                indexer.ReIndexNode(newXml, "media");

                //ensure it still exists in the index (raw examine search)
                var criteria = searcher.CreateSearchCriteria();
                var filter = criteria.Id(3113);
                var found = searcher.Search(filter.Compile());
                Assert.IsNotNull(found);
                Assert.AreEqual(1, found.TotalItemCount);

                //ensure it does not show up in the published media store
                var recycledMedia = cache.GetById(3113);
                Assert.IsNull(recycledMedia);

            }

        }
 public PublishedContentQuery(ContextualPublishedContentCache contentCache, ContextualPublishedMediaCache mediaCache)
 {
     _contentCache = contentCache;
     _mediaCache = mediaCache;
 }