Ejemplo n.º 1
0
 public void TestParentAndChildSubscription()
 {
     var hub = this.GetEventHub();
     var args = new EventMock(10);
     int called = 0;
     Action<EventMock> handler = (e => called++);
     hub.Subscribe(handler);
     hub.Subscribe<EventMockChild>(handler);
     hub.Raise(args);
     called.Should().Be(1, "event handler should be called exactly once");
 }
Ejemplo n.º 2
0
 public void TestEventInterface()
 {
     var hub = this.GetEventHub();
     var args = new EventMock(10);
     int called = 0;
     hub.Subscribe<IEvent>(e =>
     {
         e.Should().BeSameAs(args, "the passed arguments should be the same as provided");
         called++;
     });
     hub.Raise(args);
     called.Should().Be(1, "event handler should be called exactly once");
 }
Ejemplo n.º 3
0
 public void TestDoubleSubscription()
 {
     var hub = this.GetEventHub();
     var args = new EventMock(10);
     int called = 0;
     Action<IEvent> handler = (e => called++);
     hub.Subscribe(handler);
     hub.Subscribe(handler);
     hub.Raise(args);
     called.Should().Be(2, "event handler should be called exactly twice");
 }
Ejemplo n.º 4
0
 public void TestNoSubscription()
 {
     var hub = this.GetEventHub();
     var args = new EventMock(10);
     hub.Raise(args);
 }
Ejemplo n.º 5
0
        public void TestHandlerUnsubscribingItself()
        {
            var hub = this.GetEventHub();
            var args = new EventMock(10);

            int beforeHandlerCalled = 0;
            Action<IEvent> beforeHandler = (e => beforeHandlerCalled++);
            hub.Subscribe(beforeHandler);

            int unsubscribingHandlerCalled = 0;
            Action<IEvent> unsubscribingHandler = null;
            unsubscribingHandler = (e => { unsubscribingHandlerCalled++; hub.Unsubscribe(unsubscribingHandler); });
            hub.Subscribe(unsubscribingHandler);

            int afterHandlerCalled = 0;
            Action<IEvent> afterHandler = (e => afterHandlerCalled++);
            hub.Subscribe(afterHandler);

            hub.Raise(args);
            beforeHandlerCalled.Should().Be(1, "before event handler should be called exactly once after the first raise");
            unsubscribingHandlerCalled.Should().Be(1, "unsubscribing event handler should be called exactly once after the first raise");
            afterHandlerCalled.Should().Be(1, "after event handler should be called exactly once after the first raise");

            hub.Raise(args);
            beforeHandlerCalled.Should().Be(2, "before event handler should be called exactly twice");
            unsubscribingHandlerCalled.Should().Be(1, "unsubscribing event handler should not be called after the second raise since it has unsubscribed itself during the first");
            afterHandlerCalled.Should().Be(2, "after event handler should be called exactly twice");
        }
Ejemplo n.º 6
0
 public void TestUninitialize()
 {
     var hub = this.GetEventHub();
     var args = new EventMock(10);
     int called = 0;
     Action<EventMock> handler = (e => called++);
     hub.Subscribe(handler);
     hub.Raise(args);
     called.Should().Be(1, "event handler should be called exactly once after the first raise");
 }