Fixed Render route handler tests.

This commit is contained in:
Shannon Deminick
2013-02-20 06:30:06 +06:00
parent 694d252ce5
commit 89b85bcf4b
6 changed files with 52 additions and 6 deletions

View File

@@ -74,7 +74,9 @@ namespace Umbraco.Tests.Routing
handler.GetHandlerForRoute(routingContext.UmbracoContext.HttpContext.Request.RequestContext, docRequest);
Assert.AreEqual("RenderMvc", routeData.Values["controller"].ToString());
Assert.AreEqual("Index", routeData.Values["action"].ToString());
//the route action will still be the one we've asked for because our RenderActionInvoker is the thing that decides
// if the action matches.
Assert.AreEqual("homePage", routeData.Values["action"].ToString());
}
//test all template name styles to match the ActionName

View File

@@ -3,6 +3,7 @@ using System.Linq;
using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;
using Umbraco.Core;
namespace Umbraco.Tests.Stubs
@@ -28,12 +29,12 @@ namespace Umbraco.Tests.Stubs
public System.Web.SessionState.SessionStateBehavior GetControllerSessionBehavior(RequestContext requestContext, string controllerName)
{
throw new NotImplementedException();
return SessionStateBehavior.Disabled;
}
public void ReleaseController(IController controller)
{
throw new NotImplementedException();
controller.DisposeIfDisposable();
}
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Web.Mvc;
using System.Web.Routing;
namespace Umbraco.Web.Mvc
{
internal static class ControllerFactoryExtensions
{
/// <summary>
/// Gets a controller type by the name
/// </summary>
/// <param name="factory"></param>
/// <param name="requestContext"></param>
/// <param name="controllerName"></param>
/// <returns></returns>
/// <remarks>
/// This is related to issue: http://issues.umbraco.org/issue/U4-1726. We already have a method called GetControllerTypeInternal on our MasterControlelrFactory,
/// however, we cannot always guarantee that the usage of this will be a MasterControllerFactory like during unit tests. So we needed to create
/// this extension method to do the checks instead.
/// </remarks>
internal static Type GetControllerTypeInternal(this IControllerFactory factory, RequestContext requestContext, string controllerName)
{
var controllerFactory = factory as MasterControllerFactory;
if (controllerFactory != null)
{
return controllerFactory.GetControllerTypeInternal(requestContext, controllerName);
}
//we have no choice but to instantiate the controller
var instance = factory.CreateController(requestContext, controllerName);
if (instance != null)
{
return instance.GetType();
}
return null;
}
}
}

View File

@@ -9,7 +9,7 @@ using Umbraco.Core;
namespace Umbraco.Web.Mvc
{
/// <summary>
/// <summary>
/// A controller factory which uses an internal list of <see cref="IFilteredControllerFactory"/> in order to invoke
/// different controller factories dependent upon their implementation of <see cref="IFilteredControllerFactory.CanHandle"/> for the current
/// request. Allows circumvention of MVC3's singly registered IControllerFactory.
@@ -70,7 +70,11 @@ namespace Umbraco.Web.Mvc
}
//we have no choice but to instantiate the controller
var instance = factory.CreateController(requestContext, controllerName);
return instance.GetType();
if (instance != null)
{
return instance.GetType();
}
return null;
}
return base.GetControllerType(requestContext, controllerName);

View File

@@ -259,7 +259,7 @@ namespace Umbraco.Web.Mvc
}
//check if there's a custom controller assigned, base on the document type alias.
var controllerType = ((MasterControllerFactory)_controllerFactory).GetControllerTypeInternal(requestContext, publishedContentRequest.PublishedContent.DocumentTypeAlias);
var controllerType = _controllerFactory.GetControllerTypeInternal(requestContext, publishedContentRequest.PublishedContent.DocumentTypeAlias);
//check if that controller exists
if (controllerType != null)

View File

@@ -300,6 +300,7 @@
<Compile Include="DefaultPublishedMediaStore.cs" />
<Compile Include="Dictionary\UmbracoCultureDictionary.cs" />
<Compile Include="Dictionary\UmbracoCultureDictionaryFactory.cs" />
<Compile Include="Mvc\ControllerFactoryExtensions.cs" />
<Compile Include="Mvc\SurfaceRouteHandler.cs" />
<Compile Include="Mvc\UmbracoAuthorizeAttribute.cs" />
<Compile Include="Mvc\UmbracoAuthorizedController.cs" />