1

I'm building a new application with EF4. The EF code is in it's own assembly along with the repository code. I'm trying to do some unit testing with Visual Studio's MSTest, but I'm have trouble getting started. My code is -

string s = "metadata=res://*/DataModels.MonitorUrlEf.csdl|res://*/DataModels.MonitorUrlEf.ssdl|res://*/DataModels.MonitorUrlEf.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source=TOM-VAIO;Initial Catalog=WebMonDb4;Integrated Security=True;Pooling=False;MultipleActiveResultSets=True\"";  
var DbContext = new WebMonDb4Entities(s);

WebMonDb4Entities is the EF Context created by the EF designer. I'm putting the connection string in a variable so I don't have to deal with the issues of where the connection files are during the testing. The contents of the string are copied from the app.config file in the project where the EF designer code is.

The error is "Unable to load the specified metadata resource." I've done some research and this should work. Any suggestions?

photo_tom
  • 7,292
  • 14
  • 68
  • 116
  • Have you taken a look at this: http://stackoverflow.com/questions/689355/metadataexception-unable-to-load-the-specified-metadata-resource/2294308#2294308 – Rytmis Jan 01 '11 at 21:06
  • The answer worked. Actually, a very elegant piece of code. If you make this comment an answer, I'll give you the credit. – photo_tom Jan 01 '11 at 23:15

2 Answers2

1

Looks like your problem might get fixed by adding fully-qualified namespaces to your EDMX references, as documented here. :-)

Community
  • 1
  • 1
Rytmis
  • 31,467
  • 8
  • 60
  • 69
0

You can add/copy your working config file for unit test project. Or copy/create your connection string element in it.

And from some research I find that better to create instance of EntityConnection and use it.

Also check some discussion here on same topic.

indiPy
  • 7,844
  • 3
  • 28
  • 39
  • Neither option works. Adding the config file was one that you would think that would work, but it didn't. – photo_tom Jan 01 '11 at 19:59