我有一個觀點,它有局部視圖渲染內:如何測試局部視圖,在C#ASP .NET被渲染MVC
<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.
我在做什麼錯?
斷言AssertPartialViewRendered().ForView(「部分」)...'仍然會失敗,因爲控制器正在返回一個視圖「視圖」。 – Joe
沒有注意到。謝謝 – 2012-09-11 14:21:36