实体框架4 CTP 5 POCO - 如何单元测试我的存储库< T> [英] Entity Framework 4 CTP 5 POCO - How to Unit Test my Repository<T>

查看:168
本文介绍了实体框架4 CTP 5 POCO - 如何单元测试我的存储库< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是另一个问题的第二部分实体框架4 CTP 4 / CTP 5通用存储库模式和单元可测试),其中我询问如何使用EF 4 POCO实现通用存储库模式。现在我的存储库正在运行,我想知道如何单元测试我的存储库(TDD或BDD)。

This is the 2nd part of another question Entity Framework 4 CTP 4 / CTP 5 Generic Repository Pattern and Unit Testable), where I asked how to implement a generic repository pattern using EF 4 POCO. Now that my repository is working, I would like to know how to unit test my Repository (TDD or BDD).

感谢所有。

推荐答案

我用SpecFlow写了一些博客文章。但是,当它复杂时,这是一场灾难。

Hey I wrote some blog posts on doing this with SpecFlow. But that was a disaster when it got complex.

我试图实现一个也是灾难的测试库。尝试复制数据上下文的工作方式不是一个聪明的想法。

I tried to implement a testing repository which was also a disaster. Trying to replicate how the data context work is not a smart idea.

但是,您可以从错误中学习,并开始乐趣。我学到的是使用轻量级或内存中的数据库(SQLite)。

But you learn from your mistakes and have fun along the way. What I learnt was to use a light-weight or in-memory database (SQLite).

所以我一定会说使用SQLite数据库,如果你可以使它工作与EF代码优先。我不能这样做,所以我去了一个SQL CE紧凑版本。即使在测试中,它的运行速度也非常快。

So I would definitely say to use a SQLite database if you can get it working with EF Code First. I wasn't able to do this, so I went with a SQL CE compact edition. It runs amazingly quick, even in testing.

您可能知道这篇博客文章,但重新检查步骤4. http://weblogs.asp.net/scottgu/archive /2010/07/16/code-first-development-with-entity-framework-4.aspx

You probably know all about this blog post, but re-check step 4. http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

所以在本质上,我在我的最近的项目是要有一个单独的数据库SQL CE 4.0紧凑版本进行测试。超快速,无投诉。

So in essence, all I did on my most recent project was to have a separate database SQL CE 4.0 compact edition for testing. Super quick and no complaints.

这篇关于实体框架4 CTP 5 POCO - 如何单元测试我的存储库< T>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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