【发布时间】:2018-05-23 08:05:44
【问题描述】:
我一直试图弄清楚如何对服务进行单元测试,但到目前为止一无所获。
我正在使用 xUnit 和 NSubstitute(按照朋友的建议),下面是我想要运行的简单测试(目前失败)。
public class UnitTest1
{
private readonly RallyService _rallyService;
public UnitTest1(RallyService rallyService)
{
_rallyService= rallyService;
}
[Fact]
public void Test1()
{
var result = _rallyService.GetAllRallies();
Assert.Equal(2, result.Count());
}
}
我的拉力赛服务类对 db 进行简单调用以获取所有拉力赛实体并返回这些:
public class RallyService : IRallyService
{
private readonly RallyDbContext _context;
public RallyService(RallyDbContext context)
{
_context = context;
}
public IEnumerable<Rally> GetAllRallies()
{
return _context.Rallies;
}
}
任何指导将不胜感激。
【问题讨论】:
标签: unit-testing asp.net-core nunit nsubstitute