Hi,
I am trying to Mock System.Configuration.ConfigurationSettings
...
Is it a problem mocking sealed classes?
There is no problem mocking sealed classes, the problem is that the test framework uses ConfigurationSettings before you set the first mock.
TypeMock doesn't inject code until MockManager.Init is called (This is by design, so that code that isn't part of the test is not injected, and to enable TypeMock to send some vital information to the Injecter)
If you use the NUnit.console the test will actually work (because it doesn't call ConfigurationSettings).
This feature enhancment is already part of our requirements that will be implemented in the future.
Untill we add this feature you can solve this by changing the production code, For example change:
object filter = ConfigurationSettings.GetConfig();
to
object filter = GetFilter();
...
private object GetFilter()
{
return ConfigurationSettings.GetConfig();
}
and then mock GetFilter in your tests.