开发者

Entity Framework, SQL CE 4.0, and DB Test Automation

开发者 https://www.devze.com 2023-03-26 00:15 出处:网络
I want to perform \"fast integration\" (aka \"desktop integration\") tests of a project using EF 4.0/4.1 connected to SQL Server 2008.This means that I need to swap out the dependency upon SQL Server

I want to perform "fast integration" (aka "desktop integration") tests of a project using EF 4.0/4.1 connected to SQL Server 2008. This means that I need to swap out the dependency upon SQL Server 2008 with something more light-weight. I will like to swap-in SQL CE 4.0, a开发者_C百科s executed from mstest or mbunit.

I have already determined how I need to transform the EDMX file to make it compatible with SQL CE 4.0. My intention is to generate the EDMX, for CE use, from a pre-build event in my mstest or mbunit project. But what I need to know is how I convince EF to use my newly generated EDMX file, from within my test project, instead of the production EDMX file? I don't think it is as simple as changing my connection string.

I suspect the EDMX file is embedded into the built assemblies as a resource, so maybe this question is about how to swap a resource before it gets compiled into a DLL. If, however, I'm going about this incorrectly, I'd just like guidance of how to achieve my goal.


The problem is that EDMX is only design time feature. Having a new EDMX means nothing. EDMX is divided during compilation to three separate files: .ssdl, .msl, .csdl. These files specifies the real mapping (you need to change only .ssdl to swap SQL Server to SQL Server CE). So the simplest way for you is to set up your model to generate files to build directory instead to add them as resources. After that you just need to use modified .ssdl file and same .msl and .csdl files in your test projects (paths to files are part of the connection string).

Anyway I don't like that idea. You will do integration tests on different database with different mapping definition = it smells like you will test another application. Integration tests are supposed to be slow so run them against your targeted environment. It is truth that SQL Server and SQL Server CE are very close and replacement for testing should work but still there are differences.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号