CaveTester.Bogus 1.0.0-beta2

Test data generation helper

This is a prerelease version of CaveTester.Bogus.
Install-Package CaveTester.Bogus -Version 1.0.0-beta2
dotnet add package CaveTester.Bogus --version 1.0.0-beta2
paket add CaveTester.Bogus --version 1.0.0-beta2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Cave Tester

Cave Tester is a lightweight testing library that help you manage your database and generate mock data.

Features

  • Automatic database save and restore
  • Determinist id generator
  • Rules sets for object generation with Bogus

Planned features

  • Database pooling for easier parallel testing
  • Some methods to test entity <=> dto mapping

Quickstart

public class FooTests : Tester
{
	private readonly DbContext _dbContext;

	public FooTests()
	{
		// init your context here

		// Create a snapshot of the database before the test begin
		SaveHandler.Add(new SqlServerDbSnapshot(_dbContext.Database));
	}

	[Fact]
	public async Task ShouldFoo()
	{
		// Generate 5 Person with a random name
		await _dbContext.Generate<Person>(5, (faker, person) => person.Name = faker.Lorem.Word())
				 .SaveChangesAsync();

		// method to test
		// assertions

		// The database will automaticly be restored in a clean state from the snapeshot, wich will then be deleted
		// This happen even if the test fails
	}
}

public class Person
{
	public string Name { get; set; }
}

Example

See a complete example here

Tests

To build and run the tests you need to create a database using the script CaveTester.Tests/create_database.sql and configure the connection string CaveTester.Tests/DbSaverTests.cs

Cave Tester

Cave Tester is a lightweight testing library that help you manage your database and generate mock data.

Features

  • Automatic database save and restore
  • Determinist id generator
  • Rules sets for object generation with Bogus

Planned features

  • Database pooling for easier parallel testing
  • Some methods to test entity <=> dto mapping

Quickstart

public class FooTests : Tester
{
	private readonly DbContext _dbContext;

	public FooTests()
	{
		// init your context here

		// Create a snapshot of the database before the test begin
		SaveHandler.Add(new SqlServerDbSnapshot(_dbContext.Database));
	}

	[Fact]
	public async Task ShouldFoo()
	{
		// Generate 5 Person with a random name
		await _dbContext.Generate<Person>(5, (faker, person) => person.Name = faker.Lorem.Word())
				 .SaveChangesAsync();

		// method to test
		// assertions

		// The database will automaticly be restored in a clean state from the snapeshot, wich will then be deleted
		// This happen even if the test fails
	}
}

public class Person
{
	public string Name { get; set; }
}

Example

See a complete example here

Tests

To build and run the tests you need to create a database using the script CaveTester.Tests/create_database.sql and configure the connection string CaveTester.Tests/DbSaverTests.cs

Release Notes

Add SourceLink support
Add Jetbrain nullable attributes

Version History

Version Downloads Last updated
1.0.0-beta2 98 11/30/2018
1.0.0-beta1 84 9/26/2018