如何编写模拟存储库来测试基于实体框架上下文构建的 WCF RIA 域服务
我需要编写一个测试层来测试我的 WCF RIA 域服务层,该层构建在实体框架上下文之上。我遇到过一些模式,建议使用存储库,然后使用域服务工厂来使用存储库实例来初始化域服务。 Vijay 的博客 (http://blogs.msdn.com/vijayu/archive/2009/06/08/unit-testing-business-logic-in-net-ria-services .aspx)。此实现的问题在于,它仅针对特定域对象(例如客户/产品)初始化存储库,但它无法提供创建可以返回我想要返回的任何对象的存储库的方法。
请建议这样做的正确方法是什么以及是否可行。
预先感谢,
马诺吉
I need to write a test layer to Test my WCF RIA Domain Service layer which is build on top of Entity Framework context. I have come across some patterns which suggest to use a repository and then use the Domain Service factory to intilize the domain service with a repository instance to use. One of the sample which fits the requirement is explained here on Vijay's blog(http://blogs.msdn.com/vijayu/archive/2009/06/08/unit-testing-business-logic-in-net-ria-services.aspx). The problem with this implementation is that it initilize the repository only for a specific Domain Object e.g. Customer/Product but it provides no way to create a repository which can return any object which i would like to return.
Please suggest what is the right way of doing this and whether it is possible or not.
Thanks in advance,
Manoj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过使用 RepositoryCollection 对象扩展示例来解决这个问题,该对象根据需要自动实例化 LinqToSqlRepositories,并且还允许手动插入模拟/存根存储库以进行单元测试。
然后,在您的域服务中,您可以像这样使用它:
I got around this issue by extending the sample with a RepositoryCollection object, which automatically instantiates LinqToSqlRepositories as needed, and also allows the insertion of mock/stub repositories manually for unit testing.
Then, in your domain service, you use it like so: