From 23ce1e5b6edce58d74b3ecc30f31e3abc7c0cec4 Mon Sep 17 00:00:00 2001 From: Stephan Date: Thu, 26 May 2016 18:48:35 +0200 Subject: [PATCH] U4-8447 - prepare for NuCache (fixing, now builds) --- .../Models/Rdbms/ContentXmlDto.cs | 7 +- .../Models/Rdbms/PreviewXmlDto.cs | 16 +-- .../Repositories/ContentPreviewRepository.cs | 100 -------------- .../Repositories/ContentXmlRepository.cs | 98 -------------- src/Umbraco.Core/Umbraco.Core.csproj | 2 - .../PublishedContentCacheTests.cs | 28 ++-- .../PublishedMediaCacheTests.cs | 57 +++++--- .../CoreXml/NavigableNavigatorTests.cs | 116 +++++++++++++++- src/Umbraco.Tests/Macros/MacroTests.cs | 78 ++++++----- src/Umbraco.Tests/MockTests.cs | 13 +- .../PublishedContentMoreTests.cs | 24 ++-- .../PublishedContentTestElements.cs | 124 ++++++++---------- .../PublishedContent/PublishedMediaTests.cs | 25 ++-- .../Routing/NiceUrlProviderTests.cs | 4 +- .../NiceUrlsProviderWithDomainsTests.cs | 3 +- src/Umbraco.Tests/Routing/RoutesCacheTests.cs | 9 +- .../Routing/SiteDomainHelperTests.cs | 63 ++++----- .../Routing/UrlsWithNestedDomains.cs | 3 +- .../Security/BackOfficeCookieManagerTests.cs | 9 +- ...RenderIndexActionSelectorAttributeTests.cs | 17 +-- .../Web/Mvc/SurfaceControllerTests.cs | 21 +-- .../Web/Mvc/UmbracoViewPageTests.cs | 41 +++--- .../Web/WebExtensionMethodTests.cs | 17 +-- src/Umbraco.Web/Macros/MacroModel.cs | 30 +++++ src/Umbraco.Web/Macros/MacroRenderer.cs | 4 +- .../Macros/UserControlMacroEngine.cs | 2 +- src/Umbraco.Web/UmbracoContext.cs | 2 +- .../businesslogic/macro/MacroProperty.cs | 47 ------- .../businesslogic/macro/MacroPropertyModel.cs | 34 ----- .../businesslogic/macro/macroPropertyType.cs | 75 ----------- src/umbraco.cms/umbraco.cms.csproj | 4 - 31 files changed, 433 insertions(+), 640 deletions(-) delete mode 100644 src/Umbraco.Core/Persistence/Repositories/ContentPreviewRepository.cs delete mode 100644 src/Umbraco.Core/Persistence/Repositories/ContentXmlRepository.cs delete mode 100644 src/umbraco.cms/businesslogic/macro/MacroPropertyModel.cs delete mode 100644 src/umbraco.cms/businesslogic/macro/macroPropertyType.cs diff --git a/src/Umbraco.Core/Models/Rdbms/ContentXmlDto.cs b/src/Umbraco.Core/Models/Rdbms/ContentXmlDto.cs index c72af43901..62420a100f 100644 --- a/src/Umbraco.Core/Models/Rdbms/ContentXmlDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/ContentXmlDto.cs @@ -1,6 +1,4 @@ -using System.Data; -using NPoco; -using Umbraco.Core.Persistence; +using NPoco; using Umbraco.Core.Persistence.DatabaseAnnotations; namespace Umbraco.Core.Models.Rdbms @@ -18,5 +16,8 @@ namespace Umbraco.Core.Models.Rdbms [Column("xml")] [SpecialDbType(SpecialDbTypes.NTEXT)] public string Xml { get; set; } + + [Column("rv")] + public long Rv { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Models/Rdbms/PreviewXmlDto.cs b/src/Umbraco.Core/Models/Rdbms/PreviewXmlDto.cs index e3adb3c915..1fec47d646 100644 --- a/src/Umbraco.Core/Models/Rdbms/PreviewXmlDto.cs +++ b/src/Umbraco.Core/Models/Rdbms/PreviewXmlDto.cs @@ -1,6 +1,4 @@ -using System; -using NPoco; -using Umbraco.Core.Persistence; +using NPoco; using Umbraco.Core.Persistence.DatabaseAnnotations; namespace Umbraco.Core.Models.Rdbms @@ -11,19 +9,15 @@ namespace Umbraco.Core.Models.Rdbms internal class PreviewXmlDto { [Column("nodeId")] - [PrimaryKeyColumn(AutoIncrement = false, Name = "PK_cmsContentPreviewXml", OnColumns = "nodeId, versionId")] + [PrimaryKeyColumn(AutoIncrement = false)] [ForeignKey(typeof(ContentDto), Column = "nodeId")] public int NodeId { get; set; } - [Column("versionId")] - [ForeignKey(typeof(ContentVersionDto), Column = "VersionId")] - public Guid VersionId { get; set; } - - [Column("timestamp")] - public DateTime Timestamp { get; set; } - [Column("xml")] [SpecialDbType(SpecialDbTypes.NTEXT)] public string Xml { get; set; } + + [Column("rv")] + public long Rv { get; set; } } } \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentPreviewRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentPreviewRepository.cs deleted file mode 100644 index dfb8dc4c09..0000000000 --- a/src/Umbraco.Core/Persistence/Repositories/ContentPreviewRepository.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Xml.Linq; -using NPoco; -using Umbraco.Core.Cache; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence.Mappers; -using Umbraco.Core.Persistence.Querying; -using Umbraco.Core.Persistence.SqlSyntax; -using Umbraco.Core.Persistence.UnitOfWork; - -namespace Umbraco.Core.Persistence.Repositories -{ - /// - /// Private class to handle preview insert/update based on standard principles and units of work with transactions - /// - internal class ContentPreviewRepository : NPocoRepositoryBase> - where TContent : IContentBase - { - public ContentPreviewRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, IMappingResolver mappingResolver) - : base(work, cache, logger, mappingResolver) - { - } - - #region Not implemented (don't need to for the purposes of this repo) - protected override ContentPreviewEntity PerformGet(int id) - { - throw new NotImplementedException(); - } - - protected override IEnumerable> PerformGetAll(params int[] ids) - { - throw new NotImplementedException(); - } - - protected override IEnumerable> PerformGetByQuery(IQuery> query) - { - throw new NotImplementedException(); - } - - protected override Sql GetBaseQuery(bool isCount) - { - throw new NotImplementedException(); - } - - protected override string GetBaseWhereClause() - { - throw new NotImplementedException(); - } - - protected override IEnumerable GetDeleteClauses() - { - return new List(); - } - - protected override Guid NodeObjectTypeId - { - get { throw new NotImplementedException(); } - } - - protected override void PersistDeletedItem(ContentPreviewEntity entity) - { - throw new NotImplementedException(); - } - - //NOTE: Not implemented because all ContentPreviewEntity will always return false for having an Identity - protected override void PersistUpdatedItem(ContentPreviewEntity entity) - { - throw new NotImplementedException(); - } - - #endregion - - protected override void PersistNewItem(ContentPreviewEntity entity) - { - if (entity.Content.HasIdentity == false) - { - throw new InvalidOperationException("Cannot insert or update a preview for a content item that has no identity"); - } - - var previewPoco = new PreviewXmlDto - { - NodeId = entity.Id, - Timestamp = DateTime.Now, - VersionId = entity.Version, - Xml = entity.Xml.ToDataString() - }; - - //We need to do a special InsertOrUpdate here because we know that the PreviewXmlDto table has a composite key and thus - // a unique constraint which can be violated if 2+ threads try to execute the same insert sql at the same time. - Database.InsertOrUpdate(previewPoco, - //Since the table has a composite key, we need to specify an explit update statement - "SET xml = @Xml, timestamp = @Timestamp WHERE nodeId=@NodeId AND versionId=@VersionId", - new {NodeId = previewPoco.NodeId, VersionId = previewPoco.VersionId, Xml = previewPoco.Xml, Timestamp = previewPoco.Timestamp}); - } - - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/ContentXmlRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ContentXmlRepository.cs deleted file mode 100644 index 65387a7892..0000000000 --- a/src/Umbraco.Core/Persistence/Repositories/ContentXmlRepository.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Xml.Linq; -using NPoco; -using Umbraco.Core.Cache; -using Umbraco.Core.Logging; -using Umbraco.Core.Models; -using Umbraco.Core.Models.Rdbms; -using Umbraco.Core.Persistence.Mappers; -using Umbraco.Core.Persistence.Querying; -using Umbraco.Core.Persistence.SqlSyntax; -using Umbraco.Core.Persistence.UnitOfWork; - -namespace Umbraco.Core.Persistence.Repositories -{ - /// - /// Internal class to handle content/published xml insert/update based on standard principles and units of work with transactions - /// - internal class ContentXmlRepository : NPocoRepositoryBase> - where TContent : IContentBase - { - public ContentXmlRepository(IDatabaseUnitOfWork work, CacheHelper cache, ILogger logger, IMappingResolver mappingResolver) - : base(work, cache, logger, mappingResolver) - { - } - - #region Not implemented (don't need to for the purposes of this repo) - protected override ContentXmlEntity PerformGet(int id) - { - throw new NotImplementedException(); - } - - protected override IEnumerable> PerformGetAll(params int[] ids) - { - throw new NotImplementedException(); - } - - protected override IEnumerable> PerformGetByQuery(IQuery> query) - { - throw new NotImplementedException(); - } - - protected override Sql GetBaseQuery(bool isCount) - { - throw new NotImplementedException(); - } - - protected override string GetBaseWhereClause() - { - throw new NotImplementedException(); - } - - protected override IEnumerable GetDeleteClauses() - { - return new List(); - } - - protected override Guid NodeObjectTypeId - { - get { throw new NotImplementedException(); } - } - - //NOTE: Not implemented because all ContentXmlEntity will always return false for having an Identity - protected override void PersistUpdatedItem(ContentXmlEntity entity) - { - throw new NotImplementedException(); - } - - #endregion - - protected override void PersistDeletedItem(ContentXmlEntity entity) - { - //Remove 'published' xml from the cmsContentXml table for the unpublished content - Database.Delete("WHERE nodeId = @Id", new { Id = entity.Id }); - } - - protected override void PersistNewItem(ContentXmlEntity entity) - { - if (entity.Content.HasIdentity == false) - { - throw new InvalidOperationException("Cannot insert or update an xml entry for a content item that has no identity"); - } - - var poco = new ContentXmlDto - { - NodeId = entity.Id, - Xml = entity.Xml.ToDataString() - }; - - //We need to do a special InsertOrUpdate here because we know that the ContentXmlDto table has a 1:1 relation - // with the content table and a record may or may not exist so the - // unique constraint which can be violated if 2+ threads try to execute the same insert sql at the same time. - Database.InsertOrUpdate(poco); - - } - - } -} \ No newline at end of file diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 5212bab02a..6fb47bb8d1 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -708,8 +708,6 @@ - - diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index 26fadd5d7c..f8ffcb34b0 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -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(); + facadeService.Setup(x => x.CreateFacade(It.IsAny())).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(), + null); _cache = _umbracoContext.ContentCache; } - protected override void FreezeResolution() { PublishedContentModelFactoryResolver.Current = new PublishedContentModelFactoryResolver(); diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs index 89de783c69..0d15d58aa5 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedMediaCacheTests.cs @@ -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(); 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(), - (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(), + // 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; } diff --git a/src/Umbraco.Tests/CoreXml/NavigableNavigatorTests.cs b/src/Umbraco.Tests/CoreXml/NavigableNavigatorTests.cs index f5175b2476..69a0b35818 100644 --- a/src/Umbraco.Tests/CoreXml/NavigableNavigatorTests.cs +++ b/src/Umbraco.Tests/CoreXml/NavigableNavigatorTests.cs @@ -4,20 +4,18 @@ using System.Globalization; using System.IO; using System.Linq; using System.Net; -using System.Text; using System.Xml; using System.Xml.XPath; using System.Xml.Xsl; -using umbraco; -using Umbraco.Core; using Umbraco.Core.Xml; using Umbraco.Core.Xml.XPath; using NUnit.Framework; +using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.CoreXml { [TestFixture] - public class NavigableNavigatorTests + public class NavigableNavigatorTests : BaseUmbracoConfigurationTest { [Test] public void NewNavigatorIsAtRoot() @@ -556,15 +554,25 @@ namespace Umbraco.Tests.CoreXml Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position); Assert.IsFalse(nav.MoveToParent()); + // move to /root + Assert.IsTrue(nav.MoveToId("-1")); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(-1, (nav.UnderlyingObject as TestContent).Id); + + // move down + Assert.IsTrue(nav.MoveToFirstChild()); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id); + // get lost Assert.IsFalse(nav.MoveToId("666")); } [Test] - public void RootedNavigator() + public void RootedNavigator1() { var source = new TestSource5(); - var nav = new NavigableNavigator(source, source.Get(1)); + var nav = new NavigableNavigator(source, rootId: 1); // go to (/root) /1 Assert.IsTrue(nav.MoveToFirstChild()); @@ -594,6 +602,82 @@ namespace Umbraco.Tests.CoreXml Assert.IsFalse(nav.MoveToId("2")); } + [Test] + public void RootedNavigator2() + { + var source = new TestSource5(); + var nav = new NavigableNavigator(source, rootId: 3); + + // go to (/root/1) /3 + Assert.IsTrue(nav.MoveToFirstChild()); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(3, (nav.UnderlyingObject as TestContent).Id); + + // go to (/root/1) + Assert.IsTrue(nav.MoveToParent()); + Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position); + Assert.IsFalse(nav.MoveToParent()); + + // can't go there + Assert.IsFalse(nav.MoveToId("1")); + } + + [Test] + public void RootedMaxDepthNavigator() + { + var source = new TestSource5(); + var nav = new NavigableNavigator(source, rootId: 1, maxDepth: 0); + + // go to (/root) /1 + Assert.IsTrue(nav.MoveToFirstChild()); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id); + + // go to (/root) + Assert.IsTrue(nav.MoveToParent()); + Assert.AreEqual(NavigableNavigator.StatePosition.Root, nav.InternalState.Position); + Assert.IsFalse(nav.MoveToParent()); + + // go to (/root) /1 + Assert.IsTrue(nav.MoveToId("1")); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id); + + // can't go there + Assert.IsFalse(nav.MoveToId("-1")); + Assert.IsFalse(nav.MoveToId("3")); + } + + [Test] + public void MaxDepthNavigator() + { + var source = new TestSource5(); + var nav = new NavigableNavigator(source, maxDepth: 1); + + // go to /root + Assert.IsTrue(nav.MoveToFirstChild()); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(-1, (nav.UnderlyingObject as TestContent).Id); + + // go to /root/1 + Assert.IsTrue(nav.MoveToFirstChild()); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id); + Assert.IsTrue(nav.MoveToId("1")); + Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + Assert.AreEqual(1, (nav.UnderlyingObject as TestContent).Id); + + // go to /root/1/prop1 + Assert.IsTrue(nav.MoveToFirstChild()); + // go to /root/1/prop2 + Assert.IsTrue(nav.MoveToNext()); + // can't go to /root/1/3 + Assert.IsFalse(nav.MoveToNext()); + Assert.IsFalse(nav.MoveToId("3")); + //Assert.AreEqual(NavigableNavigator.StatePosition.Element, nav.InternalState.Position); + //Assert.AreEqual(3, (nav.UnderlyingObject as TestContent).Id); + } + [TestCase(true, true)] [TestCase(true, false)] [TestCase(false, true)] @@ -1002,7 +1086,25 @@ namespace Umbraco.Tests.CoreXml Root = new TestRootContent(type).WithChildren(1); } } - + + class TestSource3 : TestSourceBase + { + public TestSource3() + { + LastAttributeIndex = 1; + + var prop1 = new TestPropertyType("prop1"); + var prop2 = new TestPropertyType("prop2"); + var prop3 = new TestPropertyType("prop3"); + var type = new TestRootContentType(this, prop1, prop2); + var type1 = type.CreateType("type1", prop3); + + Content[1] = new TestContent(type1, 1, 1).WithValues("1:p1", "1:p2", "1:p3").WithChildren(2); + Content[2] = new TestContent(type1, 2, 1).WithValues("2:p1", "2:p2", "2:p3"); + + Root = new TestRootContent(type).WithChildren(1); + } + } class TestSource4 : TestSourceBase { diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index abd59ad587..3b8cf62d01 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -10,10 +10,10 @@ using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Core.Profiling; using umbraco; -using umbraco.cms.businesslogic.macro; using Umbraco.Core.Configuration; using Umbraco.Core.Models; using Umbraco.Tests.TestHelpers; +using Umbraco.Web.Macros; using File = System.IO.File; using Macro = umbraco.cms.businesslogic.macro.Macro; @@ -65,10 +65,15 @@ namespace Umbraco.Tests.Macros public void SetUserControlProperty(string val, string macroPropName, Type convertTo) { var ctrl = new UserControlTest(); - var macroModel = new MacroModel("test", "test", "", "", "~/usercontrols/menu.ascx", 0, false, false); + var macroModel = new MacroModel + { + Name = "test", + Alias = "test", + ScriptName = "~/usercontrols/menu.ascx" + }; macroModel.Properties.Add(new MacroPropertyModel(macroPropName, val)); - macro.UpdateControlProperties(ctrl, macroModel); + UserControlMacroEngine.UpdateControlProperties(ctrl, macroModel); var ctrlType = ctrl.GetType(); var prop = ctrlType.GetProperty(macroPropName); @@ -98,8 +103,16 @@ namespace Umbraco.Tests.Macros [TestCase("", "", "~/usercontrols/menu.ascx", "~/usercontrols/menu.ascx")] public void Get_Macro_File(string xslt, string scriptFile, string scriptType, string expectedResult) { - var model = new MacroModel("Test", "test", scriptType, xslt, scriptFile, 0, false, false); - var file = macro.GetMacroFile(model); + var model = new MacroModel + { + Name = "Test", + Alias = "test", + TypeName = scriptType, + Xslt = xslt, + ScriptName = scriptFile, + MacroType = MacroModel.FindMacroType(xslt, scriptFile, scriptType) + }; + var file = MacroRenderer.GetMacroFile(model); Assert.AreEqual(expectedResult, file); } @@ -107,45 +120,30 @@ namespace Umbraco.Tests.Macros [TestCase("PartialView", true)] [TestCase("UserControl", true)] [TestCase("Unknown", false)] - public void Macro_Is_File_Based(string macroType, bool expectedResult) + public void Macro_Is_File_Based(string macroTypeString, bool expectedNonNull) { - var mType = Enum.Parse(macroType); - var model = new MacroModel("Test", "test", "", "", "", 0, false, false); - model.MacroType = mType; //force the type - Assert.AreEqual(expectedResult, macro.MacroIsFileBased(model)); + var macroType = Enum.Parse(macroTypeString); + var model = new MacroModel + { + MacroType = macroType, + Xslt = "anything", + ScriptName = "anything", + TypeName = "anything" + }; + var filename = MacroRenderer.GetMacroFileName(model); + if (expectedNonNull) + Assert.IsNotNull(filename); + else + Assert.IsNull(filename); } - [TestCase("Xslt", true)] - [TestCase("PartialView", true)] - [TestCase("UserControl", false)] - [TestCase("Unknown", false)] - public void Can_Cache_As_String(string macroType, bool expectedResult) + //[TestCase(-5, true)] //the cache DateTime will be older than the file date + //[TestCase(5, false)] //the cache DateTime will be newer than the file date + public void Macro_Needs_Removing_Based_On_Macro_File(int minutesToNow, bool expectedNull) { - var mType = Enum.Parse(macroType); - var model = new MacroModel("Test", "test", "", "", "", 0, false, false); - model.MacroType = mType; //force the type - Assert.AreEqual(expectedResult, macro.CacheMacroAsString(model)); - } - - [TestCase(-5, true)] //the cache DateTime will be older than the file date - [TestCase(5, false)] //the cache DateTime will be newer than the file date - public void Macro_Needs_Removing_Based_On_Macro_File(int minutesToNow, bool expectedResult) - { - var now = DateTime.Now; - ApplicationContext.Current.ApplicationCache.RuntimeCache.InsertCacheItem( - "TestDate", - priority: CacheItemPriority.NotRemovable, - timeout: new TimeSpan(0, 0, 60), - getCacheItem: () => now.AddMinutes(minutesToNow)); //add a datetime value of 'now' with the minutes offset - - //now we need to update a file's date to 'now' to compare - var path = Path.Combine(TestHelpers.TestHelper.CurrentAssemblyDirectory, "temp.txt"); - File.CreateText(path).Close(); - - //needs to be file based (i.e. xslt) - var model = new MacroModel("Test", "test", "", "test.xslt", "", 0, false, false); - - Assert.AreEqual(expectedResult, macro.MacroNeedsToBeClearedFromCache(model, "TestDate", new FileInfo(path))); + // macro has been refactored, and macro.GetMacroContentFromCache() will + // take care of the macro file, if any. It requires a web environment, + // so we cannot really test this anymore. } public void Get_Macro_Cache_Identifier() diff --git a/src/Umbraco.Tests/MockTests.cs b/src/Umbraco.Tests/MockTests.cs index 5033a22f15..9b9e59ed8a 100644 --- a/src/Umbraco.Tests/MockTests.cs +++ b/src/Umbraco.Tests/MockTests.cs @@ -19,6 +19,7 @@ using Moq; using Umbraco.Core.Cache; using Umbraco.Tests.TestHelpers; using Umbraco.Web; +using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; @@ -101,8 +102,8 @@ namespace Umbraco.Tests new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -119,8 +120,8 @@ namespace Umbraco.Tests new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -147,8 +148,8 @@ namespace Umbraco.Tests new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs index facd380fc8..84bd449cbf 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentMoreTests.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Collections.ObjectModel; using System.Web.Routing; +using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; @@ -11,8 +12,11 @@ using Umbraco.Core.PropertyEditors; using Umbraco.Web; using Umbraco.Tests.TestHelpers; using umbraco.BusinessLogic; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Plugins; +using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.XmlPublishedCache; +using Umbraco.Web.Routing; using Umbraco.Web.Security; namespace Umbraco.Tests.PublishedContent @@ -59,12 +63,16 @@ namespace Umbraco.Tests.PublishedContent var caches = CreatePublishedContent(); + var facadeService = new Mock(); + var httpContext = GetHttpContextFactory("http://umbraco.local/", routeData).HttpContext; - var ctx = new UmbracoContext( - httpContext, - ApplicationContext, - caches, - new WebSecurity(httpContext, ApplicationContext)); + var ctx = UmbracoContext.CreateContext( + httpContext, ApplicationContext, + facadeService.Object, + new WebSecurity(httpContext, ApplicationContext), + Mock.Of(), + Enumerable.Empty(), + null); UmbracoContext.Current = ctx; } @@ -225,10 +233,10 @@ namespace Umbraco.Tests.PublishedContent Assert.AreEqual(2, result[1].Id); } - static SolidPublishedCaches CreatePublishedContent() + static SolidFacade CreatePublishedContent() { - var caches = new SolidPublishedCaches(); - var cache = caches.ContentCache; + var caches = new SolidFacade(); + var cache = caches.InnerContentCache; var props = new[] { diff --git a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs index 82115d670e..3daaba53b3 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedContentTestElements.cs @@ -11,26 +11,43 @@ using Umbraco.Web.PublishedCache; namespace Umbraco.Tests.PublishedContent { - class SolidPublishedCaches : IPublishedCaches + class SolidFacade : IFacade { - public readonly SolidPublishedContentCache ContentCache = new SolidPublishedContentCache(); - public readonly SolidPublishedMediaCache MediaCache = new SolidPublishedMediaCache(); + public readonly SolidPublishedContentCache InnerContentCache = new SolidPublishedContentCache(); + public readonly SolidPublishedContentCache InnerMediaCache = new SolidPublishedContentCache(); - public ContextualPublishedContentCache CreateContextualContentCache(UmbracoContext context) + public IPublishedContentCache ContentCache { - return new ContextualPublishedContentCache(ContentCache, context); + get { return InnerContentCache; } } - public ContextualPublishedMediaCache CreateContextualMediaCache(UmbracoContext context) + public IPublishedMediaCache MediaCache { - return new ContextualPublishedMediaCache(MediaCache, context); + get { return InnerMediaCache; } } + + public IPublishedMemberCache MemberCache + { + get { return null; } + } + + public IDomainCache DomainCache + { + get { return null; } + } + + public void Resync() + { } } - class SolidPublishedContentCache : IPublishedContentCache + class SolidPublishedContentCache : PublishedCacheBase, IPublishedContentCache, IPublishedMediaCache { private readonly Dictionary _content = new Dictionary(); + public SolidPublishedContentCache() + : base(false) + { } + public void Add(SolidPublishedContent content) { _content[content.Id] = content.CreateModel(); @@ -41,62 +58,72 @@ namespace Umbraco.Tests.PublishedContent _content.Clear(); } - public void ContentHasChanged(UmbracoContext umbracoContext) + public IPublishedContent GetByRoute(bool preview, string route, bool? hideTopLevelNode = null) { throw new NotImplementedException(); } - public IPublishedContent GetByRoute(UmbracoContext umbracoContext, bool preview, string route, bool? hideTopLevelNode = null) + public IPublishedContent GetByRoute(string route, bool? hideTopLevelNode = null) { throw new NotImplementedException(); } - public string GetRouteById(UmbracoContext umbracoContext, bool preview, int contentId) + public string GetRouteById(bool preview, int contentId) { throw new NotImplementedException(); } - public IPublishedContent GetById(UmbracoContext umbracoContext, bool preview, int contentId) + public string GetRouteById(int contentId) + { + throw new NotImplementedException(); + } + + public override IPublishedContent GetById(bool preview, int contentId) { return _content.ContainsKey(contentId) ? _content[contentId] : null; } - public IEnumerable GetAtRoot(UmbracoContext umbracoContext, bool preview) + public override bool HasById(bool preview, int contentId) + { + return _content.ContainsKey(contentId); + } + + public override IEnumerable GetAtRoot(bool preview) { return _content.Values.Where(x => x.Parent == null); } - public IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, Core.Xml.XPathVariable[] vars) + public override IPublishedContent GetSingleByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars) { throw new NotImplementedException(); } - public IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) + public override IPublishedContent GetSingleByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) { throw new NotImplementedException(); } - public IEnumerable GetByXPath(UmbracoContext umbracoContext, bool preview, string xpath, Core.Xml.XPathVariable[] vars) + public override IEnumerable GetByXPath(bool preview, string xpath, Core.Xml.XPathVariable[] vars) { throw new NotImplementedException(); } - public IEnumerable GetByXPath(UmbracoContext umbracoContext, bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) + public override IEnumerable GetByXPath(bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) { throw new NotImplementedException(); } - public System.Xml.XPath.XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext, bool preview) + public override System.Xml.XPath.XPathNavigator CreateNavigator(bool preview) { throw new NotImplementedException(); } - public bool XPathNavigatorIsNavigable + public override System.Xml.XPath.XPathNavigator CreateNodeNavigator(int id, bool preview) { - get { throw new NotImplementedException(); } + throw new NotImplementedException(); } - public bool HasContent(UmbracoContext umbracoContext, bool preview) + public override bool HasContent(bool preview) { return _content.Count > 0; } @@ -105,66 +132,21 @@ namespace Umbraco.Tests.PublishedContent { throw new NotImplementedException(); } - } - class SolidPublishedMediaCache : IPublishedMediaCache - { - private readonly Dictionary _media = new Dictionary(); - - public void Add(SolidPublishedContent content) - { - _media[content.Id] = content.CreateModel(); - } - - public void Clear() - { - _media.Clear(); - } - - public IPublishedContent GetById(UmbracoContext umbracoContext, bool preview, int contentId) - { - return _media.ContainsKey(contentId) ? _media[contentId] : null; - } - - public IEnumerable GetAtRoot(UmbracoContext umbracoContext, bool preview) - { - return _media.Values.Where(x => x.Parent == null); - } - - public IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, string xpath, Core.Xml.XPathVariable[] vars) + public override PublishedContentType GetContentType(int id) { throw new NotImplementedException(); } - public IPublishedContent GetSingleByXPath(UmbracoContext umbracoContext, bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) + public override PublishedContentType GetContentType(string alias) { throw new NotImplementedException(); } - public IEnumerable GetByXPath(UmbracoContext umbracoContext, bool preview, string xpath, Core.Xml.XPathVariable[] vars) + public override IEnumerable GetByContentType(PublishedContentType contentType) { throw new NotImplementedException(); } - - public IEnumerable GetByXPath(UmbracoContext umbracoContext, bool preview, System.Xml.XPath.XPathExpression xpath, Core.Xml.XPathVariable[] vars) - { - throw new NotImplementedException(); - } - - public System.Xml.XPath.XPathNavigator GetXPathNavigator(UmbracoContext umbracoContext, bool preview) - { - throw new NotImplementedException(); - } - - public bool XPathNavigatorIsNavigable - { - get { throw new NotImplementedException(); } - } - - public bool HasContent(UmbracoContext umbracoContext, bool preview) - { - return _media.Count > 0; - } } class SolidPublishedContent : IPublishedContent @@ -226,8 +208,8 @@ namespace Umbraco.Tests.PublishedContent public int ParentId { get; set; } public IEnumerable ChildIds { get; set; } - public IPublishedContent Parent { get { return UmbracoContext.Current.ContentCache.GetById(ParentId); } } - public IEnumerable Children { get { return ChildIds.Select(id => UmbracoContext.Current.ContentCache.GetById(id)); } } + public IPublishedContent Parent { get; set; } + public IEnumerable Children { get; set; } #endregion diff --git a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs index 0832cd3ad0..ccdb7b19af 100644 --- a/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs +++ b/src/Umbraco.Tests/PublishedContent/PublishedMediaTests.cs @@ -13,8 +13,10 @@ using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.XmlPublishedCache; using System.Linq; +using System.Xml; using Examine.Session; using LightInject; +using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Core.Strings; using UmbracoExamine; @@ -58,10 +60,9 @@ namespace Umbraco.Tests.PublishedContent /// /// /// - internal static IPublishedContent GetNode(int id, UmbracoContext umbracoContext) + internal IPublishedContent GetNode(int id, UmbracoContext umbracoContext) { - var ctx = umbracoContext; - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application), ctx); + var cache = new PublishedMediaCache(new XmlStore((XmlDocument)null), umbracoContext.Application.Services.MediaService, new StaticCacheProvider(), ContentTypesCache); var doc = cache.GetById(id); Assert.IsNotNull(doc); return doc; @@ -115,7 +116,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx); + var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(1111); @@ -147,7 +148,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx); + var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //ensure it is found var publishedMedia = cache.GetById(3113); @@ -191,7 +192,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx); + var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(1111); @@ -216,7 +217,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx); + var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(1111); @@ -241,7 +242,7 @@ namespace Umbraco.Tests.PublishedContent var searcher = indexer.GetSearcher(); var ctx = GetUmbracoContext("/test", 1234); - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx); + var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(1111); @@ -266,7 +267,7 @@ namespace Umbraco.Tests.PublishedContent var ctx = GetUmbracoContext("/test", 1234); var searcher = indexer.GetSearcher(); - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx); + var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(3113); @@ -288,7 +289,7 @@ namespace Umbraco.Tests.PublishedContent var ctx = GetUmbracoContext("/test", 1234); var searcher = indexer.GetSearcher(); - var cache = new ContextualPublishedMediaCache(new PublishedMediaCache(ctx.Application, searcher, indexer), ctx); + var cache = new PublishedMediaCache(ServiceContext.MediaService, searcher, indexer, new StaticCacheProvider(), ContentTypesCache); //we are using the media.xml media to test the examine results implementation, see the media.xml file in the ExamineHelpers namespace var publishedMedia = cache.GetById(3113); @@ -461,7 +462,7 @@ namespace Umbraco.Tests.PublishedContent "); var node = xml.DescendantsAndSelf("Image").Single(x => (int)x.Attribute("id") == nodeId); - var publishedMedia = new PublishedMediaCache(ApplicationContext); + var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache); var nav = node.CreateNavigator(); @@ -481,7 +482,7 @@ namespace Umbraco.Tests.PublishedContent var errorXml = new XElement("error", string.Format("No media is maching '{0}'", 1234)); var nav = errorXml.CreateNavigator(); - var publishedMedia = new PublishedMediaCache(ApplicationContext); + var publishedMedia = new PublishedMediaCache(new XmlStore((XmlDocument)null), ServiceContext.MediaService, new StaticCacheProvider(), ContentTypesCache); var converted = publishedMedia.ConvertFromXPathNodeIterator(nav.Select("/"), 1234); Assert.IsNull(converted); diff --git a/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs b/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs index 075205ef5c..bd11dedc6f 100644 --- a/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs +++ b/src/Umbraco.Tests/Routing/NiceUrlProviderTests.cs @@ -4,6 +4,7 @@ using Moq; using NUnit.Framework; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Tests.TestHelpers; +using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; @@ -16,7 +17,6 @@ namespace Umbraco.Tests.Routing protected override void FreezeResolution() { SiteDomainHelperResolver.Current = new SiteDomainHelperResolver(new SiteDomainHelper()); - base.FreezeResolution(); } @@ -69,7 +69,7 @@ namespace Umbraco.Tests.Routing Assert.AreEqual(randomSample.Value, result); } - var cache = routingContext.UmbracoContext.ContentCache.InnerCache as PublishedContentCache; + var cache = routingContext.UmbracoContext.ContentCache as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); var cachedRoutes = cache.RoutesCache.GetCachedRoutes(); Assert.AreEqual(8, cachedRoutes.Count); diff --git a/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs b/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs index 8cc975954b..f579d7b87f 100644 --- a/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs +++ b/src/Umbraco.Tests/Routing/NiceUrlsProviderWithDomainsTests.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models; using Umbraco.Tests.TestHelpers; +using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; using umbraco.cms.businesslogic.web; @@ -300,7 +301,7 @@ namespace Umbraco.Tests.Routing ignore = routingContext.UrlProvider.GetUrl(100111, new Uri("http://domain2.com"), false); ignore = routingContext.UrlProvider.GetUrl(1002, new Uri("http://domain2.com"), false); - var cache = routingContext.UmbracoContext.ContentCache.InnerCache as PublishedContentCache; + var cache = routingContext.UmbracoContext.ContentCache as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); var cachedRoutes = cache.RoutesCache.GetCachedRoutes(); Assert.AreEqual(7, cachedRoutes.Count); diff --git a/src/Umbraco.Tests/Routing/RoutesCacheTests.cs b/src/Umbraco.Tests/Routing/RoutesCacheTests.cs index 80bdcb3b7f..a46ffdb584 100644 --- a/src/Umbraco.Tests/Routing/RoutesCacheTests.cs +++ b/src/Umbraco.Tests/Routing/RoutesCacheTests.cs @@ -18,13 +18,14 @@ namespace Umbraco.Tests.Routing { //var routingContext = GetRoutingContext("/test", 1111); var umbracoContext = GetUmbracoContext("/test", 0); - var cache = umbracoContext.ContentCache.InnerCache as PublishedContentCache; + var cache = umbracoContext.Facade.ContentCache as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); - PublishedContentCache.UnitTesting = false; // else does not write to routes cache - Assert.IsFalse(PublishedContentCache.UnitTesting); + // fixme not sure? + //PublishedContentCache.UnitTesting = false; // else does not write to routes cache + //Assert.IsFalse(PublishedContentCache.UnitTesting); - var z = cache.GetByRoute(umbracoContext, false, "/home/sub1"); + var z = cache.GetByRoute(false, "/home/sub1"); Assert.IsNotNull(z); Assert.AreEqual(1173, z.Id); diff --git a/src/Umbraco.Tests/Routing/SiteDomainHelperTests.cs b/src/Umbraco.Tests/Routing/SiteDomainHelperTests.cs index 481325524f..9553e5b484 100644 --- a/src/Umbraco.Tests/Routing/SiteDomainHelperTests.cs +++ b/src/Umbraco.Tests/Routing/SiteDomainHelperTests.cs @@ -1,13 +1,8 @@ using System; -using System.Collections.Generic; +using System.Globalization; using System.Linq; -using System.Text; using NUnit.Framework; -using Umbraco.Core.Models; -using Umbraco.Tests.TestHelpers; using Umbraco.Web.Routing; -using umbraco.cms.businesslogic.web; -using System.Reflection; namespace Umbraco.Tests.Routing { @@ -182,8 +177,8 @@ namespace Umbraco.Tests.Routing var current = new Uri("http://domain1.com/foo/bar"); var output = helper.MapDomain(current, new[] { - new DomainAndUri(new UmbracoDomain("domain1.com"), Uri.UriSchemeHttp), - new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp), + new DomainAndUri(new Domain(1, "domain1.com", -1, CultureInfo.CurrentCulture, false), current), + new DomainAndUri(new Domain(1, "domain2.com", -1, CultureInfo.CurrentCulture, false), current), }).Uri.ToString(); Assert.AreEqual("http://domain1.com/", output); @@ -193,8 +188,8 @@ namespace Umbraco.Tests.Routing current = new Uri("http://domain1.com/foo/bar"); output = helper.MapDomain(current, new[] { - new DomainAndUri(new UmbracoDomain("domain1.net"), Uri.UriSchemeHttp), - new DomainAndUri(new UmbracoDomain("domain2.net"), Uri.UriSchemeHttp) + new DomainAndUri(new Domain(1, "domain1.net", -1, CultureInfo.CurrentCulture, false), current), + new DomainAndUri(new Domain(1, "domain2.net", -1, CultureInfo.CurrentCulture, false), current) }).Uri.ToString(); Assert.AreEqual("http://domain1.net/", output); @@ -205,8 +200,8 @@ namespace Umbraco.Tests.Routing current = new Uri("http://domain1.com/foo/bar"); output = helper.MapDomain(current, new[] { - new DomainAndUri(new UmbracoDomain("domain2.net"), Uri.UriSchemeHttp), - new DomainAndUri(new UmbracoDomain("domain1.net"), Uri.UriSchemeHttp) + new DomainAndUri(new Domain(1, "domain2.net", -1, CultureInfo.CurrentCulture, false), current), + new DomainAndUri(new Domain(1, "domain1.net", -1, CultureInfo.CurrentCulture, false), current) }).Uri.ToString(); Assert.AreEqual("http://domain1.net/", output); } @@ -232,11 +227,11 @@ namespace Umbraco.Tests.Routing var current = new Uri("http://domain1.com/foo/bar"); var output = helper.MapDomains(current, new[] { - new DomainAndUri(new UmbracoDomain("domain1.com"), Uri.UriSchemeHttp), // no: current + what MapDomain would pick - new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp), // yes: same site (though bogus setup) + new DomainAndUri(new Domain(1, "domain1.com", -1, CultureInfo.CurrentCulture, false), current), // no: current + what MapDomain would pick + new DomainAndUri(new Domain(1, "domain2.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain3.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain4.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain1.org", -1, CultureInfo.CurrentCulture, false), current), // yes: same site (though bogus setup) }, true).ToArray(); Assert.AreEqual(1, output.Count()); @@ -247,11 +242,11 @@ namespace Umbraco.Tests.Routing current = new Uri("http://domain1.com/foo/bar"); output = helper.MapDomains(current, new[] { - new DomainAndUri(new UmbracoDomain("domain1.net"), Uri.UriSchemeHttp), // no: what MapDomain would pick - new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp), // yes: same site (though bogus setup) + new DomainAndUri(new Domain(1, "domain1.net", -1, CultureInfo.CurrentCulture, false), current), // no: what MapDomain would pick + new DomainAndUri(new Domain(1, "domain2.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain3.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain4.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain1.org", -1, CultureInfo.CurrentCulture, false), current), // yes: same site (though bogus setup) }, true).ToArray(); Assert.AreEqual(1, output.Count()); @@ -265,12 +260,12 @@ namespace Umbraco.Tests.Routing current = new Uri("http://domain1.com/foo/bar"); output = helper.MapDomains(current, new[] { - new DomainAndUri(new UmbracoDomain("domain1.com"), Uri.UriSchemeHttp), // no: current + what MapDomain would pick - new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp), // yes: bound site - new DomainAndUri(new UmbracoDomain("domain3.org"), Uri.UriSchemeHttp), // yes: bound site - new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp), // yes: same site (though bogus setup) + new DomainAndUri(new Domain(1, "domain1.com", -1, CultureInfo.CurrentCulture, false), current), // no: current + what MapDomain would pick + new DomainAndUri(new Domain(1, "domain2.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain3.com", -1, CultureInfo.CurrentCulture, false), current), // yes: bound site + new DomainAndUri(new Domain(1, "domain3.org", -1, CultureInfo.CurrentCulture, false), current), // yes: bound site + new DomainAndUri(new Domain(1, "domain4.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain1.org", -1, CultureInfo.CurrentCulture, false), current), // yes: same site (though bogus setup) }, true).ToArray(); Assert.AreEqual(3, output.Count()); @@ -283,12 +278,12 @@ namespace Umbraco.Tests.Routing current = new Uri("http://domain1.com/foo/bar"); output = helper.MapDomains(current, new[] { - new DomainAndUri(new UmbracoDomain("domain1.net"), Uri.UriSchemeHttp), // no: what MapDomain would pick - new DomainAndUri(new UmbracoDomain("domain2.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain3.com"), Uri.UriSchemeHttp), // yes: bound site - new DomainAndUri(new UmbracoDomain("domain3.org"), Uri.UriSchemeHttp), // yes: bound site - new DomainAndUri(new UmbracoDomain("domain4.com"), Uri.UriSchemeHttp), // no: not same site - new DomainAndUri(new UmbracoDomain("domain1.org"), Uri.UriSchemeHttp), // yes: same site (though bogus setup) + new DomainAndUri(new Domain(1, "domain1.net", -1, CultureInfo.CurrentCulture, false), current), // no: what MapDomain would pick + new DomainAndUri(new Domain(1, "domain2.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain3.com", -1, CultureInfo.CurrentCulture, false), current), // yes: bound site + new DomainAndUri(new Domain(1, "domain3.org", -1, CultureInfo.CurrentCulture, false), current), // yes: bound site + new DomainAndUri(new Domain(1, "domain4.com", -1, CultureInfo.CurrentCulture, false), current), // no: not same site + new DomainAndUri(new Domain(1, "domain1.org", -1, CultureInfo.CurrentCulture, false), current), // yes: same site (though bogus setup) }, true).ToArray(); Assert.AreEqual(3, output.Count()); diff --git a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs index 2eebc5a6e8..93a257db63 100644 --- a/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs +++ b/src/Umbraco.Tests/Routing/UrlsWithNestedDomains.cs @@ -7,6 +7,7 @@ using NUnit.Framework; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Models; using Umbraco.Tests.TestHelpers; +using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.XmlPublishedCache; using Umbraco.Web.Routing; using umbraco.cms.businesslogic.web; @@ -42,7 +43,7 @@ namespace Umbraco.Tests.Routing Assert.AreEqual("http://domain2.com/1001-1-1/", routingContext.UrlProvider.GetUrl(100111, true)); // check that the proper route has been cached - var cache = routingContext.UmbracoContext.ContentCache.InnerCache as PublishedContentCache; + var cache = routingContext.UmbracoContext.ContentCache as PublishedContentCache; if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the Xml one is supported."); var cachedRoutes = cache.RoutesCache.GetCachedRoutes(); Assert.AreEqual("10011/1001-1-1", cachedRoutes[100111]); diff --git a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs index dba759cf49..5548bfc2ab 100644 --- a/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs +++ b/src/Umbraco.Tests/Security/BackOfficeCookieManagerTests.cs @@ -14,6 +14,7 @@ using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Profiling; using Umbraco.Tests.TestHelpers; using Umbraco.Web; +using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; using Umbraco.Web.Security.Identity; @@ -39,8 +40,8 @@ namespace Umbraco.Tests.Security new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.CreateContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new WebSecurity(Mock.Of(), appCtx), Mock.Of(), new List(), false); @@ -64,8 +65,8 @@ namespace Umbraco.Tests.Security new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.CreateContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new WebSecurity(Mock.Of(), appCtx), Mock.Of(), new List(), false); diff --git a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs index d244ea476f..11f67be59d 100644 --- a/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/RenderIndexActionSelectorAttributeTests.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Profiling; using Umbraco.Web; using Umbraco.Web.Models; using Umbraco.Web.Mvc; +using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; @@ -45,8 +46,8 @@ namespace Umbraco.Tests.Web.Mvc CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -68,8 +69,8 @@ namespace Umbraco.Tests.Web.Mvc CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - Mock.Of(), - appCtx, + Mock.Of(),appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -91,8 +92,8 @@ namespace Umbraco.Tests.Web.Mvc CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - Mock.Of(), - appCtx, + Mock.Of(),appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -114,8 +115,8 @@ namespace Umbraco.Tests.Web.Mvc CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - Mock.Of(), - appCtx, + Mock.Of(),appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs index d27ff2118a..4efb12250a 100644 --- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Services; using Umbraco.Tests.TestHelpers; using Umbraco.Web; using Umbraco.Web.Mvc; +using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; @@ -35,8 +36,8 @@ namespace Umbraco.Tests.Web.Mvc new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - new Mock().Object, - appCtx, + new Mock().Object, appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -59,8 +60,8 @@ namespace Umbraco.Tests.Web.Mvc ApplicationContext.EnsureContext(appCtx, true); var umbCtx = UmbracoContext.EnsureContext( - new Mock().Object, - appCtx, + new Mock().Object, appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -83,8 +84,8 @@ namespace Umbraco.Tests.Web.Mvc new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - new Mock().Object, - appCtx, + new Mock().Object, appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(), Enumerable.Empty(), @@ -103,8 +104,8 @@ namespace Umbraco.Tests.Web.Mvc new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.EnsureContext( - new Mock().Object, - appCtx, + new Mock().Object, appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(section => section.WebRouting == Mock.Of(routingSection => routingSection.UrlProviderMode == "AutoLegacy")), Enumerable.Empty(), @@ -141,8 +142,8 @@ namespace Umbraco.Tests.Web.Mvc var webRoutingSettings = Mock.Of(section => section.UrlProviderMode == "AutoLegacy"); var umbCtx = UmbracoContext.EnsureContext( - new Mock().Object, - appCtx, + new Mock().Object, appCtx, + Mock.Of(), new Mock(null, null).Object, Mock.Of(section => section.WebRouting == webRoutingSettings), Enumerable.Empty(), diff --git a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs index 5d9a9ed69c..406001adb4 100644 --- a/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Web/Mvc/UmbracoViewPageTests.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.Linq; using System.Web.Mvc; using System.Web.Routing; +using LightInject; using Moq; using NUnit.Framework; using umbraco.BusinessLogic; @@ -31,8 +32,18 @@ using Umbraco.Web.Security; namespace Umbraco.Tests.Web.Mvc { [TestFixture] - public class UmbracoViewPageTests + public class UmbracoViewPageTests : BaseUmbracoConfigurationTest { + private FacadeService _service; + + [TearDown] + public override void TearDown() + { + if (_service == null) return; + _service.Dispose(); + _service = null; + } + #region RenderModel To ... [Test] @@ -414,18 +425,6 @@ namespace Umbraco.Tests.Web.Mvc protected UmbracoContext GetUmbracoContext(ILogger logger, IUmbracoSettingsSection umbracoSettings, string url, int templateId, RouteData routeData = null, bool setSingleton = false) { - var cache = new PublishedContentCache(); - - //cache.GetXmlDelegate = (context, preview) => - //{ - // var doc = new XmlDocument(); - // doc.LoadXml(GetXmlContent(templateId)); - // return doc; - //}; - - //PublishedContentCache.UnitTesting = true; - - // ApplicationContext.Current = new ApplicationContext(false) { IsReady = true }; var svcCtx = GetServiceContext(); var databaseFactory = TestObjects.GetIDatabaseFactoryMock(); @@ -436,12 +435,18 @@ namespace Umbraco.Tests.Web.Mvc CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(logger, Mock.Of())) { IsReady = true }; + var cache = new NullCacheProvider(); + var provider = new NPocoUnitOfWorkProvider(databaseFactory, new RepositoryFactory(Mock.Of())); + _service = new FacadeService(svcCtx, provider, cache, true, false); // no events + var http = GetHttpContextFactory(url, routeData).HttpContext; - var ctx = new UmbracoContext( - GetHttpContextFactory(url, routeData).HttpContext, - appCtx, - new PublishedCaches(cache, new PublishedMediaCache(appCtx)), - new WebSecurity(http, appCtx)); + + var ctx = UmbracoContext.CreateContext( + GetHttpContextFactory(url, routeData).HttpContext, appCtx, + _service, + new WebSecurity(http, appCtx), + Mock.Of(), + Enumerable.Empty()); //if (setSingleton) //{ diff --git a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs index 38b6e3a13a..dadf0c0d9a 100644 --- a/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs +++ b/src/Umbraco.Tests/Web/WebExtensionMethodTests.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Logging; using Umbraco.Core.Profiling; using Umbraco.Web; using Umbraco.Web.Mvc; +using Umbraco.Web.PublishedCache; using Umbraco.Web.Routing; using Umbraco.Web.Security; @@ -32,8 +33,8 @@ namespace Umbraco.Tests.Web CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.CreateContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new WebSecurity(Mock.Of(), appCtx), Mock.Of(), new List(), @@ -58,8 +59,8 @@ namespace Umbraco.Tests.Web CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.CreateContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new WebSecurity(Mock.Of(), appCtx), Mock.Of(), new List(), @@ -80,8 +81,8 @@ namespace Umbraco.Tests.Web CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.CreateContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new WebSecurity(Mock.Of(), appCtx), Mock.Of(), new List(), @@ -110,8 +111,8 @@ namespace Umbraco.Tests.Web CacheHelper.CreateDisabledCacheHelper(), new ProfilingLogger(Mock.Of(), Mock.Of())); var umbCtx = UmbracoContext.CreateContext( - Mock.Of(), - appCtx, + Mock.Of(), appCtx, + Mock.Of(), new WebSecurity(Mock.Of(), appCtx), Mock.Of(), new List(), diff --git a/src/Umbraco.Web/Macros/MacroModel.cs b/src/Umbraco.Web/Macros/MacroModel.cs index 8203800b8e..ae1b928e2c 100644 --- a/src/Umbraco.Web/Macros/MacroModel.cs +++ b/src/Umbraco.Web/Macros/MacroModel.cs @@ -2,8 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; using umbraco.cms.businesslogic.macro; +using Umbraco.Core; +using Umbraco.Core.IO; using Umbraco.Core.Models; using Macro = Umbraco.Core.Models.Macro; @@ -71,5 +74,32 @@ namespace Umbraco.Web.Macros // can convert enums MacroType = Core.Services.MacroService.GetMacroType(macro); } + + // fixme what's the point? used only in tests! + internal static MacroTypes FindMacroType(string xslt, string scriptFile, string scriptType /*, string scriptAssembly*/) + { + if (string.IsNullOrEmpty(xslt) == false) + return MacroTypes.Xslt; + + if (string.IsNullOrEmpty(scriptFile) == false) + { + //we need to check if the file path saved is a virtual path starting with ~/Views/MacroPartials, if so then this is + //a partial view macro, not a script macro + //we also check if the file exists in ~/App_Plugins/[Packagename]/Views/MacroPartials, if so then it is also a partial view. + return (scriptFile.InvariantStartsWith(SystemDirectories.MvcViews + "/MacroPartials/") + || (Regex.IsMatch(scriptFile, "~/App_Plugins/.+?/Views/MacroPartials", RegexOptions.Compiled | RegexOptions.IgnoreCase))) + ? MacroTypes.PartialView + : MacroTypes.Script; + } + + if (string.IsNullOrEmpty(scriptType) == false && scriptType.InvariantContains(".ascx")) + return MacroTypes.UserControl; + + //if (string.IsNullOrEmpty(scriptType) == false && !string.IsNullOrEmpty(scriptAssembly)) + // return MacroTypes.CustomControl; + + return MacroTypes.Unknown; + } + } } diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index b435e1ed5f..16f5625988 100644 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -185,7 +185,7 @@ namespace Umbraco.Web.Macros // gets the macro source file name // null if the macro is not file-based - private static string GetMacroFileName(MacroModel model) + internal static string GetMacroFileName(MacroModel model) { string filename; @@ -218,7 +218,7 @@ namespace Umbraco.Web.Macros // gets the macro source file // null if macro is not file-based - private static FileInfo GetMacroFile(MacroModel model) + internal static FileInfo GetMacroFile(MacroModel model) { var filename = GetMacroFileName(model); if (filename == null) return null; diff --git a/src/Umbraco.Web/Macros/UserControlMacroEngine.cs b/src/Umbraco.Web/Macros/UserControlMacroEngine.cs index 38fb7d4d46..1251906239 100644 --- a/src/Umbraco.Web/Macros/UserControlMacroEngine.cs +++ b/src/Umbraco.Web/Macros/UserControlMacroEngine.cs @@ -75,7 +75,7 @@ namespace Umbraco.Web.Macros } // set the control properties according to the model properties ie parameters - private static void UpdateControlProperties(Control control, MacroModel model) + internal static void UpdateControlProperties(Control control, MacroModel model) { var type = control.GetType(); diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 62c5b067e9..70a521764c 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -104,7 +104,7 @@ namespace Umbraco.Web WebSecurity webSecurity, IUmbracoSettingsSection umbracoSettings, IEnumerable urlProviders, - bool? preview) + bool? preview = null) { if (httpContext == null) throw new ArgumentNullException(nameof(httpContext)); if (applicationContext == null) throw new ArgumentNullException(nameof(applicationContext)); diff --git a/src/umbraco.cms/businesslogic/macro/MacroProperty.cs b/src/umbraco.cms/businesslogic/macro/MacroProperty.cs index 53cc1d0120..6315460684 100644 --- a/src/umbraco.cms/businesslogic/macro/MacroProperty.cs +++ b/src/umbraco.cms/businesslogic/macro/MacroProperty.cs @@ -78,47 +78,8 @@ namespace umbraco.cms.businesslogic.macro /// The macro. public Macro Macro { get; set; } - private MacroPropertyType _type; private string _parameterEditorAlias; - /// - /// The basetype which defines which component is used in the UI for editing content - /// - [Obsolete("This is no longer used and will be removed in future versions")] - public MacroPropertyType Type - { - get - { - if (_type == null) - { - //we'll try to create one based on the resolved new parameter editors - var found = ParameterEditorResolver.Current.GetByAlias(ParameterEditorAlias); - if (found == null) - { - return null; - } - var type = new MacroPropertyType - { - Alias = ParameterEditorAlias, - Id = 0, - Assembly = found.GetType().Namespace, - //NOTE: In v6 macro parameter's stored in the database used to - // expose a CLR type but we no longer support that, instead we'll just attempt - // to convert the value to the CLR type - It's also important to note that the - // ONLY place this BaseType is ever used is to assign to the umbraco.cms.businesslogic.macro.MacroPropertyModel.CLRType - // property, which is then used when attempting to render a UserControl macro. So basically - // it is completely pointless since we already know the CLR property type of the UserControl - // property and we're just going to do the conversion anyways since it is always essentially a string. - BaseType = "String", - Type = found.GetType().Name - }; - _type = type; - } - return _type; - } - set { _type = Type; } - } - /// /// The macro parameter editor alias used to render the editor /// @@ -151,7 +112,6 @@ namespace umbraco.cms.businesslogic.macro SortOrder = (int)dr.GetByte("macroPropertySortOrder"); Alias = dr.GetString("macroPropertyAlias"); Name = dr.GetString("macroPropertyName"); - Type = null; ParameterEditorAlias = dr.GetString("editorAlias"); } else @@ -228,13 +188,6 @@ namespace umbraco.cms.businesslogic.macro } - [MethodImpl(MethodImplOptions.Synchronized)] - [Obsolete("This method is no longer supported because MacroPropertyType no longer has a function")] - public static MacroProperty MakeNew(Macro macro, bool show, string alias, string name, MacroPropertyType propertyType) - { - return MakeNew(macro, alias, name, propertyType.Alias); - } - /// /// Creates a new MacroProperty on a macro /// diff --git a/src/umbraco.cms/businesslogic/macro/MacroPropertyModel.cs b/src/umbraco.cms/businesslogic/macro/MacroPropertyModel.cs deleted file mode 100644 index 497b9e6552..0000000000 --- a/src/umbraco.cms/businesslogic/macro/MacroPropertyModel.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; - -namespace umbraco.cms.businesslogic.macro -{ - [Serializable] - public class MacroPropertyModel - { - public string Key { get; set; } - public string Value { get; set; } - public string Type { get; set; } - - [Obsolete("This is no longer used an will be removed in future versions")] - public string CLRType { get; set; } - - public MacroPropertyModel() - { - - } - - public MacroPropertyModel(string key, string value) - { - Key = key; - Value = value; - } - - public MacroPropertyModel(string key, string value, string type, string clrType) - { - Key = key; - Value = value; - Type = type; - CLRType = clrType; - } - } -} \ No newline at end of file diff --git a/src/umbraco.cms/businesslogic/macro/macroPropertyType.cs b/src/umbraco.cms/businesslogic/macro/macroPropertyType.cs deleted file mode 100644 index f4b6dc960e..0000000000 --- a/src/umbraco.cms/businesslogic/macro/macroPropertyType.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Data; -using umbraco.DataLayer; -using umbraco.BusinessLogic; -using System.Collections.Generic; - -namespace umbraco.cms.businesslogic.macro -{ - /// - /// The MacroPropertyType class contains information on the assembly and class of the - /// IMacroGuiRendering component and basedatatype - /// - [Obsolete("This class is no longer used, the cmsMacroPropertyType has been removed, all methods will return empty collections and not perform any functions")] - public class MacroPropertyType - { - protected static ISqlHelper SqlHelper - { - get { return LegacySqlHelper.SqlHelper; } - } - - public static List GetAll - { - get { return new List(); } - } - - /// - /// Identifier - /// - public int Id { get; internal set; } - - /// - /// The alias of the MacroPropertyType - /// - public string Alias { get; internal set; } - - /// - /// The assembly (without the .dll extension) used to retrieve the component at runtime - /// - public string Assembly { get; internal set; } - - /// - /// The MacroPropertyType - /// - public string Type { get; internal set; } - - /// - /// The IMacroGuiRendering component (namespace.namespace.Classname) - /// - public string BaseType { get; internal set; } - - internal MacroPropertyType() - { - - } - - /// - /// Constructor - /// - /// Identifier - public MacroPropertyType(int Id) - { - - } - - /// - /// Constructor - /// - /// The alias of the MacroPropertyType - public MacroPropertyType(string Alias) - { - - } - - } -} diff --git a/src/umbraco.cms/umbraco.cms.csproj b/src/umbraco.cms/umbraco.cms.csproj index f2f2f715c9..56c351cb1c 100644 --- a/src/umbraco.cms/umbraco.cms.csproj +++ b/src/umbraco.cms/umbraco.cms.csproj @@ -170,7 +170,6 @@ - True @@ -205,9 +204,6 @@ Code - - Code -