实体框架是否有内存提供程序? [英] Is there an in-memory provider for Entity Framework?
问题描述
我可以使用Rhino Mock模拟实体框架,但是是不够的我会告诉我们什么实体返回给我。这样既不会测试where子句也不会测试.Include()语句。我想确保我的where子句只匹配我打算的行,没有其他的。我想确保我已经要求我需要的实体,没有我没有。
例如:
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)
其中c.CustomerID == customerId
选择c;
return customers.FirstOrDefault();
}
}
如果我嘲笑ObjectQuery返回已知的客户填充有订单,我怎么知道CustomerService有权利的where子句和包含?我宁愿插入一些客户行和一些订单行,然后断言正确的客户被选中并且订单被填充。
目前还没有一个用于EF的内存提供商,但是如果你看看Highway.Data,它有一个基本的抽象接口和一个InMemoryDataContext。
I am unit testing code written against the ADO .NET Entity Framework. I would like to populate an in-memory database with rows, and make sure that my code retrieves them properly.
I can mock the Entity Framework using Rhino Mocks, but that would not be sufficient. I would be telling the query what entities to return to me. This would neither test the where clause nor the .Include() statements. I want to be sure that my where clause matches only the rows I intend, and no others. I want to be sure that I have asked for the entities that I need, and none that I don't.
For example:
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();
}
}
If I mock the ObjectQuery to return a known customer populated with orders, how do I know that CustomerService has the right where clause and Include? I would rather insert some customer rows and some order rows, then assert that the right customer was selected and the orders are populated.
There is not currently a in memory provider for EF, but if you take a look at Highway.Data it has a base abstraction interface and an InMemoryDataContext.
Testing Data Access and EF with Highway.Data
这篇关于实体框架是否有内存提供程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!