我是单元测试的新手。我想为删除控制器操作编写单元测试。我想使用NSubstitute来模拟所有依赖项。当前实现使用接口IRepository抽象出对底层数据源的调用。
控制器
public ActionResult Delete(string fileName, bool isPublic)
{
try
{
repo.DeleteDocument(new PortalDocument
{
Path = fileName,
IsPublic = isPublic
});
}
catch (Exception e)
{
EventLog.Logger.LogCritical(e, e.Message);
}
return RedirectToAction(IndexViewName);
}
存储库接口。
public interface IRepository<out T> where T:
CloudBlobContainer
{
bool DeleteDocument(PortalDocument document);
}
PortalDocument类
public class PortalDocument
{
public bool IsPublic { get; set; }
}
提前致谢。