Started adding tests for surface controller routing. They are working but not quite correctly yet.

This commit is contained in:
Shannon Deminick
2012-09-25 13:33:47 +07:00
parent 0b7f04ab37
commit 7b7e3b82f1
6 changed files with 36 additions and 3 deletions

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Umbraco.Tests.Surface
{
public class SurfaceControllerAreaTests
{
}
}

View File

@@ -70,6 +70,7 @@
<Compile Include="DataTypeFactoryTests.cs" />
<Compile Include="Routing\LookupByNiceUrlWithDomainsTests.cs" />
<Compile Include="Routing\NiceUrlsProviderWithDomainsTests.cs" />
<Compile Include="Surface\SurfaceControllerAreaTests.cs" />
<Compile Include="TestHelpers\BaseRoutingTest.cs" />
<Compile Include="GlobalSettingsTests.cs" />
<Compile Include="Routing\LookupByAliasTests.cs" />

View File

@@ -59,6 +59,10 @@ namespace Umbraco.Web
//set the namespace of the controller to match
new[] { controllerType.Namespace });
//TODO: FIx this!!
//By setting the default this will always route even without specifying the surfaceId syntax in the URL,
// we need to unit test this and ensure it is correct
//set defaults
controllerPluginRoute.Defaults = new RouteValueDictionary(
new Dictionary<string, object>

View File

@@ -6,6 +6,15 @@ using Umbraco.Core;
namespace Umbraco.Web.Mvc
{
[SurfaceController("DD307F95-6D90-4593-8C97-093AC7C12573")]
public class TestSurfaceController : SurfaceController
{
public ActionResult Index()
{
return Content("<html><body>hello</body></html>");
}
}
/// <summary>
/// The base controller that all Presentation Add-in controllers should inherit from
/// </summary>

View File

@@ -39,7 +39,7 @@ namespace Umbraco.Web.Mvc
var areaName = GlobalSettings.UmbracoMvcArea;
//local surface controllers do not contain the attribute
var localSurfaceControlleres = surfaceControllers.Where(x => TypeExtensions.GetCustomAttribute<SurfaceControllerAttribute>(x.GetType(), false) == null);
var localSurfaceControlleres = surfaceControllers.Where(x => x.GetType().GetCustomAttribute<SurfaceControllerAttribute>(false) == null);
foreach (var s in localSurfaceControlleres)
{
var meta = s.GetMetadata();

View File

@@ -10,9 +10,17 @@ namespace Umbraco.Web.Mvc
{
public Guid Id { get; private set; }
public SurfaceControllerAttribute(Guid id)
public SurfaceControllerAttribute(string id)
{
Id = id;
Guid gid;
if (Guid.TryParse(id, out gid))
{
Id = gid;
}
else
{
throw new InvalidCastException("Cannot convert the value " + id + " to a Guid");
}
}
}
}