Package | Last version |
---|---|
Integra.DbExecutor |
Abstractions for integration tests:
Branch | Build status |
---|---|
master | |
dev |
AppVeyor Nuget project feed: https://ci.appveyor.com/nuget/integra-ksjcb4t7lhvd
Project | Dependency |
---|---|
Integra.DbExecutor | DbConn.DbExecutor.Dapper |
- Install this package to your project with integration tests:
Install-Package Integra.DbExecutor
- Create integration test class and inherit it from
DbIntegrationTest
class and be sure that you override theInit
method and add attribute from you favorite test framework:
using NUnit.Framework
[TestFixture]
[Category("Integration test")]
public class CreateUserCommandTest : DbIntegrationTest
{
private CreateUserCommand CreateTestedCommand(IDbExecutor dbExecutor)
{
return new CreateUserCommand(dbExecutor)
}
[SetUp] // NUnit
//[TestInitialize] // MS Test
public override void Init()
{
base.Init();
}
[Test]
public void Execute__CreateNewUserSuccess()
{
var connectionStringToDb = "data-source:...";
using (var dbExecutor = CreateTransactionalDbExecutor(connectionStringToDb))
{
// Arrange
var command = CreateTestedCommand(dbExecutor);
var user = new User();
// Act
var createResult = command.Execute(user);
// Assert
Assert.IsTrue(createResult.Success());
}
}
}
- Or you can create your own base integration class and inherit it from
DbIntegrationTest
class:
using NUnit.Framework;
//...
public abstract class IntegrationTest : DbIntegrationTest
{
// Set attribute for init method from you favorite test framework
[SetUp] // NUnit
//[TestInitialize] // MS Test
public override void Init()
{
base.Init();
}
protected string ConnectionString => "data-source:...";
protected IDbExecutor CreateDbExecutor()
{
return CreateDbExecutor(ConnectionString);
}
protected IDbExecutor CreateTransactionalDbExecutor()
{
return CreateTransactionalDbExecutor(ConnectionString);
}
}
- Then create integration test class and inherit it from your own base integration test:
using NUnit.Framework
[TestFixture]
[Category("Integration test")]
public class CreateUserCommandTest : IntegrationTest
{
private CreateUserCommand CreateTestedCommand(IDbExecutor dbExecutor)
{
return new CreateUserCommand(dbExecutor)
}
[Test]
public void Execute__CreateNewUserSuccess()
{
using (var dbExecutor = CreateTransactionalDbExecutor())
{
// Arrange
var command = CreateTestedCommand(dbExecutor);
var user = new User();
// Act
var createResult = command.Execute(user);
// Assert
Assert.IsTrue(createResult.Success());
}
}
}