Eine dbConnection mit Nunit/Nsubstitute/Autofixure und InsightDatabase verspottenC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Eine dbConnection mit Nunit/Nsubstitute/Autofixure und InsightDatabase verspotten

Post by Anonymous »

Wir verwenden Nunit, Nsubstitute und Autofixure, um eine Repository -Klasse zu testen, die auf der Insight -Datenbank aufgebaut ist ... < /p>

Code: Select all

[TestFixture]
public class CalculationResultsRepositoryTests
{
private IFixture _fixture;

private IDbConnection _connection;
private CalculationResultsRepository _calculationResultsRepository;

[SetUp]
public void Setup()
{
_fixture = new Fixture().Customize(new AutoConfiguredNSubstituteCustomization());
_connection = _fixture.Freeze();
_calculationResultsRepository = _fixture.Create();
}

[Test]
public void TestReturnsPagedCalculationResults()
{
//Arrange
var financialYear = _fixture.Create();
var pagedResults = _fixture.Create();
_connection.QueryAsync(Arg.Any(), Arg.Any(), Arg.Any()).Returns(pagedResults);

//Act
var result = _calculationResultsRepository.PagedListAsync(financialYear);

//Assert
Assert.IsInstanceOf(result);
}
}
< /code>

Wenn wir den Test ausführen > System.reflection.targetInvocationException: Ausnahme wurde durch das Ziel eines Aufrufs ausgelöst. (Arg.is, arg.any) sollte nur anstelle von Mitgliedern Argumenten verwendet werden. Verwenden Sie nicht in einer Returns () -Antage () oder irgendwo anders außerhalb eines Mitgliedsaufrufs. Falsche Verwendung:
sub.mymethod ("hi"). Returns (arg.any ()) < /p>
< /blockquote>

Wir sind bei einem gewissen Verlust mit wie zu Beheben />public static Task QueryAsync(this IDbConnection connection, string sql, object parameters, IQueryReader returns, CommandType commandType = CommandType.StoredProcedure, CommandBehavior commandBehavior = CommandBehavior.Default, int? commandTimeout = default(int?), IDbTransaction transaction = null, CancellationToken? cancellationToken = default(CancellationToken?), object outputParameters = null);
< /code>

Weiß jemand, wie man dies erfolgreich verspottet? ist das: < /p>

var results = await _connection.QueryAsync("GetCalculationResults", new { FinancialYearId = financialYearId, PageNumber = pageNumber, PageSize = pageSize },
Query.ReturnsSingle()
.ThenChildren(Some.Records));

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post