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 :)

有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top