Skip to content
Abstractions for C# code to aid testable code
C#
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Useful.Abstractions.Tests
Useful.Abstractions
.gitignore
LICENSE
README.md
Useful.Abstractions.nuspec
Useful.Abstractions.sln
appveyor.yml

README.md

Useful.Abstractions

Abstractions for C# .NET 4.5+ code to aid testable code

NuGet version

The current version only has abstractions for the C# System.ConfigurationManager and C# System.Configuration classes but I have added some additional methods to the interface.

Usually the configuration is injected in but for the examples below it is instantiated.

HasSetting - Checks to see if the configuration has a given setting

e.g.

 var wrapper = new ConfigurationManagerWrapper();
 if(wrapper.HasSetting("IsValue"))
 {
    // Do some logic
 }

this can also be used on a section

e.g.

 var wrapper = new ConfigurationManagerWrapper();
 if(wrapper.HasSetting("IsValue", "mySection"))
 {
    // Do some logic
 }

HasConnectionString - The similar to HasSetting but for the connection strings

e.g.

 var wrapper = new ConfigurationManagerWrapper();
 if(wrapper.HasConnectionString("default"))
 {
    // Do some logic
 }

GetSetting - Get the setting from the configuration and convert it to the desired type

e.g. if the configuration had

 <appSettings>
   <add key="Timeout" value="10"/>
 </appSettings>
 var wrapper = new ConfigurationManagerWrapper();
 var timeout = wrapper.GetSetting<int>("Timeout");

timeout would be 10

GetSettingOrDefault - Get the setting from the configuration but if there is no entry or no value return the default

e.g. with no configuration entry

 var wrapper = new ConfigurationManagerWrapper();
 var timeout = wrapper.GetSettingOrDefault<int>("Timeout");

timeout would be 0

The default can also be a given value

e.g.

 var wrapper = new ConfigurationManagerWrapper();
 var timeout = wrapper.GetSettingOrDefault<int>("Timeout", -1);

timeout would be -1

You can’t perform that action at this time.