Пример #1
0
        public void EventsAreNotRedispatched()
        {
            EventNotifier notifier = new EventNotifier();

            int callCount = 0;

            notifier.OnEvent <TestEvent>(evnt => ++ callCount);

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(1, callCount);
            callCount = 0;

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(3, callCount);
            callCount = 0;

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);
        }
Пример #2
0
        public void EventsAreNotRedispatchedWithConcurrentDispatch()
        {
            EventNotifier notifier = new EventNotifier();

            int callCount = 0;

            notifier.OnEvent <TestEvent>(evnt => {
                notifier.Submit(TestEvent.Create());
                ++callCount;
            });

            notifier.DispatchEvents();
            Assert.Equal(0, callCount);

            notifier.Submit(TestEvent.Create());
            notifier.DispatchEvents();
            Assert.Equal(1, callCount);

            for (int i = 0; i < 20; ++i)
            {
                callCount = 0;
                notifier.DispatchEvents();
                Assert.Equal(1, callCount);
            }

            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());
            notifier.Submit(TestEvent.Create());

            for (int i = 0; i < 20; ++i)
            {
                callCount = 0;
                notifier.DispatchEvents();
                Assert.Equal(4, callCount);
            }
        }
Пример #3
0
 public void DispatchEvents()
 {
     EventNotifier.DispatchEvents();
 }