Entity Framework - web.config - reflection

Hi,

I have an nunit test harness in a web service, with a test checking whether a DAL function can (using the Entity Framework) get data from the database.

When I run the unit test with resharper I get an unhandled exception saying "The requested database * is not defined in configuration." The connection string is in the Web.Config, no doubt about it.

This was really annoying me, and I spent far too long trying to fix it when it seemed that all syntax was right, and on a whim tried it in the browser.

It worked. :s

It seems that when running the unit test, the Entity Framework can't read from the Web.Config (using Reflection?).

Is this normal??

Cheers!

3 comments

Hello Kenny
     Do those tests run fine using the original NUnit GUI/console runner? Thank you!

Andrey Serebryansky

Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0

Does exactly the same thing within NUnit's Runner GUI.

I don't know how the entity framework does it's thing, but since it works when browsing via the webserver it seems that running just the method on it's own out of context via NUnit (or resharper) it seems to lose it's ability to view info in the Web.Config?

Sounds crazy, but that's what it "feels" like. :s

Best,

K

0

As a workaround you can extract your tests into a separate project and provide the entity framework configuration inside the project's app.config file. Thank you!

Andrey Serebryansky

Support Engineer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"
0

Please sign in to leave a comment.