Click here to Skip to main content
12,360,217 members (62,608 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

4.3K views
Posted

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...

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.

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