实现存储库模式并进行测试 [英] Implementing Repository pattern and doing Tests
问题描述
IQueryable< T>
而不是 IList< T>
)等为什么我仍然停滞不了,最终不能达到正确的水平。 所以:
-
我需要Repository模式在我的MVVM应用程序中应用IoC?
-
如果是,高效的资源库实现是什么到EF实体,这是一个很好的做法,更好的可测试?
-
如何测试我的存储库和UnitofWork行为?在内存库中进行单元测试?集成测试?
修改:根据答案我添加了第一个问题。 b $ b
Ayende Rahien有很多关于存储库的帖子 http://ayende.com/blog/search?q=repository 以及为什么在使用ORM时它是坏的。我认为存储库是要走的路。也许是在2004年。不是现在。 ORM已经实现了仓库。在EF的情况下,它是IDbSet。而DbContext是UnitOfWork。创建存储库以包装EF或其他ORM会增加很多不必要的复杂性。
进行与数据库交互的代码的集成测试。
I have read almost all articles about Repository pattern and different implementations of it. Many of them judged bad practices (ex: using IQueryable<T>
instead of IList<T>
) etc. that why i'm still stuck and couldn't end-up to the right one.
So:
Do I need Repository pattern to apply IoC in my MVVM applications ?
If yes, What is the efficient IRepository implementation to EF Entities which is a good practice and better testable ?
How can I test my Repositories and UnitofWork behavior ? Unit tests against in memory Repositories ? Integration tests ?
Edit : According to answers I added the first question.
Ayende Rahien has a lot of posts about repository http://ayende.com/blog/search?q=repository and why it is bad when you are using ORM's. I thought Repository was the way to go. Maybe it was, in 2004. Not now. ORM's already implement repository. In case of EF it is IDbSet. And DbContext is UnitOfWork. Creating a repository to wrap EF or other ORM's adds a lot of unnecessary complexity.
Do integration testing of code that will interact with database.
这篇关于实现存储库模式并进行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!