Skip to content

Instantly share code, notes, and snippets.

@TimHolzherr
Last active June 3, 2020 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TimHolzherr/84e394ace64dff308db4e6ed8649f130 to your computer and use it in GitHub Desktop.
Save TimHolzherr/84e394ace64dff308db4e6ed8649f130 to your computer and use it in GitHub Desktop.
Example of a efficient test
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