I have an interface IPeakCommunication, and derived class PeakCommunication. Inside derived class I have an implementation of method Send(RequestData request) which do something, and as I expect invokes event RequestReceived and passing there argument request.
I would to create unit tests for some classes which interact with IPeakCommunication, and call Send(RequestData request) method. But I have no idea how to create a Mock which takes an object from arguments and use it for invoking RequestReceived event.
public interface IPeakCommunication : IDisposable
{
#region Delegates
delegate void PeakRequestReceivedHandler(RequestData data);
#endregion
#region Events
event PeakRequestReceivedHandler? RequestReceived;
#endregion
#region Methods
void Send(RequestData data);
#endregion
}
The code which I tried to make:
var mockCommunication = new Mock<IPeakCommunication>();
mockCommunication.Setup(x => x.Send(It.IsAny<RequestData>()))
.Raises(x => x.RequestReceived += null, new object[] { /*argument from Send()?*/ } );
You can use
Callback:Demo @dotnetfiddle.net