Entity Framework 4 CTP 5 POCO - How to Unit Test my Repository<T>

◇◆丶佛笑我妖孽 提交于 2019-12-23 04:48:08

问题


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).

Thanks all.


回答1:


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.

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).

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.

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

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.



来源:https://stackoverflow.com/questions/4738477/entity-framework-4-ctp-5-poco-how-to-unit-test-my-repositoryt

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