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