我有一个观点,它有内部的局部视图渲染:
<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.
我究竟做错了什么?