Click here to Skip to main content
12,897,945 members (86,205 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.8K views
Posted 14 Jun 2011

Changing App.Config on the fly for unit testing

, 14 Jun 2011 CPOL
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

You may also be interested in...

Pro
Pro

Comments and Discussions

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

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 14 Jun 2011
Article Copyright 2011 by EbenRoux
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid