public void Subscribe_Listener_For_Two_Type_Events_Validate()
        {
            // 1) arrange
            var listener = new CallHandleCounter_ForTwoEvents_MockListener();

            // 2) act
            eventAggregator.Subscribe(listener);
            Dictionary <Type, List <IListener> > listeners = FieldReflector.GetListeners(eventAggregator);

            // 3) assert
            Assert.Contains(listener, listeners[typeof(Simple_MockEvent)]);
            Assert.Contains(listener, listeners[typeof(Another_MockEvent)]);
        }
        public void Unsubscribe_Not_Exists_Validate()
        {
            // 1) arrange
            var listener      = new Simple_MockListener();
            var twiceListener = new CallHandleCounter_ForTwoEvents_MockListener();

            // 2) act
            eventAggregator.Subscribe(listener);
            eventAggregator.Unsubscribe <Simple_MockEvent>(twiceListener);
            Dictionary <Type, List <IListener> > listeners = FieldReflector.GetListeners(eventAggregator);

            // 3) assert
            Assert.Contains(listener, listeners[typeof(Simple_MockEvent)]);
        }
示例#3
0
        public void Publish_Two_Listening_Event_Check_AnotherEvent_Test()
        {
            // 1) arrange
            var listener = new CallHandleCounter_ForTwoEvents_MockListener();

            internalEventAggregator.Subscribe(listener);
            var simplyE  = new Simple_MockEvent();
            var anotherE = new Another_MockEvent();

            // 2) act
            internalEventAggregator.Publish(simplyE);
            internalEventAggregator.Publish(anotherE);
            int actual   = listener.RepeatTimesSimplyEvent;
            int expected = 1;

            // 3) assert
            Assert.Equal(expected, actual);
        }
        public void Subscribe_More_The_One_Another_Events_Validate()
        {
            // 1) arrange
            var listenerOne   = MockRepository.GenerateMock <IListener <Simple_MockEvent> >();
            var listenerTwo   = new Simple_MockListener();
            var listenerTwice = new CallHandleCounter_ForTwoEvents_MockListener();

            // 2) act
            eventAggregator.Subscribe(listenerOne);
            eventAggregator.Subscribe(listenerTwo);
            eventAggregator.Subscribe(listenerTwice);
            Dictionary <Type, List <IListener> > listeners = FieldReflector.GetListeners(eventAggregator);
            int expectedCountSimpleEventListeners          = 3;
            int expectedCountAnotherEventListeners         = 1;

            // 3) assert
            Assert.Equal(expectedCountSimpleEventListeners, listeners[typeof(Simple_MockEvent)].Count);
            Assert.Equal(expectedCountAnotherEventListeners, listeners[typeof(Another_MockEvent)].Count);
        }