예제 #1
0
        public void GetEventRecipients_NameofEventNameParam_NoSubscriber_ReturnsFalse()
        {
            // Arrange
            var stub = new EventClassStub();

            // Act
            var actualRecipient = CoClassEventReflector.GetEventRecipients(stub, typeof(EventClassStub), nameof(EventClassStub.Custom1Event));

            // Assert
            Assert.IsNotNull(actualRecipient);
            CollectionAssert.IsEmpty(actualRecipient);
        }
예제 #2
0
        public void GetEventRecipients_WithNoSubscribers_ReturnsEmptyCollection()
        {
            // Arrange
            var stub = new EventClassStub();

            // Act
            var actualRecipient = CoClassEventReflector.GetEventRecipients(stub, typeof(EventClassStub), "Custom1");

            // Assert
            Assert.IsNotNull(actualRecipient);
            CollectionAssert.IsEmpty(actualRecipient);
        }
예제 #3
0
        public void GetEventRecipients_NonExistingEventName_ThrowsArgumentException()
        {
            // Arrange
            var stub = new EventClassStub();

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

            Assert.AreEqual("eventName", actualException.ParamName);
            Assert.AreEqual("NonExistingEventName", actualException.ActualValue);
        }
예제 #4
0
        public void GetEventRecipients_NameofEventNameParam_EventWithSubscriber_ReturnsTrue()
        {
            // Arrange
            var stub = new EventClassStub();

            stub.Custom1Event += OnCustom1EventHandler;

            // Act
            var actualRecipient = CoClassEventReflector.GetEventRecipients(stub, typeof(EventClassStub), nameof(EventClassStub.Custom1Event));

            // Assert
            CollectionAssert.IsNotEmpty(actualRecipient);
            var recipient = actualRecipient[0];

            Assert.AreEqual("OnCustom1EventHandler", recipient.Method.Name);
        }
예제 #5
0
        public void GetEventRecipients_WithMultipleSubscribers_ReturnsTheCorrectSubsriber()
        {
            // Arrange
            var stub = new EventClassStub();

            stub.Custom1Event += OnCustom1EventHandler;
            stub.Custom2Event += OnCustom2EventHandler;
            stub.Custom3Event += OnCustom3EventHandler;

            // Act
            var actualRecipient = CoClassEventReflector.GetEventRecipients(stub, typeof(EventClassStub), "Custom2");

            // Assert
            CollectionAssert.IsNotEmpty(actualRecipient);
            var recipient = actualRecipient[0];

            Assert.AreEqual("OnCustom2EventHandler", recipient.Method.Name);
        }