实现存储库模式并进行测试 [英] Implementing Repository pattern and doing Tests

查看:227
本文介绍了实现存储库模式并进行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了几乎所有关于Repository模式的文章及其不同的实现。他们中的许多人判断不良做法(例如:使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆