C# Owin.Testing.TestServer和基于属性的路由

C# Owin.Testing.TestServer和基于属性的路由,c#,unit-testing,asp.net-web-api,owin,C#,Unit Testing,Asp.net Web Api,Owin,我们正在使用基于属性的路由的webservice。路线的几个例子: /api/v1/reporting/client /api/v1/reporting/client/{id} /api/v1/reporting/client/{id}/address/{addressId} /api/v1/reporting/account /api/v1/billing/client /api/v1/billing/client/{id} /api/v1/billing/client/{id}/transa

我们正在使用基于属性的路由的webservice。路线的几个例子:

/api/v1/reporting/client
/api/v1/reporting/client/{id}
/api/v1/reporting/client/{id}/address/{addressId}
/api/v1/reporting/account
/api/v1/billing/client
/api/v1/billing/client/{id}
/api/v1/billing/client/{id}/transactions

由于这种结构,我们使用基于属性的路由(每个控制器都有RoutePrefix属性,其中的每个方法都有Route属性)。在某个时候,我们开始将其转换为OWIN。此外,我们希望对大多数端点使用单元测试。所以我最终尝试使用Microsoft.Owin.Testing.TestServer。然而,我尝试测试的任何端点都是404,看起来b/c我们使用属性进行路由(当我在不使用属性的webapi上测试此方法时,我没有这个问题)。因此,我的问题是如何使基于属性的路由与TestServer一起工作,或者如何用其他可以与TestServer一起工作并为我提供前面列出的路由的东西来替换属性

您是否成功地实现了这一点?我使用的TestServer带有属性路由,没有任何问题-因此这肯定是可能的,但不确定您的问题可能是什么。在构建WebApi HttpConfig时是否调用MapHttpAttribute路由?@MauricioScheffer,还没有。还没有机会回到那个项目。@danielrbradley,我打电话给“globalConfig.MapHttpAttributeRoutes(constraintResolver)”;HttpConfiguration globalConfig和DefaultInlineConstraintResolver constraintResolver在哪里仍然有这个问题?我遇到了类似的情况,我的所有路线都以“api/”为前缀。它原来是由连接到
TestServer
HttpClient
上的基址引起的。我切换到实例化我自己的
HttpClient
,并将基址设置为解决该问题的集合。