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); }
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); }
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); }
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); }
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); }