【发布时间】:2012-09-04 10:22:01
【问题描述】:
我有一个视图,里面有部分视图渲染:
<div class="partialViewDiv">
@Html.RenderPartial("partial", Model.SomeModelProperty);
</div>
还有一个控制器,它返回这个视图
public ActionResult Action()
{
...
var model = new SomeModel(){SomeModelProperty = "SomeValue"}
return View("view", model);
}
我知道如何测试视图被渲染:
[TestMethod]
public void TestView()
{
...
var result = controller.Action();
// Assert
result.AssertViewRendered().ForView("view").WithViewData<SomeModel>();
}
但是当我打电话时
result.AssertPartialViewRendered().ForView("partial").WithViewData<SomeModelPropertyType>();
我收到此错误消息
Expected result to be of type PartialViewResult. It is actually of type ViewResult.
我做错了什么?
【问题讨论】:
标签: c# asp.net-mvc-3 unit-testing view partial-views