I am looking for a way to 'detour' a single item in a configuration file with Moles. I can do this:
NameValueCollection appsettings = new NameValueCollection();
appSettings.Add("MyKey", "MyValue");
System.Configuration.Moles.MConfigurationManager.AppSettingsGet = () => this.appSettings;
This works fine, however the class which I am trying to test uses some other configuration settings including ConfigSections and the Moles detour seems to have broken this. I only want to replace a specific value, not the whole section. In TypeMock, I could do this:
Isolate.WhenCalled(() => ConfigurationManager.AppSettings["MyKey"]).WithExactArguments().WillReturn("MyValue");
When I mock the configurationManager using TypeMock, my test passes, but when I use the Moles version (which looks like it should do the same thing) it fails meaning that Moles must be affecting the ConfigurationManager class in a way which TypeMock doesn't.
Any help on how I can use moles to just behave in the way which TypeMock does would be greatly appreciated.