un-ignores PublishedMedia tests. Streamlines BaseWebTest so now we only have one place for database init logic (will

enhance this more today). Changed ExamineEvents to not delete indexes on trashed and changed PublishedMediaStore to ignore
nodes in the recycle bin path... and now to write unit tests for that.
This commit is contained in:
Shannon Deminick
2013-02-19 22:46:44 +06:00
parent da908501e5
commit a2ea20de70
5 changed files with 53 additions and 141 deletions

View File

@@ -200,7 +200,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsTrue(ancestors.Select(x => x.Id).ContainsAll(new[] { 3113, 2112, 2222, 1111 }));
}
[Ignore]
[Test]
public void Children_Without_Examine()
{
@@ -225,7 +224,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsTrue(subChildren.Select(x => x.Id).ContainsAll(new[] { mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
}
[Ignore]
[Test]
public void Descendants_Without_Examine()
{
@@ -250,7 +248,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsTrue(subDescendants.Select(x => x.Id).ContainsAll(new[] { mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
}
[Ignore]
[Test]
public void DescendantsOrSelf_Without_Examine()
{
@@ -277,7 +274,6 @@ namespace Umbraco.Tests.PublishedContent
new[] { mChild1.Id, mSubChild1.Id, mSubChild2.Id, mSubChild3.Id }));
}
[Ignore]
[Test]
public void Parent_Without_Examine()
{
@@ -303,7 +299,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.AreEqual(mChild1.Id, publishedSubChild1.Parent.Id);
}
[Ignore]
[Test]
public void Ancestors_Without_Examine()
{
@@ -323,7 +318,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsTrue(publishedSubChild1.Ancestors().Select(x => x.Id).ContainsAll(new[] {mChild1.Id, mRoot.Id}));
}
[Ignore]
[Test]
public void AncestorsOrSelf_Without_Examine()
{

View File

@@ -69,14 +69,18 @@ namespace Umbraco.Tests.TestHelpers
new DatabaseContext(new DefaultDatabaseFactory()),
//assign the service context
new ServiceContext(new PetaPocoUnitOfWorkProvider(), new FileUnitOfWorkProvider(), new PublishingStrategy())) { IsReady = true };
InitializeDatabase();
}
protected virtual void InitializeDatabase()
{
//Configure the Database and Sql Syntax based on connection string set in config
DatabaseContext.Initialize();
//Create the umbraco database and its base data
DatabaseContext.Database.CreateDatabaseSchema(false);
}
[TearDown]
public virtual void TearDown()
{
@@ -103,6 +107,8 @@ namespace Umbraco.Tests.TestHelpers
{
File.Delete(filePath);
}
UmbracoSettings.ResetSetters();
}
protected ApplicationContext ApplicationContext

View File

@@ -9,6 +9,9 @@ using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Core.ObjectResolution;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Publishing;
using Umbraco.Core.Services;
using Umbraco.Tests.Stubs;
using Umbraco.Web;
using Umbraco.Web.Routing;
@@ -18,77 +21,27 @@ using umbraco.cms.businesslogic.cache;
namespace Umbraco.Tests.TestHelpers
{
[TestFixture, RequiresSTA]
public abstract class BaseWebTest
public abstract class BaseWebTest : BaseDatabaseFactoryTest
{
[SetUp]
public virtual void Initialize()
public override void Initialize()
{
TestHelper.SetupLog4NetForTests();
TestHelper.InitializeContentDirectories();
AppDomain.CurrentDomain.SetData("DataDirectory", TestHelper.CurrentAssemblyDirectory);
base.Initialize();
}
protected override void InitializeDatabase()
{
if (RequiresDbSetup)
TestHelper.InitializeDatabase();
Resolution.Freeze();
//NOTE: We are not constructing with the service context here because it is not required for these tests (currently)
// if we do, this means that we have to initialized the RepositoryResolver too.
ApplicationContext.Current = new ApplicationContext
{
IsReady = true,
//assign the db context
DatabaseContext = new DatabaseContext(new DefaultDatabaseFactory())
};
base.InitializeDatabase();
}
[TearDown]
public virtual void TearDown()
public override void TearDown()
{
TestHelper.CleanContentDirectories();
//reset the app context
DatabaseContext.Database.Dispose();
ApplicationContext.ApplicationCache.ClearAllCache();
ApplicationContext.Current = null;
Resolution.IsFrozen = false;
if (RequiresDbSetup)
{
TestHelper.ClearDatabase();
SqlCeContextGuardian.CloseBackgroundConnection();
}
AppDomain.CurrentDomain.SetData("DataDirectory", null);
Cache.ClearAllCache();
UmbracoSettings.ResetSetters();
}
protected virtual void CreateDirectories(string[] directories)
{
foreach (var directory in directories)
{
var directoryInfo = new DirectoryInfo(IOHelper.MapPath(directory));
if (directoryInfo.Exists == false)
Directory.CreateDirectory(IOHelper.MapPath(directory));
}
base.TearDown();
}
protected virtual void CleanDirectories(string[] directories)
{
foreach (var directory in directories)
{
var directoryInfo = new DirectoryInfo(IOHelper.MapPath(directory));
if (directoryInfo.Exists)
directoryInfo.GetFiles().ForEach(x => x.Delete());
}
}
/// <summary>
/// By default this unit test will create and initialize an umbraco database
/// </summary>
@@ -96,46 +49,8 @@ namespace Umbraco.Tests.TestHelpers
{
get { return true; }
}
protected FakeHttpContextFactory GetHttpContextFactory(string url, RouteData routeData = null)
{
var factory = routeData != null
? new FakeHttpContextFactory(url, routeData)
: new FakeHttpContextFactory(url);
//set the state helper
StateHelper.HttpContext = factory.HttpContext;
return factory;
}
protected ApplicationContext ApplicationContext
{
get { return ApplicationContext.Current; }
}
protected DatabaseContext DatabaseContext
{
get { return ApplicationContext.DatabaseContext; }
}
internal virtual IRoutesCache GetRoutesCache()
{
return new FakeRoutesCache();
}
protected UmbracoContext GetUmbracoContext(string url, int templateId, RouteData routeData = null)
{
var ctx = new UmbracoContext(
GetHttpContextFactory(url, routeData).HttpContext,
ApplicationContext,
GetRoutesCache());
SetupUmbracoContextForTest(ctx, templateId);
return ctx;
}
protected virtual string GetXmlContent(int templateId)
protected override string GetXmlContent(int templateId)
{
return @"<?xml version=""1.0"" encoding=""utf-8""?>
<!DOCTYPE root[
@@ -170,23 +85,5 @@ namespace Umbraco.Tests.TestHelpers
</root>";
}
/// <summary>
/// Initlializes the UmbracoContext with specific XML
/// </summary>
/// <param name="umbracoContext"></param>
/// <param name="templateId"></param>
protected void SetupUmbracoContextForTest(UmbracoContext umbracoContext, int templateId)
{
umbracoContext.GetXmlDelegate = () =>
{
var xDoc = new XmlDocument();
//create a custom xml structure to return
xDoc.LoadXml(GetXmlContent(templateId));
//return the custom x doc
return xDoc;
};
}
}
}

View File

@@ -11,6 +11,7 @@ using Umbraco.Core;
using Umbraco.Core.Dynamics;
using Umbraco.Core.Models;
using Umbraco.Web.Models;
using UmbracoExamine;
using umbraco;
using umbraco.cms.businesslogic;
using ContentType = umbraco.cms.businesslogic.ContentType;
@@ -107,7 +108,7 @@ namespace Umbraco.Web
{
//first check in Examine as this is WAY faster
var criteria = searchProvider.CreateSearchCriteria("media");
var filter = criteria.Id(id);
var filter = criteria.Id(id).Not().Field(UmbracoContentIndexer.IndexPathFieldName, "-21");
var results = searchProvider.Search(filter.Compile());
if (results.Any())
{

View File

@@ -38,11 +38,14 @@ namespace umbraco.presentation.umbraco.Search
// in the core. This is only temporary to get this task completed for 6.0:
// http://issues.umbraco.org/issue/U4-1530
MediaService.Saved += MediaService_Saved;
MediaService.Trashed += MediaService_Trashed;
MediaService.Deleted += MediaService_Deleted;
MediaService.Moved += MediaService_Moved;
MediaService.Trashed += MediaService_Trashed;
ContentService.Saved += ContentService_Saved;
ContentService.Trashed += ContentService_Trashed;
ContentService.Deleted += ContentService_Deleted;
ContentService.Moved += ContentService_Moved;
ContentService.Trashed += ContentService_Trashed;
//bind to examine events
var contentIndexer = ExamineManager.Instance.IndexProviderCollection["InternalIndexer"] as UmbracoContentIndexer;
@@ -59,36 +62,47 @@ namespace umbraco.presentation.umbraco.Search
void ContentService_Trashed(IContentService sender, Umbraco.Core.Events.MoveEventArgs<IContent> e)
{
ExamineManager.Instance.DeleteFromIndex(e.Entity.Id.ToString(),
ExamineManager.Instance.IndexProviderCollection
.OfType<BaseUmbracoIndexer>()
.Where(x => x.EnableDefaultEventHandler));
IndexContent(e.Entity);
}
void MediaService_Trashed(IMediaService sender, Umbraco.Core.Events.MoveEventArgs<IMedia> e)
{
ExamineManager.Instance.DeleteFromIndex(e.Entity.Id.ToString(),
ExamineManager.Instance.IndexProviderCollection
.OfType<BaseUmbracoIndexer>()
.Where(x => x.EnableDefaultEventHandler));
IndexMedia(e.Entity);
}
void ContentService_Moved(IContentService sender, Umbraco.Core.Events.MoveEventArgs<IContent> e)
{
IndexConent(e.Entity);
IndexContent(e.Entity);
}
void ContentService_Deleted(IContentService sender, Umbraco.Core.Events.DeleteEventArgs<IContent> e)
{
e.DeletedEntities.ForEach(
content =>
ExamineManager.Instance.DeleteFromIndex(
content.Id.ToString(),
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>().Where(x => x.EnableDefaultEventHandler)));
}
void ContentService_Saved(IContentService sender, Umbraco.Core.Events.SaveEventArgs<IContent> e)
{
e.SavedEntities.ForEach(IndexConent);
e.SavedEntities.ForEach(IndexContent);
}
void MediaService_Moved(IMediaService sender, Umbraco.Core.Events.MoveEventArgs<IMedia> e)
{
IndexMedia(e.Entity);
}
void MediaService_Deleted(IMediaService sender, Umbraco.Core.Events.DeleteEventArgs<IMedia> e)
{
e.DeletedEntities.ForEach(
media =>
ExamineManager.Instance.DeleteFromIndex(
media.Id.ToString(),
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>().Where(x => x.EnableDefaultEventHandler)));
}
void MediaService_Saved(IMediaService sender, Umbraco.Core.Events.SaveEventArgs<IMedia> e)
{
e.SavedEntities.ForEach(IndexMedia);
@@ -101,7 +115,7 @@ namespace umbraco.presentation.umbraco.Search
ExamineManager.Instance.IndexProviderCollection.OfType<BaseUmbracoIndexer>().Where(x => x.EnableDefaultEventHandler));
}
private void IndexConent(IContent sender)
private void IndexContent(IContent sender)
{
ExamineManager.Instance.ReIndexNode(
sender.ToXml(), "content",