与可以在此处找到的先前问题相关:
测试方法:
[TestMethod]
public void AMAC_Route_Maps_to_AMACController()
{
"~/amac/".ShouldMapTo<AMACController>(action => action.Index());
}
路线:
routes.MapRoute(
name: "AMAC",
url: "amac/",
defaults: new { controller = "AMAC", action = "Index" }
);
返回的错误:
测试方法 MBS.Exec.Enquiry.MVC.Tests.AMACControllerTest.AMAC_Route_Maps_to_AMACController 抛出异常:MvcContrib.TestHelper.AssertionException:URL 不匹配任何路由
仅当我在解决方案中运行所有测试时,才会抛出此错误,当我独立于其通过的类运行测试时。
作为一个例子,我有一个类似控制器的测试方法,它确实通过了,下面是测试方法的代码及其路由:
测试方法
[TestMethod]
public void HVM_Route_Maps_to_HVMController()
{
"~/hvm/".ShouldMapTo<HVMController>(action => action.Index());
}
路线:
routes.MapRoute(
name: "HVM",
url: "hvm/",
defaults: new { controller = "HVM", action = "Index" }
);
此测试不会产生错误。