0

When I run the unit test below, it fails and returns this message:

System.ArgumentException : Cannot raise event with the provided arguments. Use Raise.Event<Action'1>(CWaveform[]) to raise this event.

[Test]
public void WaveformsReceived_FourWaveformsReceived_WaveformPlotsEqual4()
{
    IWorkflowController oWorkflowControllerMock = Substitute.For<IWorkflowController>();
    IEventAggregator oEventAggregatorMock = Substitute.For<IEventAggregator>();
    CDataAcquisitionViewModel oDataAcquisitionViewModel = new CDataAcquisitionViewModel(oWorkflowControllerMock, oEventAggregatorMock);

    CWaveform[] aoWaveforms = { };
    oWorkflowControllerMock.WaveformsReceived += aoWForms => aoWaveforms = aoWForms;
    int nNumberOfWaveforms = 4;
    CWaveform[] aoFourWaveforms = Enumerable.Range(0, nNumberOfWaveforms).Select(_ => new CWaveform()).ToArray();
    oWorkflowControllerMock.WaveformsReceived += Raise.Event<Action<CWaveform[]>>(aoFourWaveforms);

    Assert.AreEqual(aoWaveforms.Length, oDataAcquisitionViewModel.Plots.Count());
}

Raise.Event does not seem to work for an Action whose parameter is an array of reference types. It does work for an array of value types. Is it possible to make it work for reference types?

Edit: The declared type for IWorkflowController.WaveformsReceived is event Action<CWaveform[]>

blueshift
  • 831
  • 2
  • 12
  • 24

1 Answers1

0

System.ArgumentException Cannot raise event with the provided arguments. Use Raise.Event<EventHandler1>(Object, IList1) to raise this event.

I was seeing a similar error, which brought me here. However it was down to how I was raising the event. I had forgotten to include the sender and was blindly trying to send the EventHandler.

Bad

+= Raise.Event<EventHandler<string>>"Something");

Good

+= Raise.Event<EventHandler<string>>(null, "Something");
metoyou
  • 639
  • 1
  • 7
  • 22