diff --git a/src/Umbraco.Tests/LibraryTests.cs b/src/Umbraco.Tests/LibraryTests.cs
index c340929c0f..ccb90d314e 100644
--- a/src/Umbraco.Tests/LibraryTests.cs
+++ b/src/Umbraco.Tests/LibraryTests.cs
@@ -38,15 +38,6 @@ namespace Umbraco.Tests
Core.Configuration.UmbracoSettings.SettingsFilePath = Core.IO.IOHelper.MapPath(Core.IO.SystemDirectories.Config + Path.DirectorySeparatorChar, false);
}
- protected override void FreezeResolution()
- {
- //set the current umbraco context and a published content cache
- PublishedContentCacheResolver.Current = new PublishedContentCacheResolver(
- new PublishedContentCache());
-
- base.FreezeResolution();
- }
-
public override void TearDown()
{
base.TearDown();
@@ -102,7 +93,7 @@ namespace Umbraco.Tests
///
private string LegacyGetItem(int nodeId, string alias)
{
- var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
+ var cache = UmbracoContext.Current.ContentCache.InnerCache as PublishedContentCache;
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
var umbracoXML = cache.GetXml(UmbracoContext.Current); // = UmbracoContext.Current.GetXml();
diff --git a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs
index 04689b7389..ed28fce075 100644
--- a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs
+++ b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs
@@ -14,7 +14,7 @@ using umbraco.BusinessLogic;
namespace Umbraco.Tests.PublishedCache
{
[TestFixture]
- public class PublishContentStoreTests
+ public class PublishContentCacheTests
{
private FakeHttpContextFactory _httpContextFactory;
private UmbracoContext _umbracoContext;
@@ -73,43 +73,38 @@ namespace Umbraco.Tests.PublishedCache
_httpContextFactory = new FakeHttpContextFactory("~/Home");
//ensure the StateHelper is using our custom context
StateHelper.HttpContext = _httpContextFactory.HttpContext;
-
- _umbracoContext = new UmbracoContext(
+
+ var cache = new PublishedContentCache
+ {
+ GetXmlDelegate = (user, preview) =>
+ {
+ var doc = new XmlDocument();
+ doc.LoadXml(GetXml());
+ return doc;
+ }
+ };
+
+ _umbracoContext = new UmbracoContext(
_httpContextFactory.HttpContext,
new ApplicationContext(),
- new PublishedContentCache(),
+ cache,
new PublishedMediaCache());
- var cache = new PublishedContentCache();
- cache.GetXmlDelegate = (user, preview) =>
- {
- var xDoc = new XmlDocument();
-
- //create a custom xml structure to return
-
- xDoc.LoadXml(GetXml());
- //return the custom x doc
- return xDoc;
- };
-
- _cache = new ContextualPublishedContentCache(cache, _umbracoContext);
+ _cache = _umbracoContext.ContentCache;
}
private void SetupForLegacy()
{
Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = true;
- var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
+ var cache = _umbracoContext.ContentCache.InnerCache as PublishedContentCache;
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
cache.GetXmlDelegate = (user, preview) =>
{
- var xDoc = new XmlDocument();
-
- //create a custom xml structure to return
- xDoc.LoadXml(GetLegacyXml());
- //return the custom x doc
- return xDoc;
+ var doc = new XmlDocument();
+ doc.LoadXml(GetLegacyXml());
+ return doc;
};
}
@@ -129,7 +124,7 @@ namespace Umbraco.Tests.PublishedCache
[Test]
public void Has_Content()
{
- Assert.IsTrue(_cache.HasContent(_umbracoContext));
+ Assert.IsTrue(_cache.HasContent());
}
[Test]
diff --git a/src/Umbraco.Tests/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/PublishedCache/PublishedMediaCacheTests.cs
index 5fc9d7659a..929e88322f 100644
--- a/src/Umbraco.Tests/PublishedCache/PublishedMediaCacheTests.cs
+++ b/src/Umbraco.Tests/PublishedCache/PublishedMediaCacheTests.cs
@@ -16,7 +16,7 @@ using umbraco.BusinessLogic;
namespace Umbraco.Tests.PublishedCache
{
[TestFixture]
- public class PublishMediaStoreTests : PublishedContentTestBase
+ public class PublishMediaCacheTests : PublishedContentTestBase
{
public override void Initialize()
{
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
index 441c98f170..e0321e08d5 100644
--- a/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
+++ b/src/Umbraco.Tests/PublishedContent/DynamicDocumentTestsBase.cs
@@ -13,17 +13,6 @@ namespace Umbraco.Tests.PublishedContent
[TestFixture]
public abstract class DynamicDocumentTestsBase : PublishedContentTestBase
{
- public override void Initialize()
- {
- base.Initialize();
- }
-
- public override void TearDown()
- {
- base.TearDown();
-
- }
-
protected override DatabaseBehavior DatabaseTestBehavior
{
get { return DatabaseBehavior.NoDatabasePerFixture; }
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs
index abd05e0ecd..c4c8385da0 100644
--- a/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs
@@ -85,7 +85,7 @@ namespace Umbraco.Tests.PublishedContent
//var ctx = GetUmbracoContext("/test", template.Id);
var ctx = GetUmbracoContext("/test", 1234);
- var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
+ var cache = ctx.ContentCache.InnerCache as PublishedContentCache;
if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
var node = new DynamicNode(
diff --git a/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentTests.cs
index 6910ca0eb0..6a796d43a9 100644
--- a/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/DynamicPublishedContentTests.cs
@@ -28,8 +28,7 @@ namespace Umbraco.Tests.PublishedContent
//var template = Template.MakeNew("test", new User(0));
//var ctx = GetUmbracoContext("/test", template.Id);
var ctx = GetUmbracoContext("/test", 1234);
- var cache = new ContextualPublishedContentCache(new PublishedContentCache(), ctx);
- var doc = cache.GetById(id);
+ var doc = ctx.ContentCache.GetById(id);
Assert.IsNotNull(doc);
var dynamicNode = new DynamicPublishedContent(doc);
Assert.IsNotNull(dynamicNode);
diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
index 6f7be801ce..1598f1fd99 100644
--- a/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTests.cs
@@ -66,25 +66,10 @@ namespace Umbraco.Tests.PublishedContent
";
}
- public override void Initialize()
- {
- base.Initialize();
-
- }
-
-
-
- public override void TearDown()
- {
- base.TearDown();
-
- }
-
internal IPublishedContent GetNode(int id)
{
var ctx = GetUmbracoContext("/test", 1234);
- var cache = new ContextualPublishedContentCache(new PublishedContentCache(), ctx);
- var doc = cache.GetById(id);
+ var doc = ctx.ContentCache.GetById(id);
Assert.IsNotNull(doc);
return doc;
}
diff --git a/src/Umbraco.Tests/PublishedContent/StronglyTypedQueryTests.cs b/src/Umbraco.Tests/PublishedContent/StronglyTypedQueryTests.cs
index 66f8737a76..89da7a89f2 100644
--- a/src/Umbraco.Tests/PublishedContent/StronglyTypedQueryTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/StronglyTypedQueryTests.cs
@@ -76,8 +76,7 @@ namespace Umbraco.Tests.PublishedContent
internal IPublishedContent GetNode(int id)
{
var ctx = UmbracoContext.Current;
- var cache = new ContextualPublishedContentCache(new PublishedContentCache(), ctx);
- var doc = cache.GetById(id);
+ var doc = ctx.ContentCache.GetById(id);
Assert.IsNotNull(doc);
return doc;
}
diff --git a/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs b/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs
index bb44827ffa..d68ba70f32 100644
--- a/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs
+++ b/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs
@@ -123,7 +123,7 @@ namespace Umbraco.Tests.Services
}
else
{
- Assert.Fail("ERROR! " + _error);
+ throw new Exception("Error!", _error);
}
}
diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs
index a891911c84..4f04076b63 100644
--- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs
+++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs
@@ -279,12 +279,21 @@ namespace Umbraco.Tests.TestHelpers
protected UmbracoContext GetUmbracoContext(string url, int templateId, RouteData routeData = null)
{
+ var cache = new PublishedContentCache();
+
+ cache.GetXmlDelegate = (user, preview) =>
+ {
+ var doc = new XmlDocument();
+ doc.LoadXml(GetXmlContent(templateId));
+ return doc;
+ };
+
var ctx = new UmbracoContext(
GetHttpContextFactory(url, routeData).HttpContext,
ApplicationContext,
- new PublishedContentCache(),
+ cache,
new PublishedMediaCache());
- SetupUmbracoContextForTest(ctx, templateId);
+
return ctx;
}
@@ -306,27 +315,6 @@ namespace Umbraco.Tests.TestHelpers
return new FakeRoutesCache();
}
- ///
- /// Initlializes the UmbracoContext with specific XML
- ///
- ///
- ///
- protected void SetupUmbracoContextForTest(UmbracoContext umbracoContext, int templateId)
- {
- var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache;
- if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported.");
- cache.GetXmlDelegate = (user, preview) =>
- {
- var xDoc = new XmlDocument();
-
- //create a custom xml structure to return
-
- xDoc.LoadXml(GetXmlContent(templateId));
- //return the custom x doc
- return xDoc;
- };
- }
-
protected virtual string GetXmlContent(int templateId)
{
return @"
diff --git a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs
index 0a32ad8e8d..393eb1e44f 100644
--- a/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs
+++ b/src/Umbraco.Web/PublishedCache/ContextualPublishedContentCache.cs
@@ -24,6 +24,12 @@ namespace Umbraco.Web.PublishedCache
_cache = cache;
}
+ ///
+ /// Gets the inner IPublishedContentCache.
+ ///
+ /// For unit tests.
+ internal IPublishedContentCache InnerCache { get { return _cache; } }
+
///
/// Gets a content identified by its unique identifier.
///
@@ -80,11 +86,10 @@ namespace Umbraco.Web.PublishedCache
///
/// Gets a value indicating whether the underlying non-contextual cache contains published content.
///
- /// The context.
/// A value indicating whether the underlying non-contextual cache contains published content.
- public bool HasContent(UmbracoContext umbracoContext)
+ public bool HasContent()
{
- return _cache.HasContent(umbracoContext);
+ return _cache.HasContent();
}
}
}
diff --git a/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs
index 42457426dc..701821f159 100644
--- a/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs
+++ b/src/Umbraco.Web/PublishedCache/IPublishedContentCache.cs
@@ -18,8 +18,7 @@ namespace Umbraco.Web.PublishedCache
///
/// Gets a value indicating whether the cache contains published content.
///
- /// The context.
/// A value indicating whether the cache contains published content.
- bool HasContent(UmbracoContext umbracoContext);
+ bool HasContent();
}
}
diff --git a/src/Umbraco.Web/PublishedCache/LegacyXmlCache/PublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/LegacyXmlCache/PublishedContentCache.cs
index 29e9946eea..a16eef8399 100644
--- a/src/Umbraco.Web/PublishedCache/LegacyXmlCache/PublishedContentCache.cs
+++ b/src/Umbraco.Web/PublishedCache/LegacyXmlCache/PublishedContentCache.cs
@@ -197,9 +197,9 @@ namespace Umbraco.Web.PublishedCache.LegacyXmlCache
return GetSingleByXPath(umbracoContext, xpath, var);
}
- public bool HasContent(UmbracoContext umbracoContext)
+ public bool HasContent()
{
- var xml = GetXml(umbracoContext, false);
+ var xml = GetXml();
if (xml == null)
return false;
var node = xml.SelectSingleNode(XPathStrings.RootDocuments);
@@ -253,9 +253,9 @@ namespace Umbraco.Web.PublishedCache.LegacyXmlCache
return GetXmlDelegate(umbracoContext.UmbracoUser, umbracoContext.InPreviewMode);
}
- internal XmlDocument GetXml(UmbracoContext umbracoContext, bool inPreviewMode)
+ internal XmlDocument GetXml()
{
- return GetXmlDelegate(umbracoContext.UmbracoUser, inPreviewMode);
+ return GetXmlDelegate(null, false);
}
#endregion
diff --git a/src/Umbraco.Web/PublishedCache/PublishedContentCacheResolver.cs b/src/Umbraco.Web/PublishedCache/PublishedContentCacheResolver.cs
index 5c02f75216..b7e49e0b91 100644
--- a/src/Umbraco.Web/PublishedCache/PublishedContentCacheResolver.cs
+++ b/src/Umbraco.Web/PublishedCache/PublishedContentCacheResolver.cs
@@ -19,17 +19,17 @@ namespace Umbraco.Web.PublishedCache
///
/// Sets the content cache.
///
- /// The content cache.
+ /// The content cache.
/// For developers, at application startup.
- public void SetContentStore(IPublishedContentCache publishedContentCache)
+ public void SetContentCache(IPublishedContentCache contentCache)
{
- Value = publishedContentCache;
+ Value = contentCache;
}
///
/// Gets the content cache.
///
- public IPublishedContentCache PublishedContentCache
+ public IPublishedContentCache ContentCache
{
get { return Value; }
}
diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs
index 500e02ea55..d869ae7fee 100644
--- a/src/Umbraco.Web/UmbracoContext.cs
+++ b/src/Umbraco.Web/UmbracoContext.cs
@@ -84,7 +84,7 @@ namespace Umbraco.Web
var umbracoContext = new UmbracoContext(
httpContext,
applicationContext,
- PublishedContentCacheResolver.Current.PublishedContentCache,
+ PublishedContentCacheResolver.Current.ContentCache,
PublishedMediaCacheResolver.Current.PublishedMediaCache);
// create the nice urls provider
diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs
index 10ed48957d..36adfdcb29 100644
--- a/src/Umbraco.Web/UmbracoModule.cs
+++ b/src/Umbraco.Web/UmbracoModule.cs
@@ -317,8 +317,7 @@ namespace Umbraco.Web
// if yes, return true
private static bool EnsureHasContent(UmbracoContext context, HttpContextBase httpContext)
{
- var store = context.ContentCache;
- if (store.HasContent(context))
+ if (context.ContentCache.HasContent())
return true;
LogHelper.Warn("Umbraco has no content");