2017-07-20 11:21:28 +02:00
|
|
|
|
using System.Linq;
|
2012-07-31 00:02:27 +06:00
|
|
|
|
using System.Xml;
|
2013-09-17 00:14:15 +10:00
|
|
|
|
using Moq;
|
2012-07-31 00:02:27 +06:00
|
|
|
|
using NUnit.Framework;
|
2016-05-26 18:48:35 +02:00
|
|
|
|
using Umbraco.Core.Cache;
|
2017-05-30 18:13:11 +02:00
|
|
|
|
using Umbraco.Core.Composing;
|
2012-07-31 00:02:27 +06:00
|
|
|
|
using Umbraco.Tests.TestHelpers;
|
2016-12-16 10:40:14 +01:00
|
|
|
|
using Umbraco.Tests.Testing;
|
2012-07-31 00:02:27 +06:00
|
|
|
|
using Umbraco.Web;
|
2013-03-19 17:51:55 -01:00
|
|
|
|
using Umbraco.Web.PublishedCache;
|
2013-03-22 15:02:26 -01:00
|
|
|
|
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
2016-05-26 18:48:35 +02:00
|
|
|
|
using Umbraco.Web.Routing;
|
2013-07-31 18:21:27 +10:00
|
|
|
|
using Umbraco.Web.Security;
|
2012-07-31 00:02:27 +06:00
|
|
|
|
|
2015-05-05 16:11:06 +10:00
|
|
|
|
namespace Umbraco.Tests.Cache.PublishedCache
|
2012-07-31 00:02:27 +06:00
|
|
|
|
{
|
2017-07-20 11:21:28 +02:00
|
|
|
|
[TestFixture]
|
2016-11-05 19:23:55 +01:00
|
|
|
|
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerFixture)]
|
|
|
|
|
|
public class PublishContentCacheTests : BaseWebTest
|
2017-07-20 11:21:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
private FakeHttpContextFactory _httpContextFactory;
|
|
|
|
|
|
private UmbracoContext _umbracoContext;
|
|
|
|
|
|
private IPublishedContentCache _cache;
|
|
|
|
|
|
private XmlDocument _xml;
|
|
|
|
|
|
|
|
|
|
|
|
private string GetXml()
|
|
|
|
|
|
{
|
|
|
|
|
|
return @"<?xml version=""1.0"" encoding=""utf-8""?><!DOCTYPE root[
|
2012-07-31 00:02:27 +06:00
|
|
|
|
<!ELEMENT Home ANY>
|
|
|
|
|
|
<!ATTLIST Home id ID #REQUIRED>
|
|
|
|
|
|
|
|
|
|
|
|
]>
|
|
|
|
|
|
<root id=""-1"">
|
2017-07-20 11:21:28 +02:00
|
|
|
|
<Home id=""1046"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Home"" urlName=""home"" writerName=""admin"" creatorName=""admin"" path=""-1,1046"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
|
<Home id=""1173"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""1"" createDate=""2012-07-20T18:06:45"" updateDate=""2012-07-20T19:07:31"" nodeName=""Sub1"" urlName=""sub1"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
|
<Home id=""1174"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""1"" createDate=""2012-07-20T18:07:54"" updateDate=""2012-07-20T19:10:27"" nodeName=""Sub2"" urlName=""sub2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1174"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
|
</Home>
|
|
|
|
|
|
<Home id=""1176"" parentID=""1173"" level=""3"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:08"" updateDate=""2012-07-20T19:10:52"" nodeName=""Sub 3"" urlName=""sub-3"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1173,1176"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
|
</Home>
|
|
|
|
|
|
</Home>
|
|
|
|
|
|
<Home id=""1175"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub 2"" urlName=""sub-2"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1175"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
|
</Home>
|
|
|
|
|
|
<Home id=""1177"" parentID=""1046"" level=""2"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""2"" createDate=""2012-07-20T18:08:01"" updateDate=""2012-07-20T18:49:32"" nodeName=""Sub'Apostrophe"" urlName=""sub'apostrophe"" writerName=""admin"" creatorName=""admin"" path=""-1,1046,1177"" isDoc=""""><content><![CDATA[]]></content>
|
|
|
|
|
|
</Home>
|
|
|
|
|
|
</Home>
|
|
|
|
|
|
<Home id=""1172"" parentID=""-1"" level=""1"" writerID=""0"" creatorID=""0"" nodeType=""1044"" template=""1045"" sortOrder=""3"" createDate=""2012-07-16T15:26:59"" updateDate=""2012-07-18T14:23:35"" nodeName=""Test"" urlName=""test"" writerName=""admin"" creatorName=""admin"" path=""-1,1172"" isDoc="""" />
|
2012-10-04 21:37:11 +05:00
|
|
|
|
</root>";
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|
2012-10-04 21:37:11 +05:00
|
|
|
|
|
2016-10-13 21:08:07 +02:00
|
|
|
|
public override void SetUp()
|
2013-09-05 17:47:13 +02:00
|
|
|
|
{
|
2016-10-13 21:08:07 +02:00
|
|
|
|
base.SetUp();
|
2013-03-23 04:01:52 +06:00
|
|
|
|
|
2013-09-05 17:47:13 +02:00
|
|
|
|
_httpContextFactory = new FakeHttpContextFactory("~/Home");
|
2016-09-01 19:06:08 +02:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
var settings = SettingsForTests.GenerateMockSettings();
|
2015-01-27 15:18:58 +11:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
SettingsForTests.ConfigureSettings(settings);
|
2013-09-05 17:47:13 +02:00
|
|
|
|
_xml = new XmlDocument();
|
|
|
|
|
|
_xml.LoadXml(GetXml());
|
2017-12-15 11:19:03 +01:00
|
|
|
|
var xmlStore = new XmlStore(() => _xml, null, null, null);
|
2017-07-20 11:21:28 +02:00
|
|
|
|
var cacheProvider = new StaticCacheProvider();
|
2016-05-26 18:48:35 +02:00
|
|
|
|
var domainCache = new DomainCache(ServiceContext.DomainService);
|
2017-10-31 12:48:24 +01:00
|
|
|
|
var publishedShapshot = new Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedShapshot(
|
2017-07-20 11:21:28 +02:00
|
|
|
|
new PublishedContentCache(xmlStore, domainCache, cacheProvider, ContentTypesCache, null, null),
|
|
|
|
|
|
new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, cacheProvider, ContentTypesCache),
|
|
|
|
|
|
new PublishedMemberCache(null, cacheProvider, Current.Services.MemberService, ContentTypesCache),
|
|
|
|
|
|
domainCache);
|
2017-10-31 12:48:24 +01:00
|
|
|
|
var publishedSnapshotService = new Mock<IPublishedSnapshotService>();
|
|
|
|
|
|
publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny<string>())).Returns(publishedShapshot);
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
|
|
|
|
|
_umbracoContext = new UmbracoContext(
|
|
|
|
|
|
_httpContextFactory.HttpContext,
|
2017-10-31 12:48:24 +01:00
|
|
|
|
publishedSnapshotService.Object,
|
2017-07-20 11:21:28 +02:00
|
|
|
|
new WebSecurity(_httpContextFactory.HttpContext, Current.Services.UserService),
|
|
|
|
|
|
settings,
|
|
|
|
|
|
Enumerable.Empty<IUrlProvider>());
|
|
|
|
|
|
|
|
|
|
|
|
_cache = _umbracoContext.ContentCache;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Has_Content()
|
|
|
|
|
|
{
|
|
|
|
|
|
Assert.IsTrue(_cache.HasContent());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
|
public void Get_Root_Docs()
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = _cache.GetAtRoot();
|
|
|
|
|
|
Assert.AreEqual(2, result.Count());
|
|
|
|
|
|
Assert.AreEqual(1046, result.ElementAt(0).Id);
|
|
|
|
|
|
Assert.AreEqual(1172, result.ElementAt(1).Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestCase("/", 1046)]
|
|
|
|
|
|
[TestCase("/home", 1046)]
|
|
|
|
|
|
[TestCase("/Home", 1046)] //test different cases
|
|
|
|
|
|
[TestCase("/home/sub1", 1173)]
|
|
|
|
|
|
[TestCase("/Home/sub1", 1173)]
|
|
|
|
|
|
[TestCase("/home/Sub1", 1173)] //test different cases
|
|
|
|
|
|
[TestCase("/home/Sub'Apostrophe", 1177)]
|
|
|
|
|
|
public void Get_Node_By_Route(string route, int nodeId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = _cache.GetByRoute(route, false);
|
|
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
|
|
Assert.AreEqual(nodeId, result.Id);
|
2013-09-05 17:47:13 +02:00
|
|
|
|
}
|
2012-10-04 21:37:11 +05:00
|
|
|
|
|
2017-07-20 11:21:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestCase("/", 1046)]
|
|
|
|
|
|
[TestCase("/sub1", 1173)]
|
|
|
|
|
|
[TestCase("/Sub1", 1173)]
|
|
|
|
|
|
public void Get_Node_By_Route_Hiding_Top_Level_Nodes(string route, int nodeId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = _cache.GetByRoute(route, true);
|
|
|
|
|
|
Assert.IsNotNull(result);
|
|
|
|
|
|
Assert.AreEqual(nodeId, result.Id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|