diff --git a/src/Umbraco.Core/Profiling/ProfilingViewEngine.cs b/src/Umbraco.Core/Profiling/ProfilingViewEngine.cs index 641e060d50..70bb014bb3 100644 --- a/src/Umbraco.Core/Profiling/ProfilingViewEngine.cs +++ b/src/Umbraco.Core/Profiling/ProfilingViewEngine.cs @@ -4,12 +4,12 @@ namespace Umbraco.Core.Profiling { public class ProfilingViewEngine: IViewEngine { - private readonly IViewEngine _inner; + internal readonly IViewEngine Inner; private readonly string _name; public ProfilingViewEngine(IViewEngine inner) { - _inner = inner; + Inner = inner; _name = inner.GetType().Name; } @@ -17,7 +17,7 @@ namespace Umbraco.Core.Profiling { using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindPartialView, {1}, {2}", _name, partialViewName, useCache))) { - return WrapResult(_inner.FindPartialView(controllerContext, partialViewName, useCache)); + return WrapResult(Inner.FindPartialView(controllerContext, partialViewName, useCache)); } } @@ -25,7 +25,7 @@ namespace Umbraco.Core.Profiling { using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.FindView, {1}, {2}, {3}", _name, viewName, masterName, useCache))) { - return WrapResult(_inner.FindView(controllerContext, viewName, masterName, useCache)); + return WrapResult(Inner.FindView(controllerContext, viewName, masterName, useCache)); } } @@ -41,7 +41,7 @@ namespace Umbraco.Core.Profiling { using (ProfilerResolver.Current.Profiler.Step(string.Format("{0}.ReleaseView, {1}", _name, view.GetType().Name))) { - _inner.ReleaseView(controllerContext, view); + Inner.ReleaseView(controllerContext, view); } } } diff --git a/src/Umbraco.Tests/BootManagers/WebBootManagerTests.cs b/src/Umbraco.Tests/BootManagers/WebBootManagerTests.cs new file mode 100644 index 0000000000..9ddba6df5f --- /dev/null +++ b/src/Umbraco.Tests/BootManagers/WebBootManagerTests.cs @@ -0,0 +1,78 @@ +using System.Collections.Generic; +using System.Web.Mvc; +using Microsoft.Web.Mvc; +using NUnit.Framework; +using Umbraco.Core.Profiling; +using Umbraco.Web; +using Umbraco.Web.Mvc; + +namespace Umbraco.Tests.BootManagers +{ + [TestFixture] + public class WebBootManagerTests + { + [Test] + public void WrapViewEngines_HasEngines_WrapsAll() + { + IList engines = new List + { + new FixedWebFormViewEngine(), + new FixedRazorViewEngine(), + new RenderViewEngine(), + new PluginViewEngine() + }; + + WebBootManager.WrapViewEngines(engines); + + Assert.That(engines.Count, Is.EqualTo(4)); + Assert.That(engines[0], Is.InstanceOf()); + Assert.That(engines[1], Is.InstanceOf()); + Assert.That(engines[2], Is.InstanceOf()); + Assert.That(engines[3], Is.InstanceOf()); + } + + [Test] + public void WrapViewEngines_HasEngines_KeepsSortOrder() + { + IList engines = new List + { + new FixedWebFormViewEngine(), + new FixedRazorViewEngine(), + new RenderViewEngine(), + new PluginViewEngine() + }; + + WebBootManager.WrapViewEngines(engines); + + Assert.That(engines.Count, Is.EqualTo(4)); + Assert.That(((ProfilingViewEngine)engines[0]).Inner, Is.InstanceOf()); + Assert.That(((ProfilingViewEngine)engines[1]).Inner, Is.InstanceOf()); + Assert.That(((ProfilingViewEngine)engines[2]).Inner, Is.InstanceOf()); + Assert.That(((ProfilingViewEngine)engines[3]).Inner, Is.InstanceOf()); + } + + + [Test] + public void WrapViewEngines_HasProfiledEngine_AddsSameInstance() + { + var profiledEngine = new ProfilingViewEngine(new FixedRazorViewEngine()); + IList engines = new List + { + profiledEngine + }; + + WebBootManager.WrapViewEngines(engines); + + Assert.That(engines[0], Is.SameAs(profiledEngine)); + } + + [Test] + public void WrapViewEngines_CollectionIsNull_DoesNotThrow() + { + IList engines = null; + Assert.DoesNotThrow(() => WebBootManager.WrapViewEngines(engines)); + Assert.That(engines, Is.Null); + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 245dc1a050..945e4f8624 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -78,6 +78,9 @@ True ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + + ..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll + ..\packages\Moq.4.1.1309.0919\lib\net40\Moq.dll @@ -135,17 +138,17 @@ True ..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll - - True + ..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll - - True + + ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll - - True + + ..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll + True True @@ -171,6 +174,7 @@ + diff --git a/src/Umbraco.Tests/Views/web.config b/src/Umbraco.Tests/Views/web.config new file mode 100644 index 0000000000..aa5e0eb2e3 --- /dev/null +++ b/src/Umbraco.Tests/Views/web.config @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Umbraco.Tests/packages.config b/src/Umbraco.Tests/packages.config index 3f2292a8b8..df4bc3d02d 100644 --- a/src/Umbraco.Tests/packages.config +++ b/src/Umbraco.Tests/packages.config @@ -6,6 +6,7 @@ + diff --git a/src/Umbraco.Web/CacheHelperExtensions.cs b/src/Umbraco.Web/CacheHelperExtensions.cs index 9324e48cd2..03f462909f 100644 --- a/src/Umbraco.Web/CacheHelperExtensions.cs +++ b/src/Umbraco.Web/CacheHelperExtensions.cs @@ -12,7 +12,7 @@ namespace Umbraco.Web /// /// Extension methods for the cache helper /// - internal static class CacheHelperExtensions + public static class CacheHelperExtensions { public const string PartialViewCacheKey = "Umbraco.Web.PartialViewCacheKey"; @@ -54,4 +54,4 @@ namespace Umbraco.Web cacheHelper.ClearCacheByKeySearch(PartialViewCacheKey); } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index 3b4e5b3146..0b25dc63c3 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -83,7 +83,8 @@ namespace Umbraco.Web int cachedSeconds, bool cacheByPage = false, bool cacheByMember = false, - ViewDataDictionary viewData = null) + ViewDataDictionary viewData = null, + Func contextualKeyBuilder = null) { var cacheKey = new StringBuilder(partialViewName); if (cacheByPage) @@ -98,7 +99,12 @@ namespace Umbraco.Web { var currentMember = Member.GetCurrentMember(); cacheKey.AppendFormat("m{0}-", currentMember == null ? 0 : currentMember.Id); - } + } + if (contextualKeyBuilder != null) + { + var contextualKey = contextualKeyBuilder(model, viewData); + cacheKey.AppendFormat("c{0}-", contextualKey); + } return ApplicationContext.Current.ApplicationCache.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData); } @@ -814,4 +820,4 @@ namespace Umbraco.Web #endregion } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 1c15ecf3a1..5604ea2760 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -140,13 +140,7 @@ namespace Umbraco.Web public override IBootManager Complete(Action afterComplete) { //Wrap viewengines in the profiling engine - IViewEngine[] engines = ViewEngines.Engines.Select(e => e).ToArray(); - ViewEngines.Engines.Clear(); - foreach (var engine in engines) - { - var wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine); - ViewEngines.Engines.Add(wrappedEngine); - } + WrapViewEngines(ViewEngines.Engines); //set routes CreateRoutes(); @@ -159,7 +153,20 @@ namespace Umbraco.Web return this; } - /// + internal static void WrapViewEngines(IList viewEngines) + { + if (viewEngines == null || viewEngines.Count == 0) return; + + var originalEngines = viewEngines.Select(e => e).ToArray(); + viewEngines.Clear(); + foreach (var engine in originalEngines) + { + var wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine); + viewEngines.Add(wrappedEngine); + } + } + + /// /// Creates the application cache based on the HttpRuntime cache /// protected override void CreateApplicationCache() diff --git a/src/umbraco.cms/businesslogic/web/Domain.cs b/src/umbraco.cms/businesslogic/web/Domain.cs index f5bcb46090..f260ab639f 100644 --- a/src/umbraco.cms/businesslogic/web/Domain.cs +++ b/src/umbraco.cms/businesslogic/web/Domain.cs @@ -151,8 +151,7 @@ namespace umbraco.cms.businesslogic.web () => { var result = new List(); - using (var dr = SqlHelper.ExecuteReader( - "select id, domainName from umbracoDomains")) + using (var dr = SqlHelper.ExecuteReader("SELECT id, domainName FROM umbracoDomains ORDER BY id")) { while (dr.Read()) {