1
使用Moq或Rhino,我想在我的一個MVC動作方法中嘲諷一個局部變量。模擬MVC操作方法中的局部變量?
在我的程序我有實例的「ProfileController可」,有看起來像一個方法:
public ActionResult Profile(ProfileOptions oProfile)
{
ProfileViewModel oModel = new ProfileViewModel(); // <--can I mock this?
//… do work, using oModel along the way
return View(oModel);
}
我的測試將創建一個測試類[SetUp]
法新ProfileController可,我會跑使用它的動作方法的各種測試。
我想在我的測試中調用Profile
方法來模擬上面的變量oModel
,但因爲它是本地的而不是通過注入傳入的,所以我可以以某種方式執行此操作?