whats a good way to test the settings (especially keys) in web.config? I think its not really testable with 开发者_StackOverflow社区NUnit, or is it?
Example: <add key="SomeKey" value="SomeValue" />
Thanks for ideas :-)
How do you mean "test"? There's no real value, that I can see at least, in running tests against a .config file, given that there's no code of yours actually executing, unless you've written a custom ConfigSectionHandler?
If you have a defined set of keys that your application requires, you might consider it worthwhile to wrap calls to System.Configuration.ConfigurationManager
in a configuration helper class that exposes your application specific configuration, parses values into their appropriate datatypes and so on. That would be something that would be worth testing, but not the web.config file itself. For example:
using System;
using System.Configuration;
namespace MyApplication
{
public sealed class MyApplicationConfiguration
{
public int NumberOfConnectionAttempts {get; private set;}
public string ServerName {get; private set;}
public MyApplicationConfiguration()
{
NumberOfConnectionAttempts = Convert.ToInt32(ConfigurationManager.AppSettings["ConnectionAtttempts"];
ServerName = ConfigurationManager.AppSettings["ServerName"];
}
}
}
You can create a class that is responsible for configuration parameters and test methods of that class.
精彩评论