public void UnsubscribeEvents_NoSubscriptions_Nop() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); // Act bus.UnsubscribeEvents(subscriber); // Assert: no exception }
public void UnsubscribeEvent_NoSubscription_Nop() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); // Act bus.UnsubscribeEvent <TestEventArgs>(EventSource.Local, subscriber); // Assert: Does not throw }
public void SubscribeEvent_NullHandler_NullArgumentException() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); // Act void Code() => bus.SubscribeEvent(EventSource.Local, subscriber, (EntityEventHandler <TestEventArgs>)null !); //Assert Assert.Throws <ArgumentNullException>(Code); }
public void UnsubscribeEvent_SourceNone_ArgOutOfRange() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); // Act void Code() => bus.UnsubscribeEvent <TestEventArgs>(EventSource.None, subscriber); // Assert Assert.Throws <ArgumentOutOfRangeException>(Code); }
public void SubscribeEvent_SourceNone_ArgOutOfRange() { // Arrange var bus = BusFactory(); var subscriber = new TestEventSubscriber(); // Act void Code() => bus.SubscribeEvent(EventSource.None, subscriber, (EntityEventHandler<TestEventArgs>)null!); //Assert Assert.Throws<ArgumentOutOfRangeException>(Code); }
public void SubscribeEvent_NullEvent_NoNullException() { // Arrange var manager = new TestEntityManager(); var subscriber = new TestEventSubscriber(); manager.SubscribeEvent((EntityEventHandler <TestEventArgs>)null, subscriber); // Act manager.RaiseEvent(null, new TestEventArgs()); //Assert: this should do nothing }
public void RegisterCustomSubscriberRaw() { var eventSubscriber = new TestEventSubscriber(); JEventBus.GetDefault().Register(this, eventSubscriber); var testEvent = new TestEvent(); for (int i = 0; i < 100; i++) { JEventBus.GetDefault().Post(testEvent); } Assert.AreEqual(100, eventSubscriber.EventCounter); }
public void RaiseEvent_NoSubscriptions_Nop() { // Arrange var bus = BusFactory(); var subscriber = new TestEventSubscriber(); int delCalledCount = 0; bus.SubscribeEvent<TestEventTwoArgs>(EventSource.Local, subscriber, ev => delCalledCount++); // Act bus.RaiseEvent(EventSource.Local, new TestEventArgs()); // Assert Assert.That(delCalledCount, Is.EqualTo(0)); }
public void RaiseEvent_NoSubscriptions_Nop() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); int delCalledCount = 0; bus.SubscribeEvent <TestEventTwoArgs>(((sender, ev) => delCalledCount++), subscriber); // Act bus.RaiseEvent(null, new TestEventArgs()); // Assert Assert.That(delCalledCount, Is.EqualTo(0)); }
public void UnsubscribeEvent_DoubleUnsubscribe_Nop() { // Arrange var bus = BusFactory(); var subscriber = new TestEventSubscriber(); void Handler(TestEventArgs ev) { } bus.SubscribeEvent<TestEventArgs>(EventSource.Local, subscriber, Handler); bus.UnsubscribeEvent<TestEventArgs>(EventSource.Local, subscriber); // Act bus.UnsubscribeEvent<TestEventArgs>(EventSource.Local, subscriber); // Assert: Does not throw }
public void QueueEvent_EventQueued_DoesNotImmediatelyRaise() { // Arrange var bus = BusFactory(); var subscriber = new TestEventSubscriber(); int delCallCount = 0; void Handler(TestEventArgs ev) => delCallCount++; bus.SubscribeEvent<TestEventArgs>(EventSource.Local, subscriber, Handler); // Act bus.QueueEvent(EventSource.Local, new TestEventArgs()); // Assert Assert.That(delCallCount, Is.EqualTo(0)); }
public void ProcessQueue_EventQueued_HandlerRaised() { // Arrange var bus = BusFactory(); var subscriber = new TestEventSubscriber(); int delCallCount = 0; void Handler(TestEventArgs ev) => delCallCount++; bus.SubscribeEvent<TestEventArgs>(EventSource.Local, subscriber, Handler); bus.QueueEvent(EventSource.Local, new TestEventArgs()); // Act bus.ProcessEventQueue(); // Assert Assert.That(delCallCount, Is.EqualTo(1)); }
public void UnsubscribeEvents_UnsubscribedHandler_Nop() { // Arrange var bus = BusFactory(); var subscriber = new TestEventSubscriber(); int delCallCount = 0; void Handler(TestEventArgs ev) => delCallCount++; bus.SubscribeEvent<TestEventArgs>(EventSource.Local, subscriber, Handler); bus.UnsubscribeEvents(subscriber); // Act bus.RaiseEvent(EventSource.Local, new TestEventArgs()); // Assert Assert.That(delCallCount, Is.EqualTo(0)); }
public void QueueEvent_EventQueued_DoesNotImmediatelyRaise() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); int delCallCount = 0; void Handler(object sender, TestEventArgs ev) => delCallCount++; bus.SubscribeEvent <TestEventArgs>(Handler, subscriber); // Act bus.QueueEvent(null, new TestEventArgs()); // Assert Assert.That(delCallCount, Is.EqualTo(0)); }
public void UnsubscribeEvent_DoubleUnsubscribe_Nop() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); void Handler(object sender, TestEventArgs ev) { } bus.SubscribeEvent <TestEventArgs>(Handler, subscriber); bus.UnsubscribeEvent <TestEventArgs>(subscriber); // Act bus.UnsubscribeEvent <TestEventArgs>(subscriber); // Assert: Does not throw }
public void SubscribeEvent_DuplicateSubscription_RaisedOnce() { // Arrange var bus = BusFactory(); var subscriber = new TestEventSubscriber(); int delegateCallCount = 0; void Handler(TestEventArgs ev) => delegateCallCount++; // 2 subscriptions 1 handler bus.SubscribeEvent<TestEventArgs>(EventSource.Local, subscriber, Handler); bus.SubscribeEvent<TestEventArgs>(EventSource.Local, subscriber, Handler); // Act bus.RaiseEvent(EventSource.Local, new TestEventArgs()); //Assert Assert.That(delegateCallCount, Is.EqualTo(1)); }
public void SubscribeEvent_MultipleDelegates_BothRaised() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); int delFooCount = 0; int delBarCount = 0; bus.SubscribeEvent <TestEventArgs>(EventSource.Local, subscriber, ev => delFooCount++); bus.SubscribeEvent <TestEventArgs>(EventSource.Local, subscriber, ev => delBarCount++); // Act bus.RaiseEvent(EventSource.Local, new TestEventArgs()); // Assert Assert.That(delFooCount, Is.EqualTo(1)); Assert.That(delBarCount, Is.EqualTo(1)); }
public void AutoEventConnector_TestConnectDisconnect() { var testEventPublisher = new TestEventPublisher(); var testEventSubscriber = new TestEventSubscriber(); testEventSubscriber.ConnectTo(testEventPublisher); testEventPublisher.RaiseTestEvent1(); testEventPublisher.RaiseTestEvent2(); Assert.AreEqual(0, testEventSubscriber.HandleTestEvent1Count); Assert.AreEqual(1, testEventSubscriber.HandleTestEventPublisherTestEvent1Count); testEventSubscriber.DisconnectFrom(testEventPublisher); testEventPublisher.RaiseTestEvent1(); testEventPublisher.RaiseTestEvent2(); Assert.AreEqual(0, testEventSubscriber.HandleTestEvent1Count); Assert.AreEqual(1, testEventSubscriber.HandleTestEventPublisherTestEvent1Count); }
public void AutoEventConnector_TestConnectDisconnect() { var testEventPublisher = new TestEventPublisher(); var testEventSubscriber = new TestEventSubscriber(); testEventSubscriber.ConnectTo(testEventPublisher); testEventPublisher.RaiseTestEvent1(); testEventPublisher.RaiseTestEvent2(); Assert.AreEqual(0, testEventSubscriber.HandleTestEvent1Count); Assert.AreEqual(1, testEventSubscriber.HandleTestEventPublisherTestEvent1Count); testEventSubscriber.DisconnectFrom(testEventPublisher); testEventPublisher.RaiseTestEvent1(); testEventPublisher.RaiseTestEvent2(); Assert.AreEqual(0, testEventSubscriber.HandleTestEvent1Count); Assert.AreEqual(1, testEventSubscriber.HandleTestEventPublisherTestEvent1Count); }
public void UnsubscribeEvents_UnsubscribedHandler_Nop() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); int delCallCount = 0; void Handler(object sender, TestEventArgs ev) => delCallCount++; bus.SubscribeEvent <TestEventArgs>(Handler, subscriber); bus.UnsubscribeEvents(subscriber); // Act bus.RaiseEvent(null, new TestEventArgs()); // Assert Assert.That(delCallCount, Is.EqualTo(0)); }
public void ProcessQueue_EventQueued_HandlerRaised() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); int delCallCount = 0; void Handler(object sender, TestEventArgs ev) => delCallCount++; bus.SubscribeEvent <TestEventArgs>(Handler, subscriber); bus.QueueEvent(null, new TestEventArgs()); // Act bus.ProcessEventQueue(); // Assert Assert.That(delCallCount, Is.EqualTo(1)); }
public void SubscribeEvent_DuplicateSubscription_RaisedOnce() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); int delegateCallCount = 0; void Handler(object sender, TestEventArgs ev) => delegateCallCount++; // 2 subscriptions 1 handler bus.SubscribeEvent <TestEventArgs>(Handler, subscriber); bus.SubscribeEvent <TestEventArgs>(Handler, subscriber); // Act bus.RaiseEvent(null, new TestEventArgs()); //Assert Assert.That(delegateCallCount, Is.EqualTo(1)); }
public void SubscribeEvent_MultipleSubscriptions_IndividuallyCalled() { // Arrange var bus = new EntityEventBus(); var subscriber = new TestEventSubscriber(); int delFooCount = 0; int delBarCount = 0; bus.SubscribeEvent <TestEventArgs>(EventSource.Local, subscriber, ev => delFooCount++); bus.SubscribeEvent <TestEventTwoArgs>(EventSource.Local, subscriber, ev => delBarCount++); // Act & Assert bus.RaiseEvent(EventSource.Local, new TestEventArgs()); Assert.That(delFooCount, Is.EqualTo(1)); Assert.That(delBarCount, Is.EqualTo(0)); delFooCount = delBarCount = 0; bus.RaiseEvent(EventSource.Local, new TestEventTwoArgs()); Assert.That(delFooCount, Is.EqualTo(0)); Assert.That(delBarCount, Is.EqualTo(1)); }