0

According to the documentation of fakeiteasy all I have to do is:

public delegate void CustomEventHandler(object sender, CustomEventArgs e);

event CustomEventHandler CustomEvent;

fake.CustomEvent += Raise.With<CustomEventHandler>(fake, sampleCustomEventArgs);

I tried this in my code as follows:

public delegate void RowStateHandler(object sender, RowStateHandlerArgs e);
public class RowStateHandlerArgs : EventArgs
{
    public bool Selected { get; set; }
    public string CampaignId { get; set; }
}

... The interface of the view:

public interface ICampaignChannelView
{
     event RowStateHandler RowStateChanged;
}

The snippet in my unit test:

ICampaignChannelView v = A.Fake<ICampaignChannelView>();
RowStateHandlerArgs args = new RowStateHandlerArgs() {CampaignId = "1", Selected = true};
v.RowStateChanged += Raise.With<RowStateHandler>(v, args);

I get following compile error:

Error   CS0029  Cannot implicitly convert type
FakeItEasy.Raise<Add_in.UI.Wizard.RowStateHandler> to
Add_in.UI.Wizard.RowStateHandler    Add-inTests C:\..\WizardPresenterTests.cs

and

Error CS1503 Argument 2: cannot convert from 'Add_in.UI.Wizard.RowStateHandlerArgs' to 'Add_in.UI.Wizard.RowStateHandler' Add-inTests C:..\WizardPresenterTests.cs

Any help is much appreciated!

janhamburg
  • 25
  • 7

1 Answers1

0

It sounds like you're using an older version of FakeItEasy than that documentation refers to. The Raising Events documentation page has two flavours. One for FakeItEasy 1.x and one for 2.x.

(Update: the documentation has since been moved to readthedocs, which has a better system for maintaining different versions of the documentation.)

I just checked the two pages and built two test projects with your code. The only line I ended up changing was

 v.RowStateChanged += Raise.With<RowStateHandler>(v, args);

Under FakeItEasy 1.25.3, this call works:

v.RowStateChanged += Raise.With(v, args).Now;

Under FakeItEasy 2.0.0, this call works:

v.RowStateChanged += Raise.With<RowStateHandler>(v, args);
Blair Conrad
  • 233,004
  • 25
  • 132
  • 111
  • Yeah, we upgraded to 2.0.0-rc1 and now it works. At first, it wasnt obvious to us, that the docs we read were for 2.0. Thanks. – janhamburg Apr 04 '16 at 09:35