Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FakeItEasy to have a faked method call raise an event?

I'm trying to do something along the lines of:

A.CallTo(() => fakeTimer.Start()).Invokes(() => 
    fakeTimer.Elapsed += Raise.With<ElapsedEventArgs>(ElapsedEventArgs.Empty).Now);

The fakeTimer is a fake of ITimer, a wrapper interface per this answer.

Obviously this doesn't work, since I cannot do an assignment inside an Experssion Tree.

What I am actually tying to achieve is simulating raising timer events when the Start method was called. This way I can assert that a call to Start indeed happened.

Any (alternative) ideas?

Edit I'm an idiot and the fault is my own! I accidentally added an extra A.CallTo, where I shouldn't have. Instead of deleting this question, I'll keep it to award Patrik Hägne his rightful reputation :)

like image 738
Igal Tabachnik Avatar asked Feb 19 '23 18:02

Igal Tabachnik


1 Answers

I'm not really sure what you're trying to do, is this it???

A.CallTo(() => fakeTimer.Start()).Invokes(() => 
    fakeTimer.Elapsed += Raise.With<ElapsedEventArgs>(ElapsedEventArgs.Empty).Now);
like image 169
Patrik Hägne Avatar answered Mar 24 '23 01:03

Patrik Hägne