たとえば、Mvc3コントローラー用のモック(Moqを使用)セットアップがあります。
[TestMethod]
public void Step_One_Post_Should_Redirect_To_Step_Two()
{
// this test checks that when I submit a type parameter of StepOneModel and
// the next button was clicked Request["next"] , then goto Step Two
}
このテストの実行を停止する唯一のことは、コントローラーから呼び出された Save メソッドです。これは、このテスト コンテキストのセッションで値が適切に設定されていないため失敗します。本当に、この単体テストからこのデータベース呼び出しを省略したいと思います。
基本的に、コントローラーアクションから Save(model) 呼び出しを停止/モックするにはどうすればよいですか?
[HttpPost]
public ActionResult Index(IStepViewModel step)
{
// after model is deserialized
if (!string.IsNullOrEmpty(Request["next"]))
{
Save(model) <-- the bit blocking me
}
return View(model) <-- the bit I want to assert against
}