0
如何测试事件处理程序的代码?单元测试事件处理程序的代码
我有这个
[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;
}
但NCover指出,事件的代码handlet本身不是测试(“thow e.Exception”被标记为红色)。
我可以尝试直接调用事件处理程序方法吗?我如何创建ValidationEventArgs的实例?
我正在检查所有帖子,我忘记标记为答案。抱歉耽搁了 – Kaikus