public void AttachEventCorrectly() { var obj = new TestEventClass(); var wrapper = new ImplBaseTester(obj); wrapper.AddEvent <EventArgs>(nameof(TestEventClass.Event), nameof(ImplBaseTester.HandleEvent)); obj.FireEvent(); Assert.IsTrue(wrapper.EventCalled); }
public void DetachEventCorrectly() { var obj = new TestEventClass(); var wrapper = new ImplBaseTester(obj); obj.Event += wrapper.HandleEvent; wrapper.RemoveEvent <EventArgs>(nameof(TestEventClass.Event), nameof(ImplBaseTester.HandleEvent)); obj.FireEvent(); Assert.IsFalse(wrapper.EventCalled); }
public void ThrowExceptionIfHandlerNameIsNull() { var obj = new TestEventClass(); var wrapper = new ImplBaseTester(obj); var ex = Assert.Throws <ArgumentNullException>(() => wrapper.AddEvent <EventArgs>(nameof(TestEventClass.Event), null)); Assert.IsNotNull(ex); ex.ParamName.Should().Be("handlerName"); }
public void ThrowExceptionIfEventNameIsInvalid() { var obj = new TestEventClass(); var wrapper = new ImplBaseTester(obj); var ex = Assert.Throws <ArgumentOutOfRangeException>( () => wrapper.AddEvent <EventArgs>("InvalidEvent", nameof(ImplBaseTester.HandleEvent))); Assert.IsNotNull(ex); ex.Message.Should().Be($"Invalid event name supplied!{Environment.NewLine}Parameter name: eventName"); }
public void ThrowExceptionIfHandlerHasIncorrectSignature() { var obj = new TestEventClass(); var wrapper = new ImplBaseTester(obj); var ex = Assert.Throws <ArgumentOutOfRangeException>( () => wrapper.AddEvent <EventArgs>(nameof(TestEventClass.Event), nameof(ImplBaseTester.HandleEvent2))); Assert.IsNotNull(ex); ex.Message.Should().Be($"Invalid handler name supplied!{Environment.NewLine}Parameter name: handlerName"); }