public void CanHaveMultipleSubscribersAndRaiseCustomEvent() { var customEvent = new TestableEventBase(); Payload payload = new Payload(); object[] received1 = null; object[] received2 = null; var eventSubscription1 = new MockEventSubscription(); eventSubscription1.GetPublishActionReturnValue = delegate(object[] args) { received1 = args; }; var eventSubscription2 = new MockEventSubscription(); eventSubscription2.GetPublishActionReturnValue = delegate(object[] args) { received2 = args; }; customEvent.Subscribe(eventSubscription1); customEvent.Subscribe(eventSubscription2); customEvent.Publish(payload); Assert.AreEqual(1, received1.Length); Assert.AreSame(received1[0], payload); Assert.AreEqual(1, received2.Length); Assert.AreSame(received2[0], payload); }
public void WhenEventSubscriptionActionIsNullPruneItFromList() { var eventBase = new TestableEventBase(); var eventSubscription = new MockEventSubscription { GetPublishActionReturnValue = null }; var token = eventBase.Subscribe(eventSubscription); eventBase.Publish(); Assert.False(eventBase.Contains(token)); }
public void CanPublishSimpleEvents() { var eventBase = new TestableEventBase(); var eventSubscription = new MockEventSubscription(); bool eventPublished = false; eventSubscription.GetPublishActionReturnValue = delegate { eventPublished = true; }; eventBase.Subscribe(eventSubscription); eventBase.Publish(); Assert.True(eventSubscription.GetPublishActionCalled); Assert.True(eventPublished); }
public void WhenEventSubscriptionActionIsNullPruneItFromList() { var eventBase = new TestableEventBase(); var eventSubscription = new MockEventSubscription(); eventSubscription.GetPublishActionReturnValue = null; var token = eventBase.Subscribe(eventSubscription); eventBase.Publish(); Assert.IsFalse(eventBase.Contains(token)); }
public void CanPublishSimpleEvents() { var eventBase = new TestableEventBase(); var eventSubscription = new MockEventSubscription(); bool eventPublished = false; eventSubscription.GetPublishActionReturnValue = delegate { eventPublished = true; }; eventBase.Subscribe(eventSubscription); eventBase.Publish(); Assert.IsTrue(eventSubscription.GetPublishActionCalled); Assert.IsTrue(eventPublished); }