-
Notifications
You must be signed in to change notification settings - Fork 2
Stubs: Simple Event Usage
haven1433 edited this page Nov 21, 2018
·
1 revision
public interface IExample {
event EventHandler SimpleEvent;
}
You can use +=, -=, and Invoke on event handlers to handle most simple scenarios.
public void SimpleEventUsage() {
var stub = new StubExample();
IExample example = stub;
// you can add and remove handlers like normal
int count = 0;
stub.SimpleEvent += (sender, e) => count++;
// you can invoke the event like you would from within the stub
stub.SimpleEvent.Invoke(stub, EventArgs.Empty);
Assert.Equal(1, count);
// you can access all the handlers that have been added.
Assert.Single(stub.SimpleEvent.handlers);
}