New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for MVC attribute routes (fixes #767) #769

Merged
merged 12 commits into from Apr 23, 2014

Added additional unit tests for Route alternate type

  • Loading branch information...
PaulAtkins committed Mar 25, 2014
commit eb3eb07cb1c8c5c88aa048e381f847cf650413c4
@@ -22,6 +22,18 @@ public Route(IProxyFactory proxyFactory, ILogger logger)
routeConstraintAlternate = new RouteConstraint(proxyFactory);
}
public IEnumerable<IAlternateMethod> AllMethodsRouteBase
{
get
{
return allMethodsRouteBase ?? (allMethodsRouteBase = new List<IAlternateMethod>
{
new GetRouteData(typeof(System.Web.Routing.RouteBase)),
new GetVirtualPath(typeof(System.Web.Routing.RouteBase))
});
}
}
public IEnumerable<IAlternateMethod> AllMethodsRoute
{
get
@@ -69,9 +81,9 @@ public bool TryCreate(System.Web.Routing.Route originalObj, out System.Web.Routi
if (newObj == null)
{
if (ProxyFactory.IsWrapClassEligible(typeof(System.Web.Routing.Route)))
if (ProxyFactory.IsWrapClassEligible(typeof(System.Web.Routing.RouteBase)))
{
newObj = ProxyFactory.WrapClass(originalObj, AllMethodsRoute, mixins);
newObj = ProxyFactory.WrapClass(originalObj, AllMethodsRouteBase, mixins);
}
}
@@ -11,16 +11,21 @@
namespace Glimpse.Test.AspNet.AlternateType
{
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Reviewed. Class is okay because it only changes the generic T parameter for the abstract class below.")]
public class RouteBaseGetRouteDataShould : GetRouteDataShould<System.Web.Routing.RouteBase>
public class RouteBaseGetRouteDataRouteBaseShould : GetRouteDataRouteBaseShould<System.Web.Routing.RouteBase>
{
}
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Reviewed. Class is okay because it only changes the generic T parameter for the abstract class below.")]
public class RouteGetRouteDataShould : GetRouteDataShould<System.Web.Routing.Route>
public class RouteGetRouteDataRouteBaseShould : GetRouteDataRouteBaseShould<System.Web.Routing.Route>
{
}
public abstract class GetRouteDataShould<T>
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:FileMayOnlyContainASingleClass", Justification = "Reviewed. Class is okay because it only changes the generic T parameter for the abstract class below.")]
public class RouteGetRouteDataRouteShould : GetRouteDataRouteShould<System.Web.Routing.Route>
{
}
public abstract class GetRouteDataRouteBaseShould<T>
where T : System.Web.Routing.RouteBase
{
[Fact]
@@ -59,4 +64,44 @@ public void PublishMessageWhenExecuted([Frozen] IExecutionTimer timer, IAlternat
context.MessageBroker.Verify(mb => mb.Publish(It.IsAny<RouteBase.GetRouteData.Message>()));
}
}
public abstract class GetRouteDataRouteShould<T>
where T : System.Web.Routing.Route
{
[Fact]
public void ReturnProperMethodToImplement()
{
var impl = new Route.GetRouteData(typeof(T));
Assert.Equal("GetRouteData", impl.MethodToImplement.Name);
}
[Theory, AutoMock]
public void ReturnWhenRuntimePolicyIsOff(IAlternateMethodContext context)
{
context.Setup(c => c.RuntimePolicyStrategy).Returns(() => RuntimePolicy.Off);
var impl = new Route.GetRouteData(typeof(T));
impl.NewImplementation(context);
context.Verify(c => c.Proceed());
}
[Theory, AutoMock]
public void PublishMessageWhenExecuted([Frozen] IExecutionTimer timer, IAlternateMethodContext context, IRouteNameMixin mixin)
{
context.Setup(c => c.Arguments).Returns(new object[5]);
context.Setup(c => c.ReturnValue).Returns(new System.Web.Routing.RouteData());
context.Setup(c => c.InvocationTarget).Returns(new System.Web.Routing.Route("Test", null));
context.Setup(c => c.Proxy).Returns(mixin);
var impl = new Route.GetRouteData(typeof(T));
impl.NewImplementation(context);
timer.Verify(t => t.Time(It.IsAny<Action>()));
context.MessageBroker.Verify(mb => mb.Publish(It.IsAny<Route.GetRouteData.Message>()));
}
}
}
@@ -0,0 +1,21 @@
using System.Linq;
using Glimpse.AspNet.AlternateType;
using Glimpse.Core.Extensibility;
using Glimpse.Test.Common;
using Xunit;
using Xunit.Extensions;
namespace Glimpse.Test.AspNet.AlternateType
{
public class RouteShould
{
[Theory, AutoMock]
public void ReturnOneMethod(IProxyFactory proxyFactory, ILogger logger)
{
var alternationImplementation = new Route(proxyFactory, logger);
Assert.Equal(2, alternationImplementation.AllMethodsRouteBase.Count());
Assert.Equal(3, alternationImplementation.AllMethodsRoute.Count());
}
}
}
@@ -64,7 +64,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AlternateType\RouteBaseGetRouteDataShould.cs" />
<Compile Include="AlternateType\RouteGetRouteDataShould.cs" />
<Compile Include="AlternateType\RouteShould .cs" />
<Compile Include="AlternateType\RouteBaseShould.cs" />
<Compile Include="AlternateType\RouteConstraintMatchShould.cs" />
<Compile Include="AlternateType\RouteConstraintRegexShould.cs" />
@@ -119,7 +120,6 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
ProTip! Use n and p to navigate between commits in a pull request.