Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

How to reload app.config at runtime
mmcdow
#1 Posted : Wednesday, September 23, 2015 9:44:42 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 9/23/2015(UTC)
Posts: 1
Location: United States of America

Thanks: 1 times
Hi,

The SUT I am using looks in the app.config for a directory path. I am trying to test what happens if that path is invalid as part of a larger test suite. So at runtime, in the InitializeClassUnderTest method, I am rewriting that particular appsetting and creating an instance of the SUT, However, NCrunch has already loaded the app.config and that is the value that the SUT is finding, so my test fails.

Is there anyway to reload the appConfig in the NCrunch workspace or to configure NCrunch so that it does not load the app.config?

I appreciate an help I can get on this.

Thanks,
mmcdow
Remco
#2 Posted : Wednesday, September 23, 2015 10:50:15 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,979

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi, thanks for posting!

Without attempting to hack/override the .NET configuration system, I broadly know of two ways to achieve what you're trying to do:

1. Create a new application domain, specifying the path to a different (modified) .config file, and using this application domain to call into your SUT. A major drawback of doing this is that NCrunch code coverage won't work inside this isolated application domain. It also makes your initialisation much more complex.

2. Wrap the application configuration objects behind an abstraction of some sort that can be controlled by your test code. This is highly recommended and it is the standard approach for overriding configuration settings during a test run. As long as the SUT depends on the abstraction and not on the .NET configuration system, you can easily inject whatever you like without .NET getting in the way.
1 user thanked Remco for this useful post.
mmcdow on 9/24/2015(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.029 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download