Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }