我有一个事件和一个提升方法如下:
public class Events {
public event EventHandler<CustomEventArgs> Succeed;
public virtual void OnSucceed(object sender, params object[] data)
{
CustomEventArgs args = new CustomEventArgs(data);
EventHandler<CustomEventArgs> _succeed = Succeed;
if (_succeed != null)
{
_succeed(sender, args);
}
}}
我为OnSucceed方法创建了一个单元测试(使用FluentAssertions):
[Test]
public void SucceedShouldNotBeRaisedTest()
{
Events events = new Events();
events.MonitorEvents();
events.OnSucceed(this,"somedata");
events.ShouldNotRaise("Succeed");
}
因为该事件没有订阅者,所以我希望它不会引发成功事件
但测试失败,因为引发了成功事件。这有什么问题?!