Skip to content
Easy fakes for Entity Framework 6
C# Batchfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
UglyToad.FakeItEasy.EntityFrameworkFakes.Integration
UglyToad.FakeItEasy.EntityFrameworkFakes.Net40.Tests
UglyToad.FakeItEasy.EntityFrameworkFakes.Net40
UglyToad.FakeItEasy.EntityFrameworkFakes.Tests
UglyToad.FakeItEasy.EntityFrameworkFakes
tools
.gitattributes
.gitignore
LICENSE
UglyToad.FakeItEasy.EntityFrameworkFakes.nuspec
UglyToad.FakeItEasy.EntityFrameworkFakes.sln
nuget-pack.bat
readme.md

readme.md

Entity Framework Fakes

This library provides convenience faking methods for Entity Framework 6 using FakeItEasy.

Usage

Assuming you have some kind of DbContext:

public class MyContext : DbContext
{
	// My DbSets...
}

You can get a faked instance of the context with:

var context = ContextFaker.CreateContext<MyContext>();

The DbSets can then be configured using:

// ContextFaker.ContextReturnsDbSet(lambda expression accessing DbSet, list of test data)
ContextFaker.ContextReturnsDbSet(() => context.Acorns, new List<Acorn>());

If you use DbSet.Find() on your entity the ContextFaker will attempt to use properties with the name "Id" or "ClassName" + "Id". If you need to configure a property with a different name, use the following method:

ContextFaker.AddIdGetterForType((T entity) => entity.SomeWeirdIdProperty); 

Notes

The faked set supports the following operations:

  • Add
  • AddRange
  • Attach
  • Find
  • FindAsync
  • Remove
  • RemoveRange

Any queries using Include() will effectively ignore the Include and just use the data passed in to the creation of the fake DbSet.

Be aware that any data passed into ContextReturnsDbSet() will be changed by operations against the DbSet so ensure unexpected changes to the list do not affect your tests.

Implementation

This library adapts this implementation of Entity Framework mocking.

You can’t perform that action at this time.