Testing the wrapping of view engines
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
78
src/Umbraco.Tests/BootManagers/WebBootManagerTester.cs
Normal file
78
src/Umbraco.Tests/BootManagers/WebBootManagerTester.cs
Normal file
@@ -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 WebBootManagerTester
|
||||
{
|
||||
[Test]
|
||||
public void WrapViewEngines_HasEngines_WrapsAll()
|
||||
{
|
||||
IList<IViewEngine> engines = new List<IViewEngine>
|
||||
{
|
||||
new FixedWebFormViewEngine(),
|
||||
new FixedRazorViewEngine(),
|
||||
new RenderViewEngine(),
|
||||
new PluginViewEngine()
|
||||
};
|
||||
|
||||
WebBootManager.WrapViewEngines(engines);
|
||||
|
||||
Assert.That(engines.Count, Is.EqualTo(4));
|
||||
Assert.That(engines[0], Is.InstanceOf<ProfilingViewEngine>());
|
||||
Assert.That(engines[1], Is.InstanceOf<ProfilingViewEngine>());
|
||||
Assert.That(engines[2], Is.InstanceOf<ProfilingViewEngine>());
|
||||
Assert.That(engines[3], Is.InstanceOf<ProfilingViewEngine>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrapViewEngines_HasEngines_KeepsSortOrder()
|
||||
{
|
||||
IList<IViewEngine> engines = new List<IViewEngine>
|
||||
{
|
||||
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<FixedWebFormViewEngine>());
|
||||
Assert.That(((ProfilingViewEngine)engines[1]).Inner, Is.InstanceOf<FixedRazorViewEngine>());
|
||||
Assert.That(((ProfilingViewEngine)engines[2]).Inner, Is.InstanceOf<RenderViewEngine>());
|
||||
Assert.That(((ProfilingViewEngine)engines[3]).Inner, Is.InstanceOf<PluginViewEngine>());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void WrapViewEngines_HasProfiledEngine_AddsSameInstance()
|
||||
{
|
||||
var profiledEngine = new ProfilingViewEngine(new FixedRazorViewEngine());
|
||||
IList<IViewEngine> engines = new List<IViewEngine>
|
||||
{
|
||||
profiledEngine
|
||||
};
|
||||
|
||||
WebBootManager.WrapViewEngines(engines);
|
||||
|
||||
Assert.That(engines[0], Is.SameAs(profiledEngine));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WrapViewEngines_CollectionIsNull_DoesNotThrow()
|
||||
{
|
||||
IList<IViewEngine> engines = null;
|
||||
Assert.DoesNotThrow(() => WebBootManager.WrapViewEngines(engines));
|
||||
Assert.That(engines, Is.Null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,10 @@
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Mvc.FixedDisplayModes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Umbraco.Web.UI\bin\Microsoft.Web.Mvc.FixedDisplayModes.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq">
|
||||
<HintPath>..\packages\Moq.4.1.1309.1617\lib\net40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -146,6 +150,7 @@
|
||||
<Compile Include="AttemptTests.cs" />
|
||||
<Compile Include="Auditing\AuditTests.cs" />
|
||||
<Compile Include="BootManagers\CoreBootManagerTests.cs" />
|
||||
<Compile Include="BootManagers\WebBootManagerTester.cs" />
|
||||
<Compile Include="BusinessLogic\DictionaryTest.cs" />
|
||||
<Compile Include="Cache\CacheHelperTests.cs" />
|
||||
<Compile Include="CodeFirst\Attributes\AliasAttribute.cs" />
|
||||
|
||||
@@ -128,13 +128,7 @@ namespace Umbraco.Web
|
||||
public override IBootManager Complete(Action<ApplicationContext> 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();
|
||||
@@ -147,7 +141,20 @@ namespace Umbraco.Web
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
internal static void WrapViewEngines(IList<IViewEngine> viewEngines)
|
||||
{
|
||||
if (viewEngines == null || viewEngines.Count == 0) return;
|
||||
|
||||
var origninaleEngines = viewEngines.Select(e => e).ToArray();
|
||||
viewEngines.Clear();
|
||||
foreach (var engine in origninaleEngines)
|
||||
{
|
||||
var wrappedEngine = engine is ProfilingViewEngine ? engine : new ProfilingViewEngine(engine);
|
||||
viewEngines.Add(wrappedEngine);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the routes
|
||||
/// </summary>
|
||||
protected internal void CreateRoutes()
|
||||
|
||||
Reference in New Issue
Block a user