我需要将DbConnection传递给我的类。为此,我使用了NSubstitute。但当我运行测试时,出现了以下错误:"System.NullReferenceException: object reference未设置为Object的实例。Dapper“
我的测试
public class SceneApplicationServiceTest
{
private readonly DbConnection _connection = Substitute.For<DbConnection>();
ISceneApplicationService _sceneApplicationService;
public SceneApplicationServiceTest()
{
_sceneApplicationService = new SceneApplicationService(_connection);
}
[Fact]
public async Task ShouldBePossibleSuccessfullyGetByProgramScript()
{
const long programId = 1;
const string scriptId = "2";
await _sceneApplicationService.GetByProgramScript(programId, scriptId);
await _sceneApplicationService.Received(1).GetByProgramScript(programId, scriptId);
}
}我的方法
public class SceneApplicationService : ISceneApplicationService
{
private readonly DbConnection _connection;
public SceneApplicationService(DbConnection connection)
{
_connection = connection;
}
public async Task<IEnumerable<LegacySceneResponse>> GetByProgramScript(long programId, string scriptId)
{
object parameters = new
{
CodigoPrograma = programId,
CodigoRoteiro = scriptId
};
if (!ObjectValidation.IsInvalidAnyNullOrEmpty(parameters)) ;
return await _connection.QueryAsync<LegacySceneResponse>(GetScenesByScriptAndProgram.Query, parameters);
}}当测试尝试运行"QueryAsync“时,会出现错误。
有什么想法吗?
发布于 2020-08-30 03:18:14
https://stackoverflow.com/questions/63185949
复制相似问题