Moq: Invalid callback. Setup on method with parameters cannot invoke callback with parameters
I am trying to use moq to write a unit test. Here is my unit test code var sender = new Mock<ICommandSender>(); sender.Setup(m => m.SendCommand(It.IsAny<MyCommand>(), false)) .Callback(delegate(object o) { var msg = o as MyCommand; Assert.AreEqual(cmd.Id, msg.Id); Assert.AreEqual(cmd.Name, msg.Name); }) .Verifiable(); SendCommand takes an object and optional boolean parameter. And MyCommand derives from ICommand. void SendCommand(ICommand commands, bool idFromContent = false); When the test runs, I see the error System.ArgumentException : Invalid callback. Setup on method with parameters