0

I'm using Entity Framework 6 with Autofac for Dependency injection.

Here is my database context wrapper code:

public interface IOliveDataContext
{
    OlivesHealthEntities Context { get; }
}

Here is its implementation:

public class OliveDataContext : IOliveDataContext
{
    public OlivesHealthEntities Context => new OlivesHealthEntities();
}

I wonder if there is anyway to wrap the default context with in-memory database connection for unit testing or I have to connect to an other database to do the test.

Can anyone help me please ?

P/s : I've read some tuts about unit testing with EF6, they always write context interfaces for this, its different from my current app implementation.

Redplane
  • 2,971
  • 4
  • 30
  • 59
  • You might find it easier to [mock the DbContext](https://msdn.microsoft.com/en-us/library/dn314429.aspx), which would allow you to customise behaviour and assert conditions. If you wish to perform integration testing, then you can [set up your database in a controlled manner](http://stackoverflow.com/a/22691703/1269511) to allow you to test your mapping logic. – Chima Osuji Aug 09 '16 at 14:53

1 Answers1

1

If you are talking about in-memory database instance, there is Effort for that purpose. It simulate real database using entity framework engine on memory. It has limitation though, it couldn't simulate stored procedure, view, and trigger.

Ariwibawa
  • 627
  • 11
  • 23