トピックにあるように、MVC テスト プロジェクトでモック オブジェクトを null として返す方法がわかりません。単体テストの作成は初めてです。
アクションがあります:
[HttpPost]
public ActionResult Edit(ClubToAddVM clubToAddVm, HttpPostedFileBase imageFile)
{
if (ModelState.IsValid)
{
if (imageFile!=null)
{
clubToAddVm.ImageMimeType = imageFile.ContentType;
clubToAddVm.ImageData = new byte[imageFile.ContentLength];
imageFile.InputStream.Read(clubToAddVm.ImageData, 0, imageFile.ContentLength);
}
}
...
}
そして、テストで imageFile オブジェクトを null として渡したいと思います。残念ながら、HttpPostedFileBase
抽象クラスのインスタンスを作成することはできません。次のようなものを試してみたいと思います:
var mockImageFile = new Mock<HttpPostedFileBase>();
mockImageFile.Object
しかし、読み取り専用であるため、nullにする方法がわかりません
。何か案は?