/// <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 mediaStore = new DefaultPublishedMediaStore();
			var doc = mediaStore.GetDocumentById(ctx, id);
			Assert.IsNotNull(doc);
			return doc;
		}
		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 mediaStore = new DefaultPublishedMediaStore();
			var roots = mediaStore.GetRootDocuments(ctx);
			Assert.AreEqual(2, roots.Count());
			Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));

		}
	    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;
            }

                

	    }
		private void DoAssert(
			DefaultPublishedMediaStore.DictionaryPublishedContent dicDoc,
			int idVal = 1234,
			int templateIdVal = 333,
			int sortOrderVal = 44,
			string urlNameVal = "testing",
			string nodeTypeAliasVal = "myType",
			int nodeTypeIdVal = 22,
			string writerNameVal = "Shannon",
			string creatorNameVal = "Shannon2",
			int writerIdVal = 33,
			int creatorIdVal = 44,
			string pathVal = "1,2,3,4,5",
			DateTime? createDateVal = null,
			DateTime? updateDateVal = null,
			int levelVal = 3,
			int parentIdVal = 321)
		{
			if (!createDateVal.HasValue)
				createDateVal = DateTime.Parse("2012-01-02");
			if (!updateDateVal.HasValue)
				updateDateVal = DateTime.Parse("2012-01-03");

			DoAssert((IPublishedContent)dicDoc, idVal, templateIdVal, sortOrderVal, urlNameVal, nodeTypeAliasVal, nodeTypeIdVal, writerNameVal, 
				creatorNameVal, writerIdVal, creatorIdVal, pathVal, createDateVal, updateDateVal, levelVal);

			//now validate the parentId that has been parsed, this doesn't exist on the IPublishedContent
			Assert.AreEqual(parentIdVal, dicDoc.ParentId);
		}
		public void Convert_From_XPath_Navigator()
		{
			var xmlDoc = GetMediaXml();
			var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator();
			var store = new DefaultPublishedMediaStore();
			var doc = store.ConvertFromXPathNavigator(navigator);

			DoAssert(doc, 2000, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon2", 22, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
			Assert.AreEqual(null, doc.Parent);
			Assert.AreEqual(2, doc.Children.Count());
			Assert.AreEqual(2001, doc.Children.ElementAt(0).Id);
			Assert.AreEqual(2002, doc.Children.ElementAt(1).Id);
		}
		public void Convert_From_Search_Result()
		{
			var result = new SearchResult()
				{
					Id = 1234,
					Score = 1
				};
			result.Fields.Add("__IndexType", "media");
			result.Fields.Add("__NodeId", "1234");
			result.Fields.Add("__NodeTypeAlias", "Image");
			result.Fields.Add("__Path", "-1,1234");
			result.Fields.Add("__nodeName", "Test");
			result.Fields.Add("id", "1234");
			result.Fields.Add("nodeName", "Test");
			result.Fields.Add("nodeTypeAlias", "Image");
			result.Fields.Add("parentID", "-1");
			result.Fields.Add("path", "-1,1234");
			result.Fields.Add("updateDate", "2012-07-16T10:34:09");
			result.Fields.Add("writerName", "Shannon");

			var store = new DefaultPublishedMediaStore();
			var doc = store.ConvertFromSearchResult(result);

			DoAssert(doc, 1234, 0, 0, "", "Image", 0, "Shannon", "", 0, 0, "-1,1234", default(DateTime), DateTime.Parse("2012-07-16T10:34:09"), 2);
			Assert.AreEqual(null, doc.Parent);
		}
	    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 }));
		}