Tuesday, 22 January 2008

Unit testing ADO Entity Framework

Hello,

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 :
connectionString="metadata=.\Northwind.csdl.\Northwind.ssdl.\Northwind.msl

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,

Alexander

10 comments:

Roger Jennings (--rj) said...

Alexander,

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.

--rj

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,

Alexander

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,


Alexander

Noa said...

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

Richard Majece said...

It's clear for me that this information will be useful for students in college. Here you can read a lot about writing research paper

Ramona Brekke said...

My research about How long should a resume be in 2019? can be interesting not only for job seekers but also for last year students. If you make a well-written resume from the very beginning it'll help you to dave a kt of time in the future.

katebrouwn said...

It is no secret that a lot of students think, “I need to find someone to type my essay for me.” EliteWritings.com is at your service. The only thing you need to do is place your order on our webpage. Remember to provide explicit paper directions, i.e. the topic, deadline, page number, and other items

Anonymous said...
This comment has been removed by the author.
Anonymous said...

As Shelley's Ozymandias vividly demonstrates, the ambitions to conquer the time are vain and pathetic. It is symbolism in Ozymandias and the example of a book report of it https://bestwritingservice.co.uk/essays/book-report/main-idea-in-ozymandias.html