示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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");
        }
示例#4
0
        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");
        }
示例#5
0
        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");
        }