public void Ensure_Result_Has_All_Values()
        {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit = new IndexInitializer();
            var indexer = indexInit.GetUmbracoIndexer(newIndexFolder);
            indexer.RebuildIndex();
            
            var searcher = indexInit.GetUmbracoSearcher(newIndexFolder);
            var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.TotalItemCount);

            var searchItem = result.First();
            var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);

            Assert.AreEqual(searchItem.Id, backedMedia.Id);
            Assert.AreEqual(searchItem.Fields["sortOrder"], backedMedia.SortOrder.ToString());
            Assert.AreEqual(searchItem.Fields["urlName"], backedMedia.UrlName);
            Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["createDate"]), backedMedia.CreateDate);
            Assert.AreEqual(DateTools.StringToDate(searchItem.Fields["updateDate"]), backedMedia.UpdateDate);
            Assert.AreEqual(Guid.Parse(searchItem.Fields["version"]), backedMedia.Version);
            Assert.AreEqual(searchItem.Fields["level"], backedMedia.Level.ToString());
            Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.WriterID.ToString());
            Assert.AreEqual(searchItem.Fields["writerID"], backedMedia.CreatorID.ToString()); //there's only writerId in the xml
            Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.CreatorName);
            Assert.AreEqual(searchItem.Fields["writerName"], backedMedia.WriterName); //tehre's only writer name in the xml
        }
        public void Ensure_Children_Are_Sorted()
        {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit = new IndexInitializer();
            var indexer = indexInit.GetUmbracoIndexer(newIndexFolder);
            indexer.RebuildIndex();

            var searcher = indexInit.GetUmbracoSearcher(newIndexFolder);
            var result = searcher.Search(searcher.CreateSearchCriteria().Id(1111).Compile());
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.TotalItemCount);

            var searchItem = result.First();
            var backedMedia = new ExamineBackedMedia(searchItem, indexer, searcher);
            var children = backedMedia.ChildrenAsList.Value;

            var currSort = 0;
            for (var i = 0; i < children.Count(); i++)
            {
                Assert.GreaterOrEqual(children[i].SortOrder, currSort);
                currSort = children[i].SortOrder;
            }

        }
	    public void Ensure_Children_Sorted_With_Examine()
	    {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit = new IndexInitializer();
            var indexer = indexInit.GetUmbracoIndexer(newIndexFolder);
            indexer.RebuildIndex();

            var store = new DefaultPublishedMediaStore(
                indexInit.GetUmbracoSearcher(newIndexFolder),
                indexInit.GetUmbracoIndexer(newIndexFolder));

            //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
            var publishedMedia = store.GetDocumentById(GetUmbracoContext("/test", 1234), 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()
	    {
            var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
            var indexInit = new IndexInitializer();
            var indexer = indexInit.GetUmbracoIndexer(newIndexFolder);	        
            indexer.RebuildIndex();
            var searcher = indexInit.GetUmbracoSearcher(newIndexFolder);
            var store = new DefaultPublishedMediaStore(searcher, indexer);
	        var ctx = GetUmbracoContext("/test", 1234);

            //ensure it is found
            var publishedMedia = store.GetDocumentById(ctx, 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 = store.GetDocumentById(ctx, 3113);
            Assert.IsNull(recycledMedia);
	    }
		public void AncestorsOrSelf_With_Examine()
		{
			var newIndexFolder = new DirectoryInfo(Path.Combine("App_Data\\CWSIndexSetTest", Guid.NewGuid().ToString()));
			var indexInit = new IndexInitializer();
			var indexer = indexInit.GetUmbracoIndexer(newIndexFolder);
			indexer.RebuildIndex();

            var store = new DefaultPublishedMediaStore(
                indexInit.GetUmbracoSearcher(newIndexFolder),
                indexInit.GetUmbracoIndexer(newIndexFolder));

			//we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace
			var publishedMedia = store.GetDocumentById(GetUmbracoContext("/test", 1234), 3113);
			var ancestors = publishedMedia.AncestorsOrSelf();
			Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
		}