如何使用两个参数编写Controller方法的单元测试以及需要测试哪些方案?

时间:2018-05-10 16:30:31

标签: c# asp.net-mvc xunit nsubstitute

我是单元测试的新手。我想为删除控制器操作编写单元测试。我想使用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; }
}

提前致谢。

0 个答案:

没有答案