public void TestEventArgsPublish () { var registry = new EventRegistry(); var actual = 0; registry.Subscribe<EventArgs>((object sender, EventArgs e) => actual++); Assert.True(registry.Contains(typeof(EventArgs))); var eventArgs = new EventArgs(); registry.Publish(eventArgs); Assert.Equal(1, actual); }
public void TestFooEventArgsPublish () { var registry = new EventRegistry(); // ** Verify that the event was subscribed registry.Subscribe<FooEventArgs>(IncrementCount); Assert.True(registry.Contains(typeof(FooEventArgs))); var eventArgs = new FooEventArgs(); // ** Verify that the event was published. registry.Publish(eventArgs); Assert.Equal(1, eventArgs.Count); }
public void TestEventArgsUnsubscribe () { var registry = new EventRegistry(); var actual = 0; // ** Create the event handler... EventHandler<EventArgs> eh = (object sender, EventArgs e) => actual++; // ** Subscribe and assert that the event handler was in fact added to the registry... registry.Subscribe<EventArgs>(eh); Assert.True(registry.Contains(typeof(EventArgs))); // ** Unsubscribe the event handler; the provider created from it should still be there... registry.Unsubscribe<EventArgs>(eh); Assert.True(registry.Contains(typeof(EventArgs))); // ** Publish the event, the actual value should be unmodified (because the handler was removed). var eventArgs = new EventArgs(); registry.Publish(eventArgs); Assert.Equal(0, actual); }