Registering a handler on a fake Wrapping an event does not work
See original GitHub issueHello,
I want to be able to tell whether a method has been called on an object, but still use the actual implementation of this object.
To do this, I’m creating a fake for the interface, wrapping an instance of its implementation.
It works for methods, but not for events: trying to add an event handler on the faked event results in the concrete event never receiving the call to register the event handler.
Demo (the test fails):
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
var success = false;
var instance = new MyClass();
var fake = A.Fake<IInterface>(x => x.Wrapping(instance));
fake.Event += (s, e) => success = true;
fake.RaiseEvent();
if (!success)
Assert.Fail();
}
public interface IInterface
{
void RaiseEvent();
event EventHandler Event;
}
public class MyClass : IInterface
{
public event EventHandler Event;
public void RaiseEvent() => Event?.Invoke(this, EventArgs.Empty);
}
}
I did not find any documentation about this behavior. Is this expected? Is there any way around that?
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (12 by maintainers)
Top Results From Across the Web
Lighting aura:event not firing, or handler not executing
The problem: either the event seems to not be fired, or the handlers seem to not be activated. I put console. debug's, alerts...
Read more >Workaround for generic event handler in Windows Forms
Best and very easy workaround is to subscribe the event in constructor programmatically than finding way to make the designer to work. Just...
Read more >Bubbling and capturing
But any handler may decide that the event has been fully processed and stop the bubbling. The method for it is event.stopPropagation() ....
Read more >JavaScript Event Handlers – How to Handle Events in JS
It gets handled by registering a function, called an event ... If useCapture is set to false , the event handler is in...
Read more >Marking routed events as handled, and class handling
The KeyDown routed event is marked as handled. The instance handler attached to componentWrapper is triggered by the KeyDown routed event. The ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This change has also been released as part of FakeItEasy 7.0.0.
This change has been released as part of FakeItEasy 7.0.0-beta.1.