Elasticsearch
Install
Install the Squadron nuget package for Elasticsearch within your test project:
dotnet add package Squadron.Elasticsearch
Access
Inject ElasticsearchResource into your test class constructor:
public class AccountRepositoryTests
: IClassFixture<ElasticsearchResource>
{
private readonly ElasticsearchResource _elasticsearchResource;
public AccountRepositoryTests(
ElasticsearchResource elasticsearchResource)
{
_elasticsearchResource = elasticsearchResource;
}
}
Use
Use ElasticsearchResource to create a database and initialize your repository:
[Fact]
public async Task CreateAccount_AccountExists()
{
// arrange
var accountRepository = new AccountRepository(_elasticsearchResource.Client);
var account = new Account();
// act
var addedAccount = accountRepository.Add(account);
// assert
Snapshot.Match(addedAccount);
}