asp.net-mvc – 单元测试RedirectToRouteResult
发布时间:2020-05-24 07:25:57 所属栏目:asp.Net 来源:互联网
导读:我的控制器中有以下代码: public class MyController : BaseController{ public ActionResult MyMethod() { ... return RedirectToAction(Index, Dashboard); }} 我想单元测试这个重定向(RedirectToRout
|
我的控制器中有以下代码: public class MyController : BaseController
{
public ActionResult MyMethod()
{
...
return RedirectToAction("Index","Dashboard");
}
}
我想单元测试这个重定向(RedirectToRouteResult). Assert.IsTrue(result.RouteValues.ContainsKey("action"));
Assert.IsTrue(result.RouteValues.ContainsKey("controller"));
Assert.AreEqual("Index",result.RouteValues["action"].ToString());
Assert.AreEqual("Dashboard",result.RouteValues["controller"].ToString());
所以我需要四个断言来测试我的RedirectToRouteResult. 解决方法有一种更有效的方式,因为你不需要测试这两行Assert.IsTrue(result.RouteValues.ContainsKey("action"));
Assert.IsTrue(result.RouteValues.ContainsKey("controller"));
那些是你没有写的代码的断言.你必须相信那些写这个代码的人有自己的单元测试.如果反对所有的可能性,前两行将是错误的,你的两个最后的断言将失败. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 奇怪的错误w / NinjectValidatorFactory更新
- asp.net – 客户特定语言的定制文化?
- 有没有替代ASP.NET的C#web开发?
- ASP.NET安全最佳实践
- asp.net-mvc – 为什么我的动作方法不会超时?
- asp.net – ASP .Net Web API下载图像为二进制
- 在ASP.NET中,什么决定了HostingEnvironment.IsDevelopmentE
- asp.net-mvc – 在MVC中将值从Controller传输到Shared View
- IIS 7.5应用程序初始化ASP.NET Web服务(预热),而不重新映射
- asp.net-mvc-3 – 方法“OrderBy”必须在方法“跳过”异常之
推荐文章
站长推荐
热点阅读
