Here is the code I'm trying to unit test:
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
try
{
_controllers = section.SelectSingleNode("applicationControllers");
}
catch (InvalidCastException ex)
{
bool rethrow = ExceptionHandler.HandleException(ex, ExceptionPolicies.Presenter.ToString());
if (rethrow)
throw;
}
catch (System.Xml.XPath.XPathException ex)
{
bool rethrow = ExceptionHandler.HandleException(ex, ExceptionPolicies.Presenter.ToString());
if (rethrow)
throw;
}
return this;
}
Here is the entire unit test:
[TestMethod]
[ExpectedException(typeof(InvalidCastException))]
public void ApplicationControllerConfigurationSectionHandlerCreateTestInvalidCastException()
{
MockManager.Init();
Mock mockXmlNode = MockManager.Mock(typeof(XmlNode));
mockXmlNode.ExpectAndThrow("SelectSingleNode", new InvalidCastException());
Mock factoryMockLibrary = MockManager.Mock(typeof(ExceptionHandler));
factoryMockLibrary.ExpectAndReturn("HandleException", true);
ApplicationControllerConfigurationSectionHandler configuration = (ApplicationControllerConfigurationSectionHandler)ConfigurationManager.GetSection("controllerSection/controllerHelper");
MockManager.Verify();
MockManager.ClearAll();
}