Verifying a delegate was called with Moq

c#, delegates, moq, unit-testing

Solution

What about using an anonymous function? It can act like an inline mock here, you don't need a mocking framework.

bool isDelegateCalled = false;
var a = new A(a => { isDelegateCalled = true});

//do something
Assert.True(isDelegateCalled);

Problem

i got a class that gets by argument a delegate. This class invokes that delegate, and i want to unit test it with Moq. how do i verify that this method was called ? example class : ``` public delegate void Foo(int number); public class A { int a = 5; public A(Foo myFoo) { myFoo(a); } } ``` and I want to check that Foo was called. Thank you.

Original source