0

I try test my Entity class, but i always get a Failure:

System.Data.MetadataException:
Unable to load the specified metadata resource.

I think the problem is in connection string and App.config. I try a lot of stuff: add something to build events, changing config name, copy the config file into solution folder, project folder, project_folder/bin/debug, again change a lot of names... but it still doesn't work.

I have a "AppProject" solution containing 3 projects:

  • "Entity"
  • "WebTest"
  • "MVCApp"

The Entity project has a .edmx file, and simple POCO classes. When I add the connection string from the Entity/App.config into MVCApp/Web.config, the "MVCApp" and database works fine.

When I copy the Entity/App.config into WebTest/App.config it doesn't work. I don't know where the problem is.

I use a Visual NUnit, but when I try turn on in NUnit still doesn't work.

My App.config:

<connectionStrings>
  <add name="UserDB"
       connectionString="metadata=res://*/Model.Entity.csdl|
                                  res://*/Model.Entity.ssdl|
                                  res://*/Model.Entity.msl;
                         provider=System.Data.SqlClient;
                         provider connection string=
                                  &quot;Data Source=.\SQLExpress;
                                  Initial Catalog=TestDB;
                                  Integrated Security=True;
                                  MultipleActiveResultSets=True&quot;"
       providerName="System.Data.EntityClient" />
  <!-- NOTE: line breaks in the above connection string have been inserted only
             for better legibility. -->
</connectionStrings>
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
user634199
  • 91
  • 2
  • 5
  • 5
    If you're using database resources, then you're essentially not creating a Unit test, but an Integration test. You should mock the database connection for your unit tests. – Prutswonder Mar 25 '11 at 09:41
  • Oo thanks for answer. Before, when i test DB i always start transaction, do something on db, check result and rollback transaction. – user634199 Mar 25 '11 at 10:02
  • Do you reference Entity project in WebTest project? – Ladislav Mrnka Mar 25 '11 at 10:24
  • Naturally, i use poco class from Entity project in WebTest project :) – user634199 Mar 25 '11 at 10:35
  • 1
    The purpose of a Unit Test is to test your code, not the data framework your code is using. That's why you need to mock the database connection, so you can fake (and test) any connection issues. Using a real database connection in a unit test is bad practice. – Prutswonder Mar 25 '11 at 10:38
  • Thanks. I have a UserDB class who extends ObjectContext class and implement my IUserContext interface. The interface contains e.g. ObjectSet. You think in Unit Test don't test DB, mock the IUserContext and put into UserRepository class and test only repository patter class ? – user634199 Mar 25 '11 at 10:53
  • Possibly a duplicate of this question: http://stackoverflow.com/questions/1074337/metadataexception-when-using-entity-framework-entity-connection – Pedro Mar 25 '11 at 15:00

2 Answers2

1

See my answer nunit and configs You need to tell nunit what the name of the config file is. it looks for namespace.config by default it seams

Community
  • 1
  • 1
skyfoot
  • 20,629
  • 8
  • 49
  • 71
0

Run the webtest see what processor runs in task manager. Mine was QTAgent32_40, go to the configuration file usually under C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE. Look for the config file named "QTAgent32_40.exe.config". edit it with notepad and copy paste your connection string into there. That did the trick for me.