What's the point of in memory IDbSet?

梦想与她 提交于 2019-12-12 21:23:37

问题


I see one of the ways people test solutions based on EntityFramework (code first) is to create interface for their custom context that contains properties of type IDbSet (instead of DbSet). Then in unit tests they use InMemoryDbSets.

I'm new to EntityFramework and that seemed like great way to do it. But it doesn't work at all does it? When we are using InMemory DbSets we can create and run queries that use any of the properties of our entity objects. Even if those are calculated properties. But during runtime the same queries will throw "The specified type member 'PropertyName' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.".

So either I don't understand something (probably) or it is not possible to unit test at all if you are using custom context with IDbSets.


回答1:


Ok I did a lot of research and seems that the only reasonable way (if You want to expose IDbSet) is to do integration testing. Just forget about unit testing it.

Ladislav Mrnka summarized it here very nicely. Fake DbContext of Entity Framework 4.1 to Test

Also I saw on Ayende's blog (http://ayende.com/) that this is the way he is doing it.



来源:https://stackoverflow.com/questions/12028270/whats-the-point-of-in-memory-idbset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!