diff --git a/src/Umbraco.Tests/LibraryTests.cs b/src/Umbraco.Tests/LibraryTests.cs index ed47e27b7c..c340929c0f 100644 --- a/src/Umbraco.Tests/LibraryTests.cs +++ b/src/Umbraco.Tests/LibraryTests.cs @@ -102,8 +102,11 @@ namespace Umbraco.Tests /// private string LegacyGetItem(int nodeId, string alias) { - var umbracoXML = UmbracoContext.Current.GetXml(); - string xpath = UmbracoSettings.UseLegacyXmlSchema ? "./data [@alias='{0}']" : "./{0}"; + var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache; + if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported."); + var umbracoXML = cache.GetXml(UmbracoContext.Current); // = UmbracoContext.Current.GetXml(); + + string xpath = UmbracoSettings.UseLegacyXmlSchema ? "./data [@alias='{0}']" : "./{0}"; if (umbracoXML.GetElementById(nodeId.ToString()) != null) if ( ",id,parentID,level,writerID,template,sortOrder,createDate,updateDate,nodeName,writerName,path," diff --git a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs index 4da1a34359..04689b7389 100644 --- a/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/PublishedCache/PublishedContentCacheTests.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Xml; using NUnit.Framework; @@ -79,7 +80,8 @@ namespace Umbraco.Tests.PublishedCache new PublishedContentCache(), new PublishedMediaCache()); - _umbracoContext.GetXmlDelegate = () => + var cache = new PublishedContentCache(); + cache.GetXmlDelegate = (user, preview) => { var xDoc = new XmlDocument(); @@ -90,14 +92,18 @@ namespace Umbraco.Tests.PublishedCache return xDoc; }; - _cache = new ContextualPublishedContentCache(new PublishedContentCache(), _umbracoContext); + _cache = new ContextualPublishedContentCache(cache, _umbracoContext); } private void SetupForLegacy() { Umbraco.Core.Configuration.UmbracoSettings.UseLegacyXmlSchema = true; - _umbracoContext.GetXmlDelegate = () => - { + + var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache; + if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported."); + + cache.GetXmlDelegate = (user, preview) => + { var xDoc = new XmlDocument(); //create a custom xml structure to return diff --git a/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs b/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs index 02a0e1a9aa..abd05e0ecd 100644 --- a/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs +++ b/src/Umbraco.Tests/PublishedContent/DynamicNodeTests.cs @@ -6,6 +6,7 @@ using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Tests.TestHelpers; using Umbraco.Web; +using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.LegacyXmlCache; using umbraco.MacroEngines; using umbraco.NodeFactory; @@ -83,10 +84,13 @@ namespace Umbraco.Tests.PublishedContent //var template = Template.MakeNew("test", new User(0)); //var ctx = GetUmbracoContext("/test", template.Id); var ctx = GetUmbracoContext("/test", 1234); - var cache = new PublishedContentCache(); + + var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache; + if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported."); + var node = new DynamicNode( new DynamicBackingItem( - new Node(ctx.GetXml().SelectSingleNode("//*[@id='" + id + "' and @isDoc]")))); + new Node(cache.GetXml(ctx).SelectSingleNode("//*[@id='" + id + "' and @isDoc]")))); Assert.IsNotNull(node); return (dynamic)node; } diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index e9a32661f6..a891911c84 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -21,6 +21,7 @@ using Umbraco.Core.Publishing; using Umbraco.Core.Services; using Umbraco.Tests.Stubs; using Umbraco.Web; +using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.LegacyXmlCache; using Umbraco.Web.Routing; using umbraco.BusinessLogic; @@ -312,7 +313,9 @@ namespace Umbraco.Tests.TestHelpers /// protected void SetupUmbracoContextForTest(UmbracoContext umbracoContext, int templateId) { - umbracoContext.GetXmlDelegate = () => + var cache = PublishedContentCacheResolver.Current.PublishedContentCache as PublishedContentCache; + if (cache == null) throw new Exception("Unsupported IPublishedContentCache, only the legacy one is supported."); + cache.GetXmlDelegate = (user, preview) => { var xDoc = new XmlDocument(); diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index cf7131eb15..500e02ea55 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -232,53 +232,6 @@ namespace Umbraco.Web /// internal ContextualPublishedMediaCache MediaCache { get; private set; } - private Func _xmlDelegate; - - /// - /// Gets/sets the delegate used to retreive the Xml content, generally the setter is only used for unit tests - /// and by default if it is not set will use the standard delegate which ONLY works when in the context an Http Request - /// - /// - /// If not defined, we will use the standard delegate which ONLY works when in the context an Http Request - /// mostly because the 'content' object heavily relies on HttpContext, SQL connections and a bunch of other stuff - /// that when run inside of a unit test fails. - /// - internal Func GetXmlDelegate - { - get - { - return _xmlDelegate ?? (_xmlDelegate = () => - { - if (InPreviewMode) - { - if (_previewContent == null) - { - _previewContent = new PreviewContent(UmbracoUser, new Guid(StateHelper.Cookies.Preview.GetValue()), true); - if (_previewContent.ValidPreviewSet) - _previewContent.LoadPreviewset(); - } - if (_previewContent.ValidPreviewSet) - return _previewContent.XmlContent; - } - return content.Instance.XmlContent; - }); - } - set { _xmlDelegate = value; } - } - - /// - /// Returns the XML Cache document - /// - /// - /// - /// This is marked internal for now because perhaps we might return a wrapper like CacheData so that it doesn't have a reliance - /// specifically on XML. - /// - internal XmlDocument GetXml() - { - return GetXmlDelegate(); - } - /// /// Boolean value indicating whether the current request is a front-end umbraco request ///