re-organizes a bit of cache tests into one folder
This commit is contained in:
@@ -3,15 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using umbraco.interfaces;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Core.Profiling;
|
||||
using Umbraco.Core.Sync;
|
||||
using umbraco.interfaces;
|
||||
|
||||
namespace Umbraco.Tests.DistributedCache
|
||||
namespace Umbraco.Tests.Cache.DistributedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Ensures that calls to DistributedCache methods carry through to the IServerMessenger correctly
|
||||
@@ -1,192 +1,188 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.ObjectResolution;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using Umbraco.Web.Security;
|
||||
using umbraco.BusinessLogic;
|
||||
|
||||
namespace Umbraco.Tests.PublishedCache
|
||||
{
|
||||
[DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerFixture)]
|
||||
[TestFixture]
|
||||
public class PublishContentCacheTests : BaseWebTest
|
||||
{
|
||||
private FakeHttpContextFactory _httpContextFactory;
|
||||
private UmbracoContext _umbracoContext;
|
||||
private ContextualPublishedContentCache _cache;
|
||||
private XmlDocument _xml;
|
||||
|
||||
private string GetLegacyXml()
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?><!DOCTYPE root[
|
||||
<!ELEMENT node ANY> <!ATTLIST node id ID #REQUIRED> <!ELEMENT data ANY>
|
||||
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
<node 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"" nodeTypeAlias=""Home""><content><![CDATA[]]></content>
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
</node>
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
</node>
|
||||
</node>
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
</node>
|
||||
</node>
|
||||
<node 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"" nodeTypeAlias=""Home"" />
|
||||
</root>";
|
||||
}
|
||||
|
||||
private string GetXml()
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?><!DOCTYPE root[
|
||||
<!ELEMENT Home ANY>
|
||||
<!ATTLIST Home id ID #REQUIRED>
|
||||
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<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="""" />
|
||||
</root>";
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_httpContextFactory = new FakeHttpContextFactory("~/Home");
|
||||
//ensure the StateHelper is using our custom context
|
||||
StateHelper.HttpContext = _httpContextFactory.HttpContext;
|
||||
|
||||
var settings = SettingsForTests.GenerateMockSettings();
|
||||
var contentMock = Mock.Get(settings.Content);
|
||||
contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(false);
|
||||
SettingsForTests.ConfigureSettings(settings);
|
||||
_xml = new XmlDocument();
|
||||
_xml.LoadXml(GetXml());
|
||||
var cache = new PublishedContentCache
|
||||
{
|
||||
GetXmlDelegate = (context, preview) => _xml
|
||||
};
|
||||
|
||||
_umbracoContext = new UmbracoContext(
|
||||
_httpContextFactory.HttpContext,
|
||||
ApplicationContext,
|
||||
new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
|
||||
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext));
|
||||
|
||||
_cache = _umbracoContext.ContentCache;
|
||||
}
|
||||
|
||||
private void SetupForLegacy()
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockSettings();
|
||||
var contentMock = Mock.Get(settings.Content);
|
||||
contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(true);
|
||||
SettingsForTests.ConfigureSettings(settings);
|
||||
_xml = new XmlDocument();
|
||||
_xml.LoadXml(GetLegacyXml());
|
||||
}
|
||||
|
||||
protected override void FreezeResolution()
|
||||
{
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Has_Content_LegacySchema()
|
||||
{
|
||||
SetupForLegacy();
|
||||
Has_Content();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Has_Content()
|
||||
{
|
||||
Assert.IsTrue(_cache.HasContent());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Root_Docs_LegacySchema()
|
||||
{
|
||||
SetupForLegacy();
|
||||
Get_Root_Docs();
|
||||
}
|
||||
|
||||
[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
|
||||
public void Get_Node_By_Route_LegacySchema(string route, int nodeId)
|
||||
{
|
||||
SetupForLegacy();
|
||||
Get_Node_By_Route(route, nodeId);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[TestCase("/", 1046)]
|
||||
[TestCase("/sub1", 1173)]
|
||||
[TestCase("/Sub1", 1173)]
|
||||
public void Get_Node_By_Route_Hiding_Top_Level_Nodes_LegacySchema(string route, int nodeId)
|
||||
{
|
||||
SetupForLegacy();
|
||||
Get_Node_By_Route_Hiding_Top_Level_Nodes(route, nodeId);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using umbraco.BusinessLogic;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using Umbraco.Web.Security;
|
||||
|
||||
namespace Umbraco.Tests.Cache.PublishedCache
|
||||
{
|
||||
[DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerFixture)]
|
||||
[TestFixture]
|
||||
public class PublishContentCacheTests : BaseWebTest
|
||||
{
|
||||
private FakeHttpContextFactory _httpContextFactory;
|
||||
private UmbracoContext _umbracoContext;
|
||||
private ContextualPublishedContentCache _cache;
|
||||
private XmlDocument _xml;
|
||||
|
||||
private string GetLegacyXml()
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?><!DOCTYPE root[
|
||||
<!ELEMENT node ANY> <!ATTLIST node id ID #REQUIRED> <!ELEMENT data ANY>
|
||||
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
<node 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"" nodeTypeAlias=""Home""><content><![CDATA[]]></content>
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
</node>
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
</node>
|
||||
</node>
|
||||
<node 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"" nodeTypeAlias=""Home"" ><content><![CDATA[]]></content>
|
||||
</node>
|
||||
</node>
|
||||
<node 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"" nodeTypeAlias=""Home"" />
|
||||
</root>";
|
||||
}
|
||||
|
||||
private string GetXml()
|
||||
{
|
||||
return @"<?xml version=""1.0"" encoding=""utf-8""?><!DOCTYPE root[
|
||||
<!ELEMENT Home ANY>
|
||||
<!ATTLIST Home id ID #REQUIRED>
|
||||
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<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="""" />
|
||||
</root>";
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_httpContextFactory = new FakeHttpContextFactory("~/Home");
|
||||
//ensure the StateHelper is using our custom context
|
||||
StateHelper.HttpContext = _httpContextFactory.HttpContext;
|
||||
|
||||
var settings = SettingsForTests.GenerateMockSettings();
|
||||
var contentMock = Mock.Get(settings.Content);
|
||||
contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(false);
|
||||
SettingsForTests.ConfigureSettings(settings);
|
||||
_xml = new XmlDocument();
|
||||
_xml.LoadXml(GetXml());
|
||||
var cache = new PublishedContentCache
|
||||
{
|
||||
GetXmlDelegate = (context, preview) => _xml
|
||||
};
|
||||
|
||||
_umbracoContext = new UmbracoContext(
|
||||
_httpContextFactory.HttpContext,
|
||||
ApplicationContext,
|
||||
new PublishedCaches(cache, new PublishedMediaCache(ApplicationContext)),
|
||||
new WebSecurity(_httpContextFactory.HttpContext, ApplicationContext));
|
||||
|
||||
_cache = _umbracoContext.ContentCache;
|
||||
}
|
||||
|
||||
private void SetupForLegacy()
|
||||
{
|
||||
var settings = SettingsForTests.GenerateMockSettings();
|
||||
var contentMock = Mock.Get(settings.Content);
|
||||
contentMock.Setup(x => x.UseLegacyXmlSchema).Returns(true);
|
||||
SettingsForTests.ConfigureSettings(settings);
|
||||
_xml = new XmlDocument();
|
||||
_xml.LoadXml(GetLegacyXml());
|
||||
}
|
||||
|
||||
protected override void FreezeResolution()
|
||||
{
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Has_Content_LegacySchema()
|
||||
{
|
||||
SetupForLegacy();
|
||||
Has_Content();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Has_Content()
|
||||
{
|
||||
Assert.IsTrue(_cache.HasContent());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Root_Docs_LegacySchema()
|
||||
{
|
||||
SetupForLegacy();
|
||||
Get_Root_Docs();
|
||||
}
|
||||
|
||||
[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
|
||||
public void Get_Node_By_Route_LegacySchema(string route, int nodeId)
|
||||
{
|
||||
SetupForLegacy();
|
||||
Get_Node_By_Route(route, nodeId);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[TestCase("/", 1046)]
|
||||
[TestCase("/sub1", 1173)]
|
||||
[TestCase("/Sub1", 1173)]
|
||||
public void Get_Node_By_Route_Hiding_Top_Level_Nodes_LegacySchema(string route, int nodeId)
|
||||
{
|
||||
SetupForLegacy();
|
||||
Get_Node_By_Route_Hiding_Top_Level_Nodes(route, nodeId);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,331 +1,330 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Examine;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Tests.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
using umbraco.BusinessLogic;
|
||||
|
||||
namespace Umbraco.Tests.PublishedCache
|
||||
{
|
||||
[DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)]
|
||||
[TestFixture]
|
||||
public class PublishMediaCacheTests : BaseWebTest
|
||||
{
|
||||
protected override void FreezeResolution()
|
||||
{
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Root_Docs()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot1", mType, user, -1);
|
||||
var mRoot2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot2", mType, user, -1);
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot1.Id);
|
||||
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 roots = cache.GetAtRoot();
|
||||
Assert.AreEqual(2, roots.Count());
|
||||
Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Item_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
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));
|
||||
|
||||
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"));
|
||||
Assert.AreEqual(mRoot.User.Id, publishedMedia.CreatorId);
|
||||
Assert.AreEqual(mRoot.User.Name, publishedMedia.CreatorName);
|
||||
Assert.AreEqual(mRoot.ContentType.Alias, publishedMedia.DocumentTypeAlias);
|
||||
Assert.AreEqual(mRoot.ContentType.Id, publishedMedia.DocumentTypeId);
|
||||
Assert.AreEqual(mRoot.Level, publishedMedia.Level);
|
||||
Assert.AreEqual(mRoot.Text, publishedMedia.Name);
|
||||
Assert.AreEqual(mRoot.Path, publishedMedia.Path);
|
||||
Assert.AreEqual(mRoot.sortOrder, publishedMedia.SortOrder);
|
||||
Assert.IsNull(publishedMedia.Parent);
|
||||
}
|
||||
|
||||
[TestCase("id")]
|
||||
[TestCase("nodeId")]
|
||||
[TestCase("__NodeId")]
|
||||
public void DictionaryDocument_Id_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(idKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("template")]
|
||||
[TestCase("templateId")]
|
||||
public void DictionaryDocument_Template_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(templateKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("nodeName")]
|
||||
[TestCase("__nodeName")]
|
||||
public void DictionaryDocument_NodeName_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(nodeNameKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("nodeTypeAlias")]
|
||||
[TestCase("__NodeTypeAlias")]
|
||||
public void DictionaryDocument_NodeTypeAlias_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(nodeTypeAliasKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("path")]
|
||||
[TestCase("__Path")]
|
||||
public void DictionaryDocument_Path_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(pathKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DictionaryDocument_Get_Children()
|
||||
{
|
||||
var child1 = GetDictionaryDocument(idVal: 222333);
|
||||
var child2 = GetDictionaryDocument(idVal: 444555);
|
||||
|
||||
var dicDoc = GetDictionaryDocument(children: new List<IPublishedContent>()
|
||||
{
|
||||
child1, child2
|
||||
});
|
||||
|
||||
Assert.AreEqual(2, dicDoc.Children.Count());
|
||||
Assert.AreEqual(222333, dicDoc.Children.ElementAt(0).Id);
|
||||
Assert.AreEqual(444555, dicDoc.Children.ElementAt(1).Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_From_Search_Result()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var result = new SearchResult()
|
||||
{
|
||||
Id = 1234,
|
||||
Score = 1
|
||||
};
|
||||
result.Fields.Add("__IndexType", "media");
|
||||
result.Fields.Add("__NodeId", "1234");
|
||||
result.Fields.Add("__NodeTypeAlias", Constants.Conventions.MediaTypes.Image);
|
||||
result.Fields.Add("__Path", "-1,1234");
|
||||
result.Fields.Add("__nodeName", "Test");
|
||||
result.Fields.Add("id", "1234");
|
||||
result.Fields.Add("nodeName", "Test");
|
||||
result.Fields.Add("nodeTypeAlias", Constants.Conventions.MediaTypes.Image);
|
||||
result.Fields.Add("parentID", "-1");
|
||||
result.Fields.Add("path", "-1,1234");
|
||||
result.Fields.Add("updateDate", "2012-07-16T10:34:09");
|
||||
result.Fields.Add("writerName", "Shannon");
|
||||
|
||||
var store = new PublishedMediaCache(ctx.Application);
|
||||
var doc = store.ConvertFromSearchResult(result);
|
||||
|
||||
DoAssert(doc, 1234, 0, 0, "", "Image", 0, "Shannon", "", 0, 0, "-1,1234", default(DateTime), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_From_XPath_Navigator()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var xmlDoc = GetMediaXml();
|
||||
var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator();
|
||||
var cache = new PublishedMediaCache(ctx.Application);
|
||||
var doc = cache.ConvertFromXPathNavigator(navigator);
|
||||
|
||||
DoAssert(doc, 2000, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon2", 22, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
Assert.AreEqual(2, doc.Children.Count());
|
||||
Assert.AreEqual(2001, doc.Children.ElementAt(0).Id);
|
||||
Assert.AreEqual(2002, doc.Children.ElementAt(1).Id);
|
||||
}
|
||||
|
||||
private XmlDocument GetMediaXml()
|
||||
{
|
||||
var xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<!DOCTYPE root[
|
||||
<!ELEMENT Home ANY>
|
||||
<!ATTLIST Home id ID #REQUIRED>
|
||||
<!ELEMENT CustomDocument ANY>
|
||||
<!ATTLIST CustomDocument id ID #REQUIRED>
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<Image id=""2000"" parentID=""-1"" level=""1"" writerID=""22"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon2"" path=""-1,2000"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
<Image id=""2001"" parentID=""2000"" level=""2"" writerID=""22"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon2"" path=""-1,2000,2001"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
</Image>
|
||||
<Image id=""2002"" parentID=""2000"" level=""2"" writerID=""22"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon2"" path=""-1,2000,2002"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
</Image>
|
||||
</Image>
|
||||
</root>";
|
||||
|
||||
var xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(xml);
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
private Dictionary<string, string> GetDictionary(
|
||||
int id,
|
||||
int parentId,
|
||||
string idKey,
|
||||
string templateKey,
|
||||
string nodeNameKey,
|
||||
string nodeTypeAliasKey,
|
||||
string pathKey)
|
||||
{
|
||||
return new Dictionary<string, string>()
|
||||
{
|
||||
{idKey, id.ToString()},
|
||||
{templateKey, "333"},
|
||||
{"sortOrder", "44"},
|
||||
{nodeNameKey, "Testing"},
|
||||
{"urlName", "testing"},
|
||||
{nodeTypeAliasKey, "myType"},
|
||||
{"nodeType", "22"},
|
||||
{"writerName", "Shannon"},
|
||||
{"creatorName", "Shannon2"},
|
||||
{"writerID", "33"},
|
||||
{"creatorID", "44"},
|
||||
{pathKey, "1,2,3,4,5"},
|
||||
{"createDate", "2012-01-02"},
|
||||
{"updateDate", "2012-01-03"},
|
||||
{"level", "3"},
|
||||
{"parentID", parentId.ToString()}
|
||||
};
|
||||
}
|
||||
|
||||
private PublishedMediaCache.DictionaryPublishedContent GetDictionaryDocument(
|
||||
string idKey = "id",
|
||||
string templateKey = "template",
|
||||
string nodeNameKey = "nodeName",
|
||||
string nodeTypeAliasKey = "nodeTypeAlias",
|
||||
string pathKey = "path",
|
||||
int idVal = 1234,
|
||||
int parentIdVal = 321,
|
||||
IEnumerable<IPublishedContent> children = null)
|
||||
{
|
||||
if (children == null)
|
||||
children = new List<IPublishedContent>();
|
||||
var dicDoc = new PublishedMediaCache.DictionaryPublishedContent(
|
||||
//the dictionary
|
||||
GetDictionary(idVal, parentIdVal, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
|
||||
//callback to get the parent
|
||||
d => new PublishedMediaCache.DictionaryPublishedContent(
|
||||
GetDictionary(parentIdVal, -1, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
|
||||
//there is no parent
|
||||
a => null,
|
||||
//we're not going to test this so ignore
|
||||
a => new List<IPublishedContent>(),
|
||||
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
|
||||
false),
|
||||
//callback to get the children
|
||||
d => children,
|
||||
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
|
||||
false);
|
||||
return dicDoc;
|
||||
}
|
||||
|
||||
private void DoAssert(
|
||||
PublishedMediaCache.DictionaryPublishedContent dicDoc,
|
||||
int idVal = 1234,
|
||||
int templateIdVal = 333,
|
||||
int sortOrderVal = 44,
|
||||
string urlNameVal = "testing",
|
||||
string nodeTypeAliasVal = "myType",
|
||||
int nodeTypeIdVal = 22,
|
||||
string writerNameVal = "Shannon",
|
||||
string creatorNameVal = "Shannon2",
|
||||
int writerIdVal = 33,
|
||||
int creatorIdVal = 44,
|
||||
string pathVal = "1,2,3,4,5",
|
||||
DateTime? createDateVal = null,
|
||||
DateTime? updateDateVal = null,
|
||||
int levelVal = 3,
|
||||
int parentIdVal = 321)
|
||||
{
|
||||
if (!createDateVal.HasValue)
|
||||
createDateVal = DateTime.Parse("2012-01-02");
|
||||
if (!updateDateVal.HasValue)
|
||||
updateDateVal = DateTime.Parse("2012-01-03");
|
||||
|
||||
DoAssert((IPublishedContent)dicDoc, idVal, templateIdVal, sortOrderVal, urlNameVal, nodeTypeAliasVal, nodeTypeIdVal, writerNameVal,
|
||||
creatorNameVal, writerIdVal, creatorIdVal, pathVal, createDateVal, updateDateVal, levelVal);
|
||||
|
||||
//now validate the parentId that has been parsed, this doesn't exist on the IPublishedContent
|
||||
Assert.AreEqual(parentIdVal, dicDoc.ParentId);
|
||||
}
|
||||
|
||||
private void DoAssert(
|
||||
IPublishedContent doc,
|
||||
int idVal = 1234,
|
||||
int templateIdVal = 333,
|
||||
int sortOrderVal = 44,
|
||||
string urlNameVal = "testing",
|
||||
string nodeTypeAliasVal = "myType",
|
||||
int nodeTypeIdVal = 22,
|
||||
string writerNameVal = "Shannon",
|
||||
string creatorNameVal = "Shannon2",
|
||||
int writerIdVal = 33,
|
||||
int creatorIdVal = 44,
|
||||
string pathVal = "1,2,3,4,5",
|
||||
DateTime? createDateVal = null,
|
||||
DateTime? updateDateVal = null,
|
||||
int levelVal = 3)
|
||||
{
|
||||
if (!createDateVal.HasValue)
|
||||
createDateVal = DateTime.Parse("2012-01-02");
|
||||
if (!updateDateVal.HasValue)
|
||||
updateDateVal = DateTime.Parse("2012-01-03");
|
||||
|
||||
Assert.AreEqual(idVal, doc.Id);
|
||||
Assert.AreEqual(templateIdVal, doc.TemplateId);
|
||||
Assert.AreEqual(sortOrderVal, doc.SortOrder);
|
||||
Assert.AreEqual(urlNameVal, doc.UrlName);
|
||||
Assert.AreEqual(nodeTypeAliasVal, doc.DocumentTypeAlias);
|
||||
Assert.AreEqual(nodeTypeIdVal, doc.DocumentTypeId);
|
||||
Assert.AreEqual(writerNameVal, doc.WriterName);
|
||||
Assert.AreEqual(creatorNameVal, doc.CreatorName);
|
||||
Assert.AreEqual(writerIdVal, doc.WriterId);
|
||||
Assert.AreEqual(creatorIdVal, doc.CreatorId);
|
||||
Assert.AreEqual(pathVal, doc.Path);
|
||||
Assert.AreEqual(createDateVal.Value, doc.CreateDate);
|
||||
Assert.AreEqual(updateDateVal.Value, doc.UpdateDate);
|
||||
Assert.AreEqual(levelVal, doc.Level);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Examine;
|
||||
using NUnit.Framework;
|
||||
using umbraco.BusinessLogic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Tests.PublishedContent;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.PublishedCache.XmlPublishedCache;
|
||||
|
||||
namespace Umbraco.Tests.Cache.PublishedCache
|
||||
{
|
||||
[DatabaseTestBehavior(DatabaseBehavior.NewDbFileAndSchemaPerTest)]
|
||||
[TestFixture]
|
||||
public class PublishMediaCacheTests : BaseWebTest
|
||||
{
|
||||
protected override void FreezeResolution()
|
||||
{
|
||||
PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver();
|
||||
base.FreezeResolution();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Root_Docs()
|
||||
{
|
||||
var user = new User(0);
|
||||
var mType = global::umbraco.cms.businesslogic.media.MediaType.MakeNew(user, "TestMediaType");
|
||||
var mRoot1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot1", mType, user, -1);
|
||||
var mRoot2 = global::umbraco.cms.businesslogic.media.Media.MakeNew("MediaRoot2", mType, user, -1);
|
||||
var mChild1 = global::umbraco.cms.businesslogic.media.Media.MakeNew("Child1", mType, user, mRoot1.Id);
|
||||
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 roots = cache.GetAtRoot();
|
||||
Assert.AreEqual(2, roots.Count());
|
||||
Assert.IsTrue(roots.Select(x => x.Id).ContainsAll(new[] {mRoot1.Id, mRoot2.Id}));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Get_Item_Without_Examine()
|
||||
{
|
||||
var user = new User(0);
|
||||
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));
|
||||
|
||||
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"));
|
||||
Assert.AreEqual(mRoot.User.Id, publishedMedia.CreatorId);
|
||||
Assert.AreEqual(mRoot.User.Name, publishedMedia.CreatorName);
|
||||
Assert.AreEqual(mRoot.ContentType.Alias, publishedMedia.DocumentTypeAlias);
|
||||
Assert.AreEqual(mRoot.ContentType.Id, publishedMedia.DocumentTypeId);
|
||||
Assert.AreEqual(mRoot.Level, publishedMedia.Level);
|
||||
Assert.AreEqual(mRoot.Text, publishedMedia.Name);
|
||||
Assert.AreEqual(mRoot.Path, publishedMedia.Path);
|
||||
Assert.AreEqual(mRoot.sortOrder, publishedMedia.SortOrder);
|
||||
Assert.IsNull(publishedMedia.Parent);
|
||||
}
|
||||
|
||||
[TestCase("id")]
|
||||
[TestCase("nodeId")]
|
||||
[TestCase("__NodeId")]
|
||||
public void DictionaryDocument_Id_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(idKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("template")]
|
||||
[TestCase("templateId")]
|
||||
public void DictionaryDocument_Template_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(templateKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("nodeName")]
|
||||
[TestCase("__nodeName")]
|
||||
public void DictionaryDocument_NodeName_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(nodeNameKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("nodeTypeAlias")]
|
||||
[TestCase("__NodeTypeAlias")]
|
||||
public void DictionaryDocument_NodeTypeAlias_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(nodeTypeAliasKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[TestCase("path")]
|
||||
[TestCase("__Path")]
|
||||
public void DictionaryDocument_Path_Keys(string key)
|
||||
{
|
||||
var dicDoc = GetDictionaryDocument(pathKey: key);
|
||||
DoAssert(dicDoc);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DictionaryDocument_Get_Children()
|
||||
{
|
||||
var child1 = GetDictionaryDocument(idVal: 222333);
|
||||
var child2 = GetDictionaryDocument(idVal: 444555);
|
||||
|
||||
var dicDoc = GetDictionaryDocument(children: new List<IPublishedContent>()
|
||||
{
|
||||
child1, child2
|
||||
});
|
||||
|
||||
Assert.AreEqual(2, dicDoc.Children.Count());
|
||||
Assert.AreEqual(222333, dicDoc.Children.ElementAt(0).Id);
|
||||
Assert.AreEqual(444555, dicDoc.Children.ElementAt(1).Id);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_From_Search_Result()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var result = new SearchResult()
|
||||
{
|
||||
Id = 1234,
|
||||
Score = 1
|
||||
};
|
||||
result.Fields.Add("__IndexType", "media");
|
||||
result.Fields.Add("__NodeId", "1234");
|
||||
result.Fields.Add("__NodeTypeAlias", Constants.Conventions.MediaTypes.Image);
|
||||
result.Fields.Add("__Path", "-1,1234");
|
||||
result.Fields.Add("__nodeName", "Test");
|
||||
result.Fields.Add("id", "1234");
|
||||
result.Fields.Add("nodeName", "Test");
|
||||
result.Fields.Add("nodeTypeAlias", Constants.Conventions.MediaTypes.Image);
|
||||
result.Fields.Add("parentID", "-1");
|
||||
result.Fields.Add("path", "-1,1234");
|
||||
result.Fields.Add("updateDate", "2012-07-16T10:34:09");
|
||||
result.Fields.Add("writerName", "Shannon");
|
||||
|
||||
var store = new PublishedMediaCache(ctx.Application);
|
||||
var doc = store.ConvertFromSearchResult(result);
|
||||
|
||||
DoAssert(doc, 1234, 0, 0, "", "Image", 0, "Shannon", "", 0, 0, "-1,1234", default(DateTime), DateTime.Parse("2012-07-16T10:34:09"), 2);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Convert_From_XPath_Navigator()
|
||||
{
|
||||
var ctx = GetUmbracoContext("/test", 1234);
|
||||
|
||||
var xmlDoc = GetMediaXml();
|
||||
var navigator = xmlDoc.SelectSingleNode("/root/Image").CreateNavigator();
|
||||
var cache = new PublishedMediaCache(ctx.Application);
|
||||
var doc = cache.ConvertFromXPathNavigator(navigator);
|
||||
|
||||
DoAssert(doc, 2000, 0, 2, "image1", "Image", 2044, "Shannon", "Shannon2", 22, 33, "-1,2000", DateTime.Parse("2012-06-12T14:13:17"), DateTime.Parse("2012-07-20T18:50:43"), 1);
|
||||
Assert.AreEqual(null, doc.Parent);
|
||||
Assert.AreEqual(2, doc.Children.Count());
|
||||
Assert.AreEqual(2001, doc.Children.ElementAt(0).Id);
|
||||
Assert.AreEqual(2002, doc.Children.ElementAt(1).Id);
|
||||
}
|
||||
|
||||
private XmlDocument GetMediaXml()
|
||||
{
|
||||
var xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<!DOCTYPE root[
|
||||
<!ELEMENT Home ANY>
|
||||
<!ATTLIST Home id ID #REQUIRED>
|
||||
<!ELEMENT CustomDocument ANY>
|
||||
<!ATTLIST CustomDocument id ID #REQUIRED>
|
||||
]>
|
||||
<root id=""-1"">
|
||||
<Image id=""2000"" parentID=""-1"" level=""1"" writerID=""22"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon2"" path=""-1,2000"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
<Image id=""2001"" parentID=""2000"" level=""2"" writerID=""22"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon2"" path=""-1,2000,2001"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
</Image>
|
||||
<Image id=""2002"" parentID=""2000"" level=""2"" writerID=""22"" creatorID=""33"" nodeType=""2044"" template=""0"" sortOrder=""2"" createDate=""2012-06-12T14:13:17"" updateDate=""2012-07-20T18:50:43"" nodeName=""Image1"" urlName=""image1"" writerName=""Shannon"" creatorName=""Shannon2"" path=""-1,2000,2002"" isDoc="""">
|
||||
<file><![CDATA[/media/1234/image1.png]]></file>
|
||||
</Image>
|
||||
</Image>
|
||||
</root>";
|
||||
|
||||
var xmlDoc = new XmlDocument();
|
||||
xmlDoc.LoadXml(xml);
|
||||
return xmlDoc;
|
||||
}
|
||||
|
||||
private Dictionary<string, string> GetDictionary(
|
||||
int id,
|
||||
int parentId,
|
||||
string idKey,
|
||||
string templateKey,
|
||||
string nodeNameKey,
|
||||
string nodeTypeAliasKey,
|
||||
string pathKey)
|
||||
{
|
||||
return new Dictionary<string, string>()
|
||||
{
|
||||
{idKey, id.ToString()},
|
||||
{templateKey, "333"},
|
||||
{"sortOrder", "44"},
|
||||
{nodeNameKey, "Testing"},
|
||||
{"urlName", "testing"},
|
||||
{nodeTypeAliasKey, "myType"},
|
||||
{"nodeType", "22"},
|
||||
{"writerName", "Shannon"},
|
||||
{"creatorName", "Shannon2"},
|
||||
{"writerID", "33"},
|
||||
{"creatorID", "44"},
|
||||
{pathKey, "1,2,3,4,5"},
|
||||
{"createDate", "2012-01-02"},
|
||||
{"updateDate", "2012-01-03"},
|
||||
{"level", "3"},
|
||||
{"parentID", parentId.ToString()}
|
||||
};
|
||||
}
|
||||
|
||||
private PublishedMediaCache.DictionaryPublishedContent GetDictionaryDocument(
|
||||
string idKey = "id",
|
||||
string templateKey = "template",
|
||||
string nodeNameKey = "nodeName",
|
||||
string nodeTypeAliasKey = "nodeTypeAlias",
|
||||
string pathKey = "path",
|
||||
int idVal = 1234,
|
||||
int parentIdVal = 321,
|
||||
IEnumerable<IPublishedContent> children = null)
|
||||
{
|
||||
if (children == null)
|
||||
children = new List<IPublishedContent>();
|
||||
var dicDoc = new PublishedMediaCache.DictionaryPublishedContent(
|
||||
//the dictionary
|
||||
GetDictionary(idVal, parentIdVal, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
|
||||
//callback to get the parent
|
||||
d => new PublishedMediaCache.DictionaryPublishedContent(
|
||||
GetDictionary(parentIdVal, -1, idKey, templateKey, nodeNameKey, nodeTypeAliasKey, pathKey),
|
||||
//there is no parent
|
||||
a => null,
|
||||
//we're not going to test this so ignore
|
||||
a => new List<IPublishedContent>(),
|
||||
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
|
||||
false),
|
||||
//callback to get the children
|
||||
d => children,
|
||||
(dd, a) => dd.Properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(a)),
|
||||
false);
|
||||
return dicDoc;
|
||||
}
|
||||
|
||||
private void DoAssert(
|
||||
PublishedMediaCache.DictionaryPublishedContent dicDoc,
|
||||
int idVal = 1234,
|
||||
int templateIdVal = 333,
|
||||
int sortOrderVal = 44,
|
||||
string urlNameVal = "testing",
|
||||
string nodeTypeAliasVal = "myType",
|
||||
int nodeTypeIdVal = 22,
|
||||
string writerNameVal = "Shannon",
|
||||
string creatorNameVal = "Shannon2",
|
||||
int writerIdVal = 33,
|
||||
int creatorIdVal = 44,
|
||||
string pathVal = "1,2,3,4,5",
|
||||
DateTime? createDateVal = null,
|
||||
DateTime? updateDateVal = null,
|
||||
int levelVal = 3,
|
||||
int parentIdVal = 321)
|
||||
{
|
||||
if (!createDateVal.HasValue)
|
||||
createDateVal = DateTime.Parse("2012-01-02");
|
||||
if (!updateDateVal.HasValue)
|
||||
updateDateVal = DateTime.Parse("2012-01-03");
|
||||
|
||||
DoAssert((IPublishedContent)dicDoc, idVal, templateIdVal, sortOrderVal, urlNameVal, nodeTypeAliasVal, nodeTypeIdVal, writerNameVal,
|
||||
creatorNameVal, writerIdVal, creatorIdVal, pathVal, createDateVal, updateDateVal, levelVal);
|
||||
|
||||
//now validate the parentId that has been parsed, this doesn't exist on the IPublishedContent
|
||||
Assert.AreEqual(parentIdVal, dicDoc.ParentId);
|
||||
}
|
||||
|
||||
private void DoAssert(
|
||||
IPublishedContent doc,
|
||||
int idVal = 1234,
|
||||
int templateIdVal = 333,
|
||||
int sortOrderVal = 44,
|
||||
string urlNameVal = "testing",
|
||||
string nodeTypeAliasVal = "myType",
|
||||
int nodeTypeIdVal = 22,
|
||||
string writerNameVal = "Shannon",
|
||||
string creatorNameVal = "Shannon2",
|
||||
int writerIdVal = 33,
|
||||
int creatorIdVal = 44,
|
||||
string pathVal = "1,2,3,4,5",
|
||||
DateTime? createDateVal = null,
|
||||
DateTime? updateDateVal = null,
|
||||
int levelVal = 3)
|
||||
{
|
||||
if (!createDateVal.HasValue)
|
||||
createDateVal = DateTime.Parse("2012-01-02");
|
||||
if (!updateDateVal.HasValue)
|
||||
updateDateVal = DateTime.Parse("2012-01-03");
|
||||
|
||||
Assert.AreEqual(idVal, doc.Id);
|
||||
Assert.AreEqual(templateIdVal, doc.TemplateId);
|
||||
Assert.AreEqual(sortOrderVal, doc.SortOrder);
|
||||
Assert.AreEqual(urlNameVal, doc.UrlName);
|
||||
Assert.AreEqual(nodeTypeAliasVal, doc.DocumentTypeAlias);
|
||||
Assert.AreEqual(nodeTypeIdVal, doc.DocumentTypeId);
|
||||
Assert.AreEqual(writerNameVal, doc.WriterName);
|
||||
Assert.AreEqual(creatorNameVal, doc.CreatorName);
|
||||
Assert.AreEqual(writerIdVal, doc.WriterId);
|
||||
Assert.AreEqual(creatorIdVal, doc.CreatorId);
|
||||
Assert.AreEqual(pathVal, doc.Path);
|
||||
Assert.AreEqual(createDateVal.Value, doc.CreateDate);
|
||||
Assert.AreEqual(updateDateVal.Value, doc.UpdateDate);
|
||||
Assert.AreEqual(levelVal, doc.Level);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -356,7 +356,7 @@
|
||||
<Compile Include="TestHelpers\BaseSeleniumTest.cs" />
|
||||
<Compile Include="Integration\InstallPackage.cs" />
|
||||
<Compile Include="CoreXml\NavigableNavigatorTests.cs" />
|
||||
<Compile Include="PublishedCache\PublishedMediaCacheTests.cs" />
|
||||
<Compile Include="Cache\PublishedCache\PublishedMediaCacheTests.cs" />
|
||||
<Compile Include="Strings\CmsHelperCasingTests.cs" />
|
||||
<Compile Include="Strings\ShortStringHelperResolverTest.cs" />
|
||||
<Compile Include="Strings\LegacyShortStringHelperTests.cs" />
|
||||
@@ -464,7 +464,7 @@
|
||||
<Compile Include="PublishedContent\DynamicDocumentTestsBase.cs" />
|
||||
<Compile Include="PublishedContent\DynamicNodeTests.cs" />
|
||||
<Compile Include="ObjectExtensionsTests.cs" />
|
||||
<Compile Include="PublishedCache\PublishedContentCacheTests.cs" />
|
||||
<Compile Include="Cache\PublishedCache\PublishedContentCacheTests.cs" />
|
||||
<Compile Include="Resolvers\LazyManyObjectResolverTests.cs" />
|
||||
<Compile Include="Resolvers\ManyResolverTests.cs" />
|
||||
<Compile Include="Resolvers\SingleResolverTests.cs" />
|
||||
@@ -490,7 +490,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Services\ThreadSafetyServiceTest.cs" />
|
||||
<Compile Include="Controllers\PluginControllerAreaTests.cs" />
|
||||
<Compile Include="DistributedCache\DistributedCacheTests.cs" />
|
||||
<Compile Include="Cache\DistributedCache\DistributedCacheTests.cs" />
|
||||
<Compile Include="Templates\MasterPageHelperTests.cs" />
|
||||
<Compile Include="TestHelpers\BaseDatabaseFactoryTest.cs" />
|
||||
<Compile Include="TestHelpers\BaseRoutingTest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user