Example of a efficient test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using Xunit; | |
using Bogus; | |
using AutoBogus; | |
using FluentAssertions; | |
using Squadron; | |
namespace Tests | |
{ | |
public class PersistenceTest : IClassFixture<MongoResource> | |
{ | |
private readonly Repository _repository; | |
private readonly IAutoFaker _fuzzer = AutoFaker.Create(); | |
public PersistenceTest(MongoResource mongoResource) | |
{ | |
Randomizer.Seed = new Random(42); | |
_repository = new Repository(mongoResource.CreateDatabase()); | |
} | |
[Fact] | |
public async Task Add_Retrieve_Equivalent() | |
{ | |
// Arrange | |
DomainModel model = _fuzzer.Generate<DomainModel>(); | |
await _repository.AddAsync(model); | |
// Act | |
DomainModel result = await _repository.GetAsync(model.Id); | |
// Assert | |
result.Should().BeEquivalentTo(model); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment