How do I test the code of an event handler?
I have this
[TestMethod]
[ExpectedException(typeof(XmlException))]
public void TheXMLValidationEventHandlerWorksOK()
{
string xSDFilePath = @"XML Test Files\wrongXSDFile.xsd";
try
{
XmlSchema xmlSchema = XmlSchema.Read(new StreamReader(xSDFilePath), XMLValidationEventHandler);
}
catch (System.Xml.XmlException e)
{
Assert.IsNotNull(e);
throw e;
}
}
private void XMLValidationEventHandler(object sender, ValidationEventArgs e)
{
throw e.Exception;
}
But NCover states that the code of the event handlet itself is NOT tested ('thow e.Exception' is marked in red).
May I have to try to call directly to the event handler method? How do I create an instance of ValidationEventArgs?