I have a class with following event:
event Func<ApplicationMessageProcessedEventArgs, Task> ApplicationMessageProcessedAsync;
I would like to test the handler for an event, I am using Moq and have following code
mqttClient.Mock.Raise(client => client.ApplicationMessageReceivedAsync += null, eventArg);
I am getting exception:
System.Reflection.TargetParameterCountException: Parameter count mismatch.
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at Moq.Extensions.InvokePreserveStack(Delegate del, IReadOnlyList`1 args) in C:\projects\moq4\src\Moq\Extensions.cs:line 158
at Moq.Mock.RaiseEvent(Mock mock, LambdaExpression expression, Stack`1 parts, Object[] arguments) in C:\projects\moq4\src\Moq\Mock.cs:line 745
at Moq.Mock.RaiseEvent[T](Mock mock, Action`1 action, Object[] arguments) in C:\projects\moq4\src\Moq\Mock.cs:line 695
at Moq.Mock`1.Raise(Action`1 eventExpression, EventArgs args) in C:\projects\moq4\src\Moq\Mock`1.cs:line 1366
at MqttChannel.MqttChannelTest.MqttChannel_ProcessNewMessage() in C:\Development\Shared\OT.Test\MqttChannel\MqttChannelTest.cs:line 298
at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.ThreadOperations.ExecuteWithAbortSafety(Action action)
Any idea how to solve this?