-
Notifications
You must be signed in to change notification settings - Fork 278
Adding null event handler to substituted event leads to exception in Raise.EventWith. #647
Copy link
Copy link
Closed
Labels
bugReported problem with NSubstitute behaviourReported problem with NSubstitute behaviourgood first issueFor smaller tasks that do not require in-depth knowledge of the code baseFor smaller tasks that do not require in-depth knowledge of the code base
Description
A "normal" event on an instance ignores null subscriptions. If I do so on a substituted interface, a null subscription leads to an exception. I have a not so nice legacy code with different listeners to an event an one class that does null-attach internally under some conditions, would be nice if this behaviour would be able to be tested as well. Example code for the problem:
public interface IEventSource
{
event EventHandler<EventArgs> MyEvent;
}
[TestMethod]
public void TestEvent()
{
var raised = false;
var source = Substitute.For<IEventSource>();
source.MyEvent += null; //<- this leads to fail on Raise
source.MyEvent += (s, e) => raised = true;
source.MyEvent += Raise.EventWith(new EventArgs());
Assert.IsTrue(raised);
}´´´
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugReported problem with NSubstitute behaviourReported problem with NSubstitute behaviourgood first issueFor smaller tasks that do not require in-depth knowledge of the code baseFor smaller tasks that do not require in-depth knowledge of the code base