Web.PublishedCache - bugfix & fix tests
This commit is contained in:
@@ -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
|
||||
/// <returns></returns>
|
||||
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();
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ using umbraco.BusinessLogic;
|
||||
namespace Umbraco.Tests.PublishedCache
|
||||
{
|
||||
[TestFixture]
|
||||
public class PublishContentStoreTests
|
||||
public class PublishContentCacheTests
|
||||
{
|
||||
private FakeHttpContextFactory _httpContextFactory;
|
||||
private UmbracoContext _umbracoContext;
|
||||
@@ -74,42 +74,37 @@ namespace Umbraco.Tests.PublishedCache
|
||||
//ensure the StateHelper is using our custom context
|
||||
StateHelper.HttpContext = _httpContextFactory.HttpContext;
|
||||
|
||||
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]
|
||||
|
||||
@@ -16,7 +16,7 @@ using umbraco.BusinessLogic;
|
||||
namespace Umbraco.Tests.PublishedCache
|
||||
{
|
||||
[TestFixture]
|
||||
public class PublishMediaStoreTests : PublishedContentTestBase
|
||||
public class PublishMediaCacheTests : PublishedContentTestBase
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
|
||||
@@ -13,17 +13,6 @@ namespace Umbraco.Tests.PublishedContent
|
||||
[TestFixture]
|
||||
public abstract class DynamicDocumentTestsBase<TDocument, TDocumentList> : PublishedContentTestBase
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
}
|
||||
|
||||
public override void TearDown()
|
||||
{
|
||||
base.TearDown();
|
||||
|
||||
}
|
||||
|
||||
protected override DatabaseBehavior DatabaseTestBehavior
|
||||
{
|
||||
get { return DatabaseBehavior.NoDatabasePerFixture; }
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -66,25 +66,10 @@ namespace Umbraco.Tests.PublishedContent
|
||||
</root>";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ namespace Umbraco.Tests.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("ERROR! " + _error);
|
||||
throw new Exception("Error!", _error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initlializes the UmbracoContext with specific XML
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext"></param>
|
||||
/// <param name="templateId"></param>
|
||||
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 @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
|
||||
@@ -24,6 +24,12 @@ namespace Umbraco.Web.PublishedCache
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the inner IPublishedContentCache.
|
||||
/// </summary>
|
||||
/// <remarks>For unit tests.</remarks>
|
||||
internal IPublishedContentCache InnerCache { get { return _cache; } }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a content identified by its unique identifier.
|
||||
/// </summary>
|
||||
@@ -80,11 +86,10 @@ namespace Umbraco.Web.PublishedCache
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the underlying non-contextual cache contains published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The context.</param>
|
||||
/// <returns>A value indicating whether the underlying non-contextual cache contains published content.</returns>
|
||||
public bool HasContent(UmbracoContext umbracoContext)
|
||||
public bool HasContent()
|
||||
{
|
||||
return _cache.HasContent(umbracoContext);
|
||||
return _cache.HasContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ namespace Umbraco.Web.PublishedCache
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the cache contains published content.
|
||||
/// </summary>
|
||||
/// <param name="umbracoContext">The context.</param>
|
||||
/// <returns>A value indicating whether the cache contains published content.</returns>
|
||||
bool HasContent(UmbracoContext umbracoContext);
|
||||
bool HasContent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,17 +19,17 @@ namespace Umbraco.Web.PublishedCache
|
||||
/// <summary>
|
||||
/// Sets the content cache.
|
||||
/// </summary>
|
||||
/// <param name="publishedContentCache">The content cache.</param>
|
||||
/// <param name="contentCache">The content cache.</param>
|
||||
/// <remarks>For developers, at application startup.</remarks>
|
||||
public void SetContentStore(IPublishedContentCache publishedContentCache)
|
||||
public void SetContentCache(IPublishedContentCache contentCache)
|
||||
{
|
||||
Value = publishedContentCache;
|
||||
Value = contentCache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the content cache.
|
||||
/// </summary>
|
||||
public IPublishedContentCache PublishedContentCache
|
||||
public IPublishedContentCache ContentCache
|
||||
{
|
||||
get { return Value; }
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<UmbracoModule>("Umbraco has no content");
|
||||
|
||||
Reference in New Issue
Block a user