I have the following code I am unit testing.
public static MyConfiguration GetConfig(string sectionName)
{
if (!Initialized)
{
try
{
InitializeEnv(); // Method is present but no implementation yet.
}
finally
{
Initialized = true;
if (configurationReader == null)
{
configurationReader = ConfigurationValueReader.ConfigurationReader();
}
}
}
return (MyConfiguration)configurationReader.ReadSection(sectionName, new MyConfigurationHandler());
}
And I want to throw an exception from the method InitializeEnv() which is defined in the same class as the above method using shims or stubs.This method InitializeEnv() doesn't have an implementation inside it at this moment to cause an exception with data. Is there a way I can still throw an exception from that method using Shims or Stubs here ?
Able to shim it but I need to add an ExpectedException attribute to my test method , since the Catch block is not present.
ShimListenerConfiguration.InitializeEnv = () =>
{
throw new Exception();
};