2013-10-18 28 views
4

所以,我一直在研究了很多关于这一点,但我不能找到一个解决办法我的问题单元测试MVC 4路使用AttributeRouting和MvcRouteTester

我有一个MVC4 /网络API应用程序,我使用AttributeRouting 3.5。 6

我的应用程序工作正常。

我能单元测试使用以下响应

AttributeRouting not working with HttpConfiguration object for writing Integration tests

我想现在要做的就是单元测试我MVC4路线,但我还没有找到一个办法做到这一点

在Web API路线

我发现了以下问题,我想知道,如果有一个变通方法在那里

https://github.com/mccalltd/AttributeRouting/issues/64

基本问题似乎是加载在内存中的属性来我单位的线路测试

这是我到目前为止已经试过:

routes.MapAttributeRoutes(x => 
{ 
    x.AddRoutesFromAssembly(typeof(HomeController).Assembly); 
    x.AddRoutesFromAssemblyOf<HomeController>(); 

    x.AddRoutesFromController(typeof(HomeController)); 
    x.AddRoutesFromController<HomeController>(); 
    x.AddRoutesFromControllersOfType(typeof(Controller)); 
    x.AddRoutesFromControllersOfType<Controller>(); 
}); 
  • 当我useany的大会的方法路由收集为空

  • 当我使用任何控制器方法我收到以下异常:

    System.Security.VerificationException:方法AttributeRouting.Web.Mvc.Configuration.AddRoutesFromControllersOfType:类型参数 'MyNamespace.Controllers.HomeController' 违反类型参数 'T' 的约束。

它必须是一种方式,因为当我运行应用程序,它工作得很好,我的所有路由都登记在RoutesCollection

回答

3

以下内容添加到您的测试项目的app.config

<configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="4.0.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 
+0

它看起来像MvcRouteTester包现在默认添加这个。 – rasx