0

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, as 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.

3
  • If your SQL CE or SQLExpress local mdb will have the same production schema, why couldn't you continue to use the production Entities and just swap out the connection string to point to the mdb instead of SQL server? Keep it simple. Commented Aug 5, 2011 at 18:27
  • @nithins: SQL CE has restrictions (e.g. it is unicode-only, and so has no such type as 'varchar') which require a transform of the EDMX file. Commented Aug 5, 2011 at 18:31
  • SQLExpress is a lot more full featured and still lightweight. Commented Aug 9, 2011 at 15:24

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The "fast integration" is meant to supplement, not replace, the "slow integration" story. Also, I don't intend on changing the .msl file. The SQL CE database will be generated from the EF context as a test initialization step. Thus it should be nearly identical to the production DB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.