コード例 #1
0
 public void TestEventChild()
 {
     var hub = this.GetEventHub();
     var args = new EventMockChild(10);
     int called = 0;
     hub.Subscribe<EventMock>(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");
 }
コード例 #2
0
 public void TestCallBaseSubscribeParent()
 {
     var hub = this.GetEventHub();
     var args = new EventMockChild(10);
     int called = 0;
     hub.Subscribe<EventMockChild>(e => called++);
     hub.Raise<EventMock>(args);
     called.Should().Be(0, "event handler should not be called if the arguments are passed as base class");
 }
コード例 #3
0
 private void TestPerformanceEventsRaiseInternal()
 {
     var hub = this.GetEventHub();
     var args = new EventMockChild(10);
     var parentCalled = 0;
     var childCalled = 0;
     var interfaceCalled = 0;
     hub.Subscribe<EventMock>(e => parentCalled++);
     hub.Subscribe<EventMockChild>(e => childCalled++);
     hub.Subscribe<IEvent>(e => interfaceCalled++);
     var calledCount = 50000;
     for (int i = 0; i < calledCount; i++)
     {
         hub.Raise(args);
     }
     parentCalled.Should().Be(calledCount, "The parent should be called exactly {0} times", calledCount);
     childCalled.Should().Be(calledCount, "The child should be called exactly {0} times", calledCount);
     interfaceCalled.Should().Be(calledCount, "The interface should be called exactly {0} times", calledCount);
 }
コード例 #4
0
 public void TestHierarchyCallingOrder()
 {
     var hub = this.GetEventHub();
     var args = new EventMockChild(10);
     var parentCalled = false;
     var childCalled = false;
     var interfaceCalled = false;
     hub.Subscribe<EventMock>(e =>
     {
         childCalled.Should().BeTrue("child should be called before parent");
         parentCalled = true;
         interfaceCalled.Should().BeFalse("interface should be called after parent");
     });
     hub.Subscribe<EventMockChild>(e =>
     {
         childCalled = true;
         parentCalled.Should().BeFalse("parent should be called after child");
         interfaceCalled.Should().BeFalse("interface should be called after child");
     });
     hub.Subscribe<IEvent>(e =>
     {
         parentCalled.Should().BeTrue("parent should be called before interface");
         childCalled.Should().BeTrue("child should be called before interface");
         interfaceCalled = true;
     });
     hub.Raise(args);
     parentCalled.Should().BeTrue("parent should be called");
     parentCalled.Should().BeTrue("child should be called");
     parentCalled.Should().BeTrue("interface should be called");
 }