Is there an Entity Framework in-memory provider?

entity-framework rhino-mocks

Question

I'm testing code that was developed for the ADO.NET Entity Framework in a unit test. I want to add entries to an in-memory database and make sure that my code can correctly retrieve them.

Rhino Mocks can be used to simulate the Entity Framework, but that wouldn't be enough. I would instruct the query on which entities it should return to me. This wouldn't put the where clause or the to the test. Include() commands. I want to confirm that just the rows I plan to match are included in my where clause. I want to be sure that I have only asked for the things I really need.

For instance:

class CustomerService
{
    ObjectQuery<Customer> _customerSource;
    public CustomerService(ObjectQuery<Customer> customerSource)
    {
        _customerSource = customerSource;
    }
    public Customer GetCustomerById(int customerId)
    {
        var customers = from c in _customerSource.Include("Order")
            where c.CustomerID == customerId
            select c;
        return customers.FirstOrDefault();
    }
}

How would I be able to verify that CustomerService has the appropriate where clause and Include if I simulate the ObjectQuery to return a known customer filled with orders? I would prefer add a few customer and order rows before claiming that the correct customer was chosen and the orders were filled.

1
38
2/22/2009 4:39:02 PM

Accepted Answer

Although there is presently no in memory provider for EF, Highway.Data offers an InMemoryDataContext and a basic abstraction interface.

Highway.Data testing data access and EF

7
5/16/2014 12:16:58 AM

Popular Answer

In EF7, an InMemory provider is present (pre-release).

You may read about it in the Repo EF on GitHub or use the NuGet bundle (access source).



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow