A framework to simplify your tests
Squadron is a helpful framework which enables you to write tests against dependent services without any overhead. Squadron can provide you isolation in tests through Container Providers or support for all other services through Cloud Providers.
- Install
- Install
Install the Squadron nuget package for MongoDB (or other supported service) within your test project:
dotnet add package Squadron.Mongo
- Access
- Access
Inject the MongoResource into your test class constructor:
public class AccountRepositoryTests
: IClassFixture<MongoResource>
{
private readonly MongoResource _mongoResource;
public AccountRepositoryTests(
MongoResource mongoResource)
{
_mongoResource = mongoResource;
}
}
- Use
- Use
In your test use MongoResource to create a database and initialize your repository:
[Fact]
public void CreateAccount_AccountExists()
{
// arrange
var database = _mongoResource.CreateDatabase();
var accountRepository = new AccountRepository(database);
var account = new Account();
// act
var addedAccount = accountRepository.Add(account);
// assert
Snapshot.Match(addedAccount);
}