Speedy is a simple easy to use Entity Framework unit testing framework
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Speedy.Samples.Tests
Speedy.Samples More progress Jun 26, 2018
Speedy.Tests
Speedy.Website
Speedy Migrated test projects to .NET Core Unit Test projects Jun 27, 2018
.gitignore More progress Jun 26, 2018
Build.ps1
IncrementVersion.ps1
LICENSE.md Added DynamicLinq. May 25, 2016
Prebuild.ps1
Publish.ps1 Updated publish profile. Jan 6, 2017
README.md
Speedy.pdn Added Speedy images. Oct 1, 2015
Speedy.png
Speedy.sln
Speedy.sln.DotSettings Fixed issue where items removed was not being cleared from the cache. Oct 17, 2015
Test.ps1 Migrated test projects to .NET Core Unit Test projects Jun 27, 2018

README.md

Speedy

Speedy is a simple easy to use Entity Framework unit testing framework.

Note: Version 5 is currently in beta testing.

Setup an interface to describe your database

public interface IContosoDatabase : IDatabase
{
	IRepository<Address, int> Addresses { get; }
	IRepository<Person, int> People { get; }
}

Setup your Entity Framework database

Version 5 for Entity Framework Core

public class ContosoDatabase : EntityFrameworkDatabase, IContosoDatabase
{
	public ContosoDatabase()
	{
		// Default constructor needed for Add-Migration
	}

	public ContosoDatabase(DbContextOptions contextOptions, DatabaseOptions options = null)
		: base(contextOptions, options)
	{
	}

	public IRepository<Address, int> Addresses => GetRepository<Address>();
	public IRepository<Person, int> People => GetRepository<Person>();
}

Version 4 for Entity Framework 6

public class ContosoDatabase : EntityFrameworkDatabase, IContosoDatabase
{
	public ContosoDatabase()
		: this("name=DefaultConnection")
	{
		// Default constructor needed for Add-Migration
	}

	public ContosoDatabase(string nameOrConnectionString, DatabaseOptions options = null)
		: base(nameOrConnectionString, options)
	{
	}

	public IRepository<Address, int> Addresses => GetRepository<Address>();
	public IRepository<Person, int> People => GetRepository<Person>();
}

Setup your Memory database

public class ContosoMemoryDatabase : Database, IContosoDatabase
{
	public ContosoMemoryDatabase(string directory = null, DatabaseOptions options = null)
		: base(directory, options)
	{
		Addresses = GetRepository<Address>();
		People = GetRepository<Person>();
	}

	public IRepository<Address, int> Addresses { get; }
	public IRepository<Person, int> People { get; }
}

Now you can write test that will run against EntityFramework and / or the Memory database

Preferable you'll write all your unit test using the memory database. You can then use the Entity Framework database for your integration tests.

This is a test for v5 for Entity Framework Core.

[TestMethod]
public void AddAddressTest()
{
	var options = new DbContextOptionsBuilder<ContosoDatabase>().UseSqlServer("server=localhost;database=Speedy;integrated security=true;").Options;

	foreach (var database in new IContosoDatabase[] { new ContosoDatabase(options), new ContosoMemoryDatabase() })
	{
		using (database)
		{
			database.Addresses.Add(new Address
				{
					City = "Greenville",
					Line1 = "Main Street",
					Line2 = string.Empty,
					Postal = "29671",
					State = "SC"
				});
			
			database.SaveChanges();
		}
	}
}

This is a test for v4 for Entity Framework 6.

[TestMethod]
public void AddAddressTest()
{
	var connectionString = "server=localhost;database=Speedy;integrated security=true;";

	foreach (var database in new IContosoDatabase[] { new ContosoDatabase(connectionString), new ContosoMemoryDatabase() })
	{
		using (database)
		{
			database.Addresses.Add(new Address
				{
					City = "Greenville",
					Line1 = "Main Street",
					Line2 = string.Empty,
					Postal = "29671",
					State = "SC"
				});
			
			database.SaveChanges();
		}
	}
}

Versions

  • v5 supports Entity Framework Core (beta testing)
  • v4 supports Entity Framework 6