public void Subscribe_Validate()
        {
            // 1) arrange
            var listener = new Simple_MockListener();

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

            // 3) assert
            Assert.Contains(listener, listeners[typeof(Simple_MockEvent)]);
        }
        public void Subscribe_One_Listener_Two_Times_Validator()
        {
            // arrange
            var listiner = new Simple_MockListener();

            // act // assert
            Assert.Throws <TheSameListenerAlreadySubscribedException>(() =>
            {
                eventAggregator.Subscribe(listiner);
                eventAggregator.Subscribe(listiner);
            });
        }
        public void Unsubscribe_Not_Contains_Listener()
        {
            // 1) arrange
            var listener = new Simple_MockListener();

            // 2) act
            eventAggregator.Unsubscribe(listener);

            // 3) assert
            Dictionary <Type, List <IListener> > listeners = FieldReflector.GetListeners(eventAggregator);

            Assert.DoesNotContain(typeof(Simple_MockEvent), listeners.Keys);
        }
        public void Subscribe_Publish_Generic_Not_Null_Event_Vaslidate()
        {
            // 1) arrange
            var listener = new Simple_MockListener();

            internalEventAggregator.Subscribe(listener);

            // 2) act
            internalEventAggregator.Publish <Simple_MockEvent>();

            // 3) assert
            Assert.NotNull(listener.Event);
        }
        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)]);
        }
        public void Subscribe_More_The_One_Validate()
        {
            // 1) arrange
            var listenerOne = MockRepository.GenerateMock <IListener <Simple_MockEvent> >();
            var listenerTwo = new Simple_MockListener();

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

            // 3) assert
            Assert.Contains(listenerOne, listeners[typeof(Simple_MockEvent)]);
            Assert.Contains(listenerTwo, listeners[typeof(Simple_MockEvent)]);
        }
        public void Subscribe_Publish_The_Same_Info_In_Event_Validate()
        {
            // 1) arrange
            var listener = new Simple_MockListener();

            internalEventAggregator.Subscribe(listener);

            // 2) act
            internalEventAggregator.Publish <Simple_MockEvent>();

            string expected = "Simple_MockEvent";
            string actual   = listener.Event.ChildType;

            // 3) assert
            Assert.Equal(expected, actual);
        }
        public void Subscribe_One_Listener_Two_Times_Catch_Validate()
        {
            // arrange
            var listiner = new Simple_MockListener();

            try
            {
                // act
                eventAggregator.Subscribe(listiner);
                eventAggregator.Subscribe(listiner);
            }
            catch (TheSameListenerAlreadySubscribedException ex)
            {
                // assert
                Assert.Same(listiner, ex.Listener);
            }
        }
        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);
        }