Fixed up merging and unit test structures so taht BaseWebTest uses BaseDatabaseFactoryTests.

Fixed up Examine unit test issues
This commit is contained in:
Shannon Deminick
2013-02-20 02:50:08 +06:00
parent dddc308167
commit b47f9e87f1
10 changed files with 136 additions and 84 deletions

View File

@@ -21,11 +21,12 @@ namespace Umbraco.Tests.ContentStores
base.Initialize();
}
protected override void OnFreezing()
protected override void FreezeResolution()
{
base.OnFreezing();
//we're going to use the same initialization as the PublishedMediaTests
PublishedMediaTests.DoInitialization(GetUmbracoContext("/test", 1234));
base.FreezeResolution();
}
public override void TearDown()

View File

@@ -85,10 +85,8 @@ namespace Umbraco.Tests.PublishedContent
/// <summary>
/// Setup any resolvers before freezing
/// </summary>
protected override void OnFreezing()
protected override void FreezeResolution()
{
base.OnFreezing();
PublishedContentStoreResolver.Current = new PublishedContentStoreResolver(new DefaultPublishedContentStore());
PropertyEditorValueConvertersResolver.Current = new PropertyEditorValueConvertersResolver(
@@ -98,6 +96,8 @@ namespace Umbraco.Tests.PublishedContent
typeof(TinyMcePropertyEditorValueConverter),
typeof(YesNoPropertyEditorValueConverter)
});
base.FreezeResolution();
}
public override void TearDown()

View File

@@ -35,13 +35,14 @@ namespace Umbraco.Tests.PublishedContent
public override void Initialize()
{
base.Initialize();
UmbracoExamineSearcher.DisableInitializationCheck = true;
BaseUmbracoIndexer.DisableInitializationCheck = true;
}
protected override void OnFreezing()
{
base.OnFreezing();
DoInitialization(GetUmbracoContext("/test", 1234));
protected override void FreezeResolution()
{
DoInitialization(GetUmbracoContext("/test", 1234));
base.FreezeResolution();
}
@@ -89,6 +90,8 @@ namespace Umbraco.Tests.PublishedContent
/// </summary>
internal static void DoTearDown()
{
UmbracoExamineSearcher.DisableInitializationCheck = null;
BaseUmbracoIndexer.DisableInitializationCheck = null;
PropertyEditorValueConvertersResolver.Reset();
UmbracoContext.Current = null;
PublishedMediaStoreResolver.Reset();
@@ -117,38 +120,41 @@ namespace Umbraco.Tests.PublishedContent
[Test]
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);
var ctx = GetUmbracoContext("/test", 1234);
using (var luceneDir = new RAMDirectory())
{
var indexer = IndexInitializer.GetUmbracoIndexer(luceneDir);
indexer.RebuildIndex();
var searcher = IndexInitializer.GetUmbracoSearcher(luceneDir);
var store = new DefaultPublishedMediaStore(searcher);
var ctx = GetUmbracoContext("/test", 1234);
//ensure it is found
var publishedMedia = store.GetDocumentById(ctx, 3113);
Assert.IsNotNull(publishedMedia);
//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'>
//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");
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 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);
//ensure it does not show up in the published media store
var recycledMedia = store.GetDocumentById(ctx, 3113);
Assert.IsNull(recycledMedia);
}
}
[Test]

View File

@@ -22,11 +22,12 @@ namespace Umbraco.Tests.PublishedContent
base.Initialize();
}
protected override void OnFreezing()
{
protected override void FreezeResolution()
{
var routingCtx = GetRoutingContext("/test", 1234);
UmbracoContext.Current = routingCtx.UmbracoContext;
PropertyEditorValueConvertersResolver.Current = new PropertyEditorValueConvertersResolver(Enumerable.Empty<Type>());
base.FreezeResolution();
}
public override void TearDown()

View File

@@ -63,17 +63,23 @@ namespace Umbraco.Tests.TestHelpers
//Create the Sql CE database
var engine = new SqlCeEngine(settings.ConnectionString);
engine.CreateDatabase();
Resolution.Freeze();
ApplicationContext.Current = new ApplicationContext(
//assign the db context
new DatabaseContext(new DefaultDatabaseFactory()),
//assign the service context
new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true };
FreezeResolution();
InitializeDatabase();
}
protected virtual void FreezeResolution()
{
Resolution.Freeze();
}
protected virtual void InitializeDatabase()
{
//Configure the Database and Sql Syntax based on connection string set in config
@@ -95,8 +101,9 @@ namespace Umbraco.Tests.TestHelpers
SqlCeContextGuardian.CloseBackgroundConnection();
ApplicationContext.Current = null;
Resolution.IsFrozen = false;
RepositoryResolver.Reset();
Resolution.Reset();
TestHelper.CleanContentDirectories();

View File

@@ -1,10 +1,12 @@
using System;
using System.Linq;
using Examine;
using Examine.LuceneEngine.Config;
using Examine.LuceneEngine.Providers;
using Lucene.Net.Analysis;
using Lucene.Net.Analysis.Standard;
using UmbracoExamine;
using UmbracoExamine.Config;
using UmbracoExamine.DataServices;
using UmbracoExamine.PDF;
@@ -30,22 +32,10 @@ namespace Umbraco.Tests.UmbracoExamine
analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);
}
var i = new UmbracoContentIndexer(new IndexCriteria(
//new[]
// {
// new TestIndexField {Name = "id", EnableSorting = true, Type = "Number"},
// new TestIndexField {Name = "nodeName", EnableSorting = true},
// new TestIndexField {Name = "updateDate", EnableSorting = true, Type = "DateTime"},
// new TestIndexField {Name = "writerName"},
// new TestIndexField {Name = "path"},
// new TestIndexField {Name = "nodeTypeAlias"},
// new TestIndexField {Name = "parentID"}
// },
Enumerable.Empty<IIndexField>(),
Enumerable.Empty<IIndexField>(),
Enumerable.Empty<string>(),
new string[] {},
-1),
var indexSet = new IndexSet();
var indexCriteria = indexSet.ToIndexCriteria(dataService);
var i = new UmbracoContentIndexer(indexCriteria,
luceneDir, //custom lucene directory
dataService,
analyzer,

View File

@@ -17,13 +17,18 @@ namespace Umbraco.Tests.UmbracoExamine
{
public const int ProtectedNode = 1142;
public TestContentService(string xml = null)
public TestContentService(string contentXml = null, string mediaXml = null)
{
if (xml == null)
if (contentXml == null)
{
xml = TestFiles.umbraco;
contentXml = TestFiles.umbraco;
}
_xDoc = XDocument.Parse(xml);
if (mediaXml == null)
{
mediaXml = TestFiles.media;
}
_xContent = XDocument.Parse(contentXml);
_xMedia = XDocument.Parse(mediaXml);
}
#region IContentService Members
@@ -39,7 +44,7 @@ namespace Umbraco.Tests.UmbracoExamine
public XDocument GetLatestContentByXPath(string xpath)
{
var xdoc = XDocument.Parse("<content></content>");
xdoc.Root.Add(_xDoc.XPathSelectElements(xpath));
xdoc.Root.Add(_xContent.XPathSelectElements(xpath));
return xdoc;
}
@@ -51,12 +56,17 @@ namespace Umbraco.Tests.UmbracoExamine
/// <returns></returns>
public XDocument GetPublishedContentByXPath(string xpath)
{
var xdoc = XDocument.Parse("<content></content>");
xdoc.Root.Add(_xDoc.XPathSelectElements(xpath));
return xdoc;
return GetContentByXPath(xpath, _xContent);
}
private XDocument GetContentByXPath(string xpath, XDocument content)
{
var xdoc = XDocument.Parse("<content></content>");
xdoc.Root.Add(content.XPathSelectElements(xpath));
return xdoc;
}
public string StripHtml(string value)
{
const string pattern = @"<(.|\n)*?>";
@@ -70,24 +80,42 @@ namespace Umbraco.Tests.UmbracoExamine
return nodeId == ProtectedNode;
}
private List<string> _userPropNames;
public IEnumerable<string> GetAllUserPropertyNames()
{
return GetPublishedContentByXPath("//*[count(@id)>0]")
.Root
.Elements()
.Select(x => x.Name.LocalName)
.ToList();
if (_userPropNames == null)
{
var xpath = "//*[count(@id)>0 and @id != -1]";
_userPropNames = GetPublishedContentByXPath(xpath)
.Root
.Elements() //each page
.SelectMany(x => x.Elements().Where(e => e.Attribute("id") == null)) //each page property (no @id)
.Select(x => x.Name.LocalName) //the name of the property
.Distinct()
.Union(GetContentByXPath(xpath, _xMedia)
.Root
.Elements() //each page
.SelectMany(x => x.Elements().Where(e => e.Attribute("id") == null)) //each page property (no @id)
.Select(x => (string)x.Attribute("alias")) //the name of the property NOTE: We are using the legacy XML here.
.Distinct()).ToList();
}
return _userPropNames;
}
private List<string> _sysPropNames;
public IEnumerable<string> GetAllSystemPropertyNames()
{
return UmbracoContentIndexer.IndexFieldPolicies.Select(x => x.Name);
if (_sysPropNames == null)
{
_sysPropNames = UmbracoContentIndexer.IndexFieldPolicies.Select(x => x.Name).ToList();
}
return _sysPropNames;
}
#endregion
private readonly XDocument _xDoc;
private readonly XDocument _xContent;
private readonly XDocument _xMedia;

View File

@@ -2,15 +2,15 @@
<media>
<node id="1111" version="902e13f7-5793-482a-9e06-cd94eebd1de0" parentID="-1" level="1" writerID="0" nodeType="1031" template="0" sortOrder="2" createDate="2010-05-19T15:26:08" updateDate="2010-05-19T15:26:09" nodeName="Product Images" urlName="productimages" writerName="Administrator" nodeTypeAlias="Folder" path="-1,1111">
<data alias="contents"></data>
<node id="2222" version="902e13f7-5793-482a-9e06-cd94eebd1de0" parentID="1111" level="1" writerID="0" nodeType="1031" template="0" sortOrder="2" createDate="2010-05-19T15:26:08" updateDate="2010-05-19T15:26:09" nodeName="Product Images" urlName="productimages" writerName="Administrator" nodeTypeAlias="Folder" path="-1,1111,2222">
<node id="2222" version="902e13f7-5793-482a-9e06-cd94eebd1de0" parentID="1111" level="2" writerID="0" nodeType="1031" template="0" sortOrder="2" createDate="2010-05-19T15:26:08" updateDate="2010-05-19T15:26:09" nodeName="Product Images" urlName="productimages" writerName="Administrator" nodeTypeAlias="Folder" path="-1,1111,2222">
<data alias="contents"></data>
<node id="2112" version="5b3e46ab-3e37-4cfa-ab70-014234b5bd39" parentID="2222" level="2" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2010-05-19T17:32:46" updateDate="2010-05-19T17:32:46" nodeName="Sam's Umbraco Image" urlName="acnestressscrub" writerName="Administrator" nodeTypeAlias="Image" path="-1,1111,2222,2112">
<node id="2112" version="5b3e46ab-3e37-4cfa-ab70-014234b5bd39" parentID="2222" level="3" writerID="0" nodeType="1032" template="0" sortOrder="1" createDate="2010-05-19T17:32:46" updateDate="2010-05-19T17:32:46" nodeName="Sam's Umbraco Image" urlName="acnestressscrub" writerName="Administrator" nodeTypeAlias="Image" path="-1,1111,2222,2112">
<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 id="3113" version="5b3e46ab-3e37-4cfa-ab70-014234b5bd33" parentID="2112" level="3" 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,1111,2222,2112,3113">
<node id="3113" version="5b3e46ab-3e37-4cfa-ab70-014234b5bd33" parentID="2112" level="4" 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,1111,2222,2112,3113">
<data alias="umbracoFile"><![CDATA[/media/1234/blah.pdf]]></data>
<data alias="umbracoWidth">115</data>
<data alias="umbracoHeight">268</data>

View File

@@ -58,6 +58,11 @@ namespace UmbracoExamine
#endregion
/// <summary>
/// Used for unit tests
/// </summary>
internal static bool? DisableInitializationCheck = null;
#region Properties
/// <summary>
@@ -214,13 +219,18 @@ namespace UmbracoExamine
[SecuritySafeCritical]
protected bool CanInitialize()
{
//We need to check if we actually can initialize, if not then don't continue
if (ApplicationContext.Current == null
|| !ApplicationContext.Current.IsConfigured
|| !ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
//check the DisableInitializationCheck and ensure that it is not set to true
if (!DisableInitializationCheck.HasValue || !DisableInitializationCheck.Value)
{
return false;
//We need to check if we actually can initialize, if not then don't continue
if (ApplicationContext.Current == null
|| !ApplicationContext.Current.IsConfigured
|| !ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
{
return false;
}
}
return true;
}

View File

@@ -85,6 +85,11 @@ namespace UmbracoExamine
#endregion
/// <summary>
/// Used for unit tests
/// </summary>
internal static bool? DisableInitializationCheck = null;
/// <summary>
/// Returns true if the Umbraco application is in a state that we can initialize the examine indexes
/// </summary>
@@ -92,13 +97,17 @@ namespace UmbracoExamine
[SecuritySafeCritical]
protected bool CanInitialize()
{
//We need to check if we actually can initialize, if not then don't continue
if (ApplicationContext.Current == null
|| !ApplicationContext.Current.IsConfigured
|| !ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
//check the DisableInitializationCheck and ensure that it is not set to true
if (!DisableInitializationCheck.HasValue || !DisableInitializationCheck.Value)
{
return false;
}
//We need to check if we actually can initialize, if not then don't continue
if (ApplicationContext.Current == null
|| !ApplicationContext.Current.IsConfigured
|| !ApplicationContext.Current.DatabaseContext.IsDatabaseConfigured)
{
return false;
}
}
return true;
}