U4-8447 - prepare for NuCache (fixing, now builds)

This commit is contained in:
Stephan
2016-05-26 18:48:35 +02:00
parent 06574b8b40
commit 23ce1e5b6e
31 changed files with 433 additions and 640 deletions

View File

@@ -3,11 +3,13 @@ using System.Xml;
using Moq;
using NUnit.Framework;
using umbraco.BusinessLogic;
using Umbraco.Core.Cache;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
namespace Umbraco.Tests.Cache.PublishedCache
@@ -18,7 +20,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
{
private FakeHttpContextFactory _httpContextFactory;
private UmbracoContext _umbracoContext;
private ContextualPublishedContentCache _cache;
private IPublishedContentCache _cache;
private XmlDocument _xml;
private string GetXml()
@@ -57,18 +59,28 @@ namespace Umbraco.Tests.Cache.PublishedCache
SettingsForTests.ConfigureSettings(settings);
_xml = new XmlDocument();
_xml.LoadXml(GetXml());
var cache = new PublishedContentCache((context, preview) => _xml);
var xmlStore = new XmlStore(() => _xml);
var cacheProvider = new StaticCacheProvider();
var domainCache = new DomainCache(ServiceContext.DomainService);
var facade = new Facade(
new PublishedContentCache(xmlStore, domainCache, cacheProvider, ContentTypesCache, null, null),
new PublishedMediaCache(xmlStore, ServiceContext.MediaService, cacheProvider, ContentTypesCache),
new PublishedMemberCache(null, cacheProvider, ApplicationContext.Services.MemberService, ContentTypesCache),
domainCache);
var facadeService = new Mock<IFacadeService>();
facadeService.Setup(x => x.CreateFacade(It.IsAny<string>())).Returns(facade);
_umbracoContext = new UmbracoContext(
_httpContextFactory.HttpContext,
ApplicationContext,
new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext));
_umbracoContext = UmbracoContext.CreateContext(
_httpContextFactory.HttpContext, ApplicationContext,
facadeService.Object,
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext),
settings,
Enumerable.Empty<IUrlProvider>(),
null);
_cache = _umbracoContext.ContentCache;
}
protected override void FreezeResolution()
{
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();

View File

@@ -10,6 +10,7 @@ using Moq;
using NUnit.Framework;
using umbraco.BusinessLogic;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
@@ -48,7 +49,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
var mChild2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child2", mType, user, mRoot2.Id);
var ctx = GetUmbracoContext("/test", 1234);
var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application), ctx);
var cache = new PublishedMediaCache(new XmlStore((XmlDocument) null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache);
var roots = cache.GetAtRoot();
Assert.AreEqual(2, roots.Count());
Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));
@@ -62,7 +63,12 @@ namespace Umbraco.Tests.Cache.PublishedCache
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
var mRoot = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot", mType, user, -1);
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot.Id);
var publishedMedia = PublishedMediaTests.GetNode(mRoot.Id, GetUmbracoContext("/test", 1234));
//var publishedMedia = PublishedMediaTests.GetNode(mRoot.Id, GetUmbracoContext("/test", 1234));
var umbracoContext = GetUmbracoContext("/test", 1234);
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), umbracoContext.Application.Services.MediaService, new StaticCacheProvider(), ContentTypesCache);
var publishedMedia = cache.GetById(mRoot.Id);
Assert.IsNotNull(publishedMedia);
Assert.AreEqual(mRoot.Id, publishedMedia.Id);
Assert.AreEqual(mRoot.CreateDateTime.ToString("dd/MM/yyyy HH:mm:ss"), publishedMedia.CreateDate.ToString("dd/MM/yyyy HH:mm:ss"));
@@ -173,7 +179,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
result.Fields.Add("creatorID", "0");
result.Fields.Add("creatorName", "Shannon");
var store = new PublishedMediaCache(ctx.Application);
var store = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache);
var doc = store.CreateFromCacheValues(store.ConvertFromSearchResult(result));
DoAssert(doc, 1234, key, 0, 0, "/media/test.jpg", "Image", 0, "Shannon", "Shannon", 0, 0, "-1,1234", DateTime.Parse("2012-07-17T10:34:09"), DateTime.Parse("2012-07-16T10:34:09"), 2);
@@ -189,7 +195,7 @@ namespace Umbraco.Tests.Cache.PublishedCache
var xmlDoc = GetMediaXml();
((XmlElement)xmlDoc.DocumentElement.FirstChild).SetAttribute("key", key.ToString());
var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator();
var cache = new PublishedMediaCache(ctx.Application);
var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache);
var doc = cache.CreateFromCacheValues(cache.ConvertFromXPathNavigator(navigator, true));
DoAssert(doc, 2000, key, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon", 33, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
@@ -271,23 +277,34 @@ namespace Umbraco.Tests.Cache.PublishedCache
if (children == null)
children = new List<IPublishedContent>();
var dicDoc = new PublishedMediaCache.DictionaryPublishedContent(
//the dictionary
GetDictionary(idVal, keyVal, parentIdVal, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
//callback to get the parent
d => new PublishedMediaCache.DictionaryPublishedContent(
GetDictionary(parentIdVal, default(Guid), -1, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
//there is no parent
a => null,
//we're not going to test this so ignore
(dd, n) => new List<IPublishedContent>(),
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
null,
false),
//callback to get the children
(dd, n) => children,
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
//the dictionary
GetDictionary(idVal, keyVal, parentIdVal, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
//callback to get the parent
d => new PublishedMediaCache.DictionaryPublishedContent(
// the dictionary
GetDictionary(parentIdVal, default(Guid), -1, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
// callback to get the parent: there is no parent
a => null,
// callback to get the children: we're not going to test this so ignore
(dd, n) => new List<IPublishedContent>(),
// callback to get a property
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
null, // cache provider
ContentTypesCache,
// no xpath
null,
false);
// not from examine
false),
//callback to get the children
(dd, n) => children,
// callback to get a property
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
null, // cache provider
ContentTypesCache,
// no xpath
null,
// not from examine
false);
return dicDoc;
}