Ejemplo n.º 1
0
        public void MapOnceWithSideDispatcherTest()
        {
            var dispatcher = new Build1.PostMVC.Extensions.MVCS.Events.Impl.EventDispatcher();

            var count00 = 0;
            var count01 = 0;
            var count02 = 0;
            var count03 = 0;

            void Listener00() => count00++;
            void Listener01(int p1) => count01++;
            void Listener02(int p1, string p2) => count02++;
            void Listener03(int p1, string p2, bool p3) => count03++;

            _map.MapOnce(dispatcher, TestEvent.Event00, Listener00);
            _map.MapOnce(dispatcher, TestEvent.Event01, Listener01);
            _map.MapOnce(dispatcher, TestEvent.Event02, Listener02);
            _map.MapOnce(dispatcher, TestEvent.Event03, Listener03);

            Assert.AreEqual(true, _map.ContainsMapInfo(dispatcher, TestEvent.Event00, Listener00));
            Assert.AreEqual(true, _map.ContainsMapInfo(dispatcher, TestEvent.Event01, Listener01));
            Assert.AreEqual(true, _map.ContainsMapInfo(dispatcher, TestEvent.Event02, Listener02));
            Assert.AreEqual(true, _map.ContainsMapInfo(dispatcher, TestEvent.Event03, Listener03));

            dispatcher.Dispatch(TestEvent.Event00);
            dispatcher.Dispatch(TestEvent.Event01, int.MinValue);
            dispatcher.Dispatch(TestEvent.Event02, int.MinValue, string.Empty);
            dispatcher.Dispatch(TestEvent.Event03, int.MinValue, string.Empty, false);

            Assert.AreEqual(count00, 1);
            Assert.AreEqual(count01, 1);
            Assert.AreEqual(count02, 1);
            Assert.AreEqual(count03, 1);

            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event00, Listener00));
            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event01, Listener01));
            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event02, Listener02));
            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event03, Listener03));

            dispatcher.Dispatch(TestEvent.Event00);
            dispatcher.Dispatch(TestEvent.Event01, int.MinValue);
            dispatcher.Dispatch(TestEvent.Event02, int.MinValue, string.Empty);
            dispatcher.Dispatch(TestEvent.Event03, int.MinValue, string.Empty, false);

            Assert.AreEqual(count00, 1);
            Assert.AreEqual(count01, 1);
            Assert.AreEqual(count02, 1);
            Assert.AreEqual(count03, 1);

            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event00, Listener00));
            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event01, Listener01));
            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event02, Listener02));
            Assert.AreEqual(false, _map.ContainsMapInfo(dispatcher, TestEvent.Event03, Listener03));
        }
Ejemplo n.º 2
0
        private readonly CommandBinder _commandBinder;   // The final type must be specified to escape AOT issues.

        public EventDispatcherWithCommandProcessing(CommandBinder commandBinder)
        {
            _dispatcher    = new EventDispatcher();
            _commandBinder = commandBinder;
        }