I'm attempting to write a test for the code behind a web service. This code lives in a separate class library called from the service itself. This class library uses ConfigurationManager
to get its connection strings, normally when you run the web service those are populated by the web service's web.config
. However, when I run it from my test code they throw null
exceptions.
I've trolled around the net for answers for a while now and attempted several fixes for roughly similar problems, but nothing worked. (Nothing was exactly my situation.)
It depends on the version of Visual Studio that you have, but if you have VS 2010 you can use Moles to mock static classes and in VS 2012 you have Microsoft Fakes.
Nevertheless, as Joachim Isaksson said in his comment, if you are actually doing a Unit Test, you could wrap access ConfigurationManager to the through an interface and a wrapper, and just mock the interface.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With