Click here to Skip to main content
11,482,039 members (68,086 online)
Click here to Skip to main content

Tagged as

Changing App.Config on the fly for unit testing

, 14 Jun 2011 CPOL 3.4K
Rate this:
Please Sign up or sign in to vote.
An alternative is to abstract the settings that you intend to use.So instead of changing your app.config on the fly, simply change a mock or the instance values of the configuration object.For example:public interface IApplicationConfiguration{ string MaybeAFolderINeed { get; } ...

An alternative is to abstract the settings that you intend to use.

So instead of changing your app.config on the fly, simply change a mock or the instance values of the configuration object.

For example:

public interface IApplicationConfiguration
{
    string MaybeAFolderINeed { get; }
    string MyConnectionString { get; }
}

Then you could mock it and return the relevant values.

public class ClassRequiringConfig
{
    public ClassRequiringConfig(IApplicationConfiguration configuration) { ... }
    public ClassRequiringConfig()
           : this(new DefaultApplicationConfigurationImpl()) { ... }
}

Just a thought.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

EbenRoux
Architect
South Africa South Africa
No Biography provided

Comments and Discussions

 
GeneralThis is a good solution in case if you start creating unit t... Pin
NeoPunk18-Jun-11 23:13
memberNeoPunk18-Jun-11 23:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 14 Jun 2011
Article Copyright 2011 by EbenRoux
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid