从ASP MVC单元测试中获取Model和Route数据

时间:2014-04-18 20:43:43

标签: asp.net-mvc asp.net-mvc-3 unit-testing nunit resharper

是否可以从ReSharper 7.1.3单元测试中获取Model和Route数据?我似乎必须使用下面的方法在一个或另一个之间做出选择

路线数据

//Execute controller action
var redirect = _controlAgtTran.Create(agency) as RedirectToRouteResult;

//Check route values since Model is not accessible
Assert.IsNotNull(redirect);
Assert.AreEqual("AgentTransmission", redirect.RouteValues["controller"]);
Assert.AreEqual("Index", redirect.RouteValues["action"]);
Assert.AreEqual("Record saved with status of 'Waiting'", redirect.RouteValues["msg"]);

模型信息

//Execute controller action
var result = _controlAgtTran.Create(agency) as ViewResult;
var model = result.Model as AgentTransmission;

//Check model properties since RouteValues is not accesible
Assert.AreEqual(model.RecordStatus, "P");

0 个答案:

没有答案