Example #1
0
        public void should_be_able_to_register_listener_and_send_message()
        {
            var mock = MockRepository.GenerateMock<IListenTo<ClockedEvent>.All>();
            distributor.AddListener(mock);

            var clockedEvent1 = new ClockedEvent { ClockCycle = 1 };

            mock.Expect(x => x.Handle(clockedEvent1));

            distributor.SendMessage(clockedEvent1);
            distributor.Distribute(1);

            mock.VerifyAllExpectations();
        }
Example #2
0
        public void should_be_able_to_register_filtered_listeners_and_send_message()
        {
            var mockToAccept = MockRepository.GenerateMock<IListenTo<ClockedEvent>.ThatSatisfy>();
            var mockToFilterOut = MockRepository.GenerateMock<IListenTo<ClockedEvent>.ThatSatisfy>();
            distributor.AddListener(mockToAccept);
            distributor.AddListener(mockToFilterOut);

            var clockedEvent1 = new ClockedEvent { ClockCycle = 1 };

            mockToAccept.Expect(x => x.SatisfiedBy(clockedEvent1)).Return(true);
            mockToAccept.Expect(x => x.Handle(clockedEvent1));

            mockToFilterOut.Expect(x => x.SatisfiedBy(clockedEvent1)).Return(false);
            mockToFilterOut.Expect(x => x.Handle(clockedEvent1)).Repeat.Never();

            distributor.SendMessage(clockedEvent1);
            distributor.Distribute(1);

            mockToAccept.VerifyAllExpectations();
            mockToFilterOut.VerifyAllExpectations();
        }
Example #3
0
        private void OrderedExpectationsForListeners(Action<MethodInvocation> afterHandleAction)
        {
            var mockRepository = new MockRepository();
            var mockA = mockRepository.StrictMock<IListenTo<ClockedEvent>.All>();
            var mockB = mockRepository.StrictMock<IListenTo<ClockedEvent>.All>();
            distributor.AddListener(mockA);
            distributor.AddListener(mockB);

            var clockedEvent1 = new ClockedEvent { ClockCycle = 1 };
            var clockedEvent2 = new ClockedEvent { ClockCycle = 2 };

            using (mockRepository.Ordered())
            {
                using (mockRepository.Unordered())
                {
                    Expect.Call(() => mockA.Handle(clockedEvent1)).WhenCalled(afterHandleAction);
                    Expect.Call(() => mockB.Handle(clockedEvent1)).WhenCalled(afterHandleAction);
                }
                using (mockRepository.Unordered())
                {
                    Expect.Call(() => mockA.Handle(clockedEvent2)).WhenCalled(afterHandleAction);
                    Expect.Call(() => mockB.Handle(clockedEvent2)).WhenCalled(afterHandleAction);
                }
            }

            mockRepository.ReplayAll();

            distributor.SendMessage(clockedEvent1);
            distributor.SendMessage(clockedEvent2);
            distributor.Distribute(1);
            distributor.Distribute(2);

            Thread.Sleep(550);
            mockRepository.VerifyAll();
        }