Exemple #1
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");
        }
Exemple #2
0
        public void TestCallBaseSubscribeParent()
        {
            var hub    = this.GetAsyncEventHub();
            var args   = new EventMockChild(10);
            int called = 0;

            hub.Subscribe <EventMockChild>(e => called++);
            hub.Raise(args);
            called.Should().Be(0, "event handler should not be called if the arguments are passed as base class");
        }
Exemple #3
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");
        }
Exemple #4
0
        private void TestPerformanceEventsRaiseInternal()
        {
            var hub             = this.GetEventHub();
            var args            = new EventMockChild(10);
            var childCalled     = 0;
            var interfaceCalled = 0;

            hub.Subscribe <EventMockChild>(e => childCalled++);
            hub.Subscribe <IEvent>(e => interfaceCalled++);
            var calledCount = 150000;

            for (int i = 0; i < calledCount; i++)
            {
                hub.Raise(args);
            }
            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);
            this.app.Reinitialize();
        }
Exemple #5
0
        private void TestPerformanceEventsRaiseDelayedInternal()
        {
            this.app.GetConfig <DelayedEventsConfig>().DefaultBehavior = EventBehavior.Delayed;
            var hub             = this.app.GetDelayedEventHub();
            var args            = new EventMockChild(10);
            var childCalled     = 0;
            var interfaceCalled = 0;

            hub.Subscribe <EventMockChild>(e => childCalled++);
            hub.Subscribe <IEvent>(e => interfaceCalled++);
            var calledCount = 65000;

            for (int i = 0; i < calledCount; i++)
            {
                hub.Raise(args);
            }
            childCalled.Should().Be(0, "The child should not be called before flush");
            interfaceCalled.Should().Be(0, "The interface should not be called before flush");
            hub.Flush();
            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);
            this.app.Reinitialize();
        }