示例#1
0
        public void RaiseCustomEvent_WithNoSubscribers_ReturnsZero()
        {
            // Arrange
            var stub = new EventClassStub();
            var p    = new object[] { };

            // Act
            var actualCount = CoClassEventReflector.RaiseCustomEvent(stub, typeof(EventClassStub), "Custom1", ref p);

            // Assert
            Assert.AreEqual(0, actualCount);
        }
示例#2
0
        public void RaiseCustomEvent_NonExistingEventName_ThrowsArgumentException()
        {
            // Arrange
            var stub = new EventClassStub();
            var p    = new object[] { };

            // Act & Assert
            var actualException = Assert.Throws <ArgumentOutOfRangeException>(
                () => CoClassEventReflector.RaiseCustomEvent(stub, typeof(EventClassStub), "NonExistingEventName", ref p));

            Assert.AreEqual("eventName", actualException.ParamName);
            Assert.AreEqual("NonExistingEventName", actualException.ActualValue);
        }
示例#3
0
        public void RaiseCustomEvent_WithTwoSubscribers_ReturnsTwo()
        {
            // Arrange
            var stub = new EventClassStub();

            stub.Custom2Event += OnCustom2EventHandler;
            stub.Custom2Event += OnCustom2EventHandler;

            var p = new object[] { this, new EventArgs() };

            // Act
            var actualCount = CoClassEventReflector.RaiseCustomEvent(stub, typeof(EventClassStub), "Custom2", ref p);

            // Assert
            Assert.AreEqual(2, actualCount);
        }
示例#4
0
        public void RaiseCustomEvent_NameofEventName_WithThreeSubscribers_ReturnsCorrectInvocationsCount()
        {
            // Arrange
            var stub = new EventClassStub();

            stub.Custom3Event += OnCustom3EventHandler;
            stub.Custom3Event += OnCustom3EventHandler;
            stub.Custom3Event += OnCustom3EventHandler;

            var p = new object[] { this, new EventArgs() };

            // Act
            var actualCount = CoClassEventReflector.RaiseCustomEvent(stub, typeof(EventClassStub), nameof(EventClassStub.Custom3Event), ref p);

            // Assert
            Assert.AreEqual(3, actualCount);
        }