Tuesday, 22 January 2008

Unit testing ADO Entity Framework


I was playing with the ADO.NET entity framework beta 3 that I installed on the Rosario November 2007 CTP and I had some problems making unit tests. I kept getting the follwing error.
System.Data.MetadataException: The specified metadata path is not valid. A valid
path must be either an existing directory, an existing file with extension
'.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource

When you use the wizard to create a model several "hidden" files are generated for you; .csdl, .ssdl, and .msl files. The information contained in these files is encapsulated in the .edmx file but the files .csdl, .ssdl, and .msl files reside in the bin\Debug or bin\Release directories of the solution. Apperently these files are still necessary at run-time. There not embedded in the assembly.

In a connectionstring you specify these files in the metadata part :

When you're using for example the VS test framework, the test infrastructure copies the assemblies to a certain test folder (isolation). If you have an app.config or use custom files in your code, you must assure that the test framework put these file in that particular test folder.

Now the .csdl, .ssdl, and .msl are also not copied to that test folder automatically. I used the deployment feature of the VS test environment. I specified the three files and now there copied to the test folder.

Maybe there are other ways? Let me know!

Best regards,



--rj said...


You should be able to solve the problem by embedding the three metadata files. See http://oakleafblog.blogspot.com/2008/01/linq-and-entity-framework-posts-for_22.html for more details.


Anonymous said...

Have you actually gotten unit testing to work or are you just experminting? I've been watching this blog. I've been waiting for a follow up to some tests on ChrisDoesDev.com from october (site seems to be down at the moment). He was stuck on mock objects.

Julie Lerman

anowak said...

Hello Roger,

Thank you for commenting!

Julie's solution is indeed far better (http://www.thedatafarm.com/blog/2007/12/15/EmbeddingEDMSchemaFilesInEntityFrameworkBeta3.aspx).

Thank you for you pointing me to the solution.

Best regards,


anowak said...

Hello Julie,

Thanks for your interest!

I'm just experimenting with Entity framework (and Linq to SQL). I trying to learn them (and compare them with NHibernate solutions and dataSet oriented solutions).

I use unit testing just as an infrastucture to use the Entity framework generated code ( or Linq to SQL generated code) instead of writing a Winforms demo app.

I'm not familiar with ChrisDoesDev.com ( probably I should have been :-) Maybe the creator has another site/blog ?

Regarding mocking : I made a little test with Rhino.Mock. But I'm NOT mocking any Entity Framework generated code directly. I provide access through repositories (or DAOs if you prefer). I just then mock those. Of course you could argue what's the use of shielding once again the data access code ....

Best regards,


Noa said...

Your solution is the only thing that worked for my unit tests project, so thanks :)
(somehow, my application is managing with Julie's solution, but the unit tests don't. I have no idea why.)

Gabe Co Hadwin said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.