抽象类尝试的NUnit Raise事件失败

时间:2014-02-24 23:14:27

标签: c# .net nunit moq

为什么下面的NUnit测试失败?或者为什么事件永远不会被触发?

public interface IGo
{
    event Action<bool> GoNow;
}

public abstract class Goer : IGo
{
    public virtual event Action<bool> GoNow = delegate {};
}

[Test]
public void VerifyNUnitRaise()
{
    var mock = new Mock<Goer> {CallBase = true};
    var hit = false;
    mock.Object.GoNow += b => hit = b;
    mock.Raise(g => g.GoNow += null, true);

    Assert.IsTrue(hit);
}

0 个答案:

没有答案