Moq Verify events triggered

I'm not sure I really understand why you ask. If you have a Mock<A>, then you control the mock so why verify that it has done something that you control?

That said, although I do use Moq's raise/raises, I still often use a flag with a lambda, which I find fairly clean:

bool eventWasDispatched = false; // yeah, it's the default
var a = new A();
a.Event1 += () => eventWasDispatched = true;
a.DoSomethingToFireEvent();
Assert.IsTrue(eventWasDispatched);

var mock = new Mock<IInterfaceWithEvent>();
mock.Raise(e => e.MyEvent += null, EventArgs.Empty);
mock.VerifyAll();

or if you want to make sure that act raises an event, your setup should look like:

mock.Setup(foo => foo.Submit()).Raises(f => f.Sent += null, EventArgs.Empty);
// ...
mock.VerifyAll();

Tags:

C#

Moq