Пример #1
0
        internal void EventDispatching(
            Type eventType,
            string[] expectedInvocations,
            MessageDispatcher dispatcher,
            Messenger m,
            Messenger sub,
            List <string> invocations
            )
        {
            GIVEN["a Messenger with some registrations a subordinate Messenger"] = () => {
                invocations = new List <string>();
                dispatcher  = new MessageDispatcher(m = new Messenger());
                m.Apply <DerivedEvent>(e => invocations.Add("ROOT-DE"));
                m.Register(sub = new Messenger());
                m.Apply <BaseEvent>(e => invocations.Add("ROOT-BE"));
                sub.Apply <DerivedEvent>(e => invocations.Add("SUB-DE"));
                sub.Apply <TestEvent>(e => invocations.Add("SUB-TE"));
            };

            WHEN["applying the event"] = () => m.ApplyChange((IEvent)Activator.CreateInstance(eventType));
            THEN["the expected handlers are invoked"] = () => invocations.Should().BeEquivalentTo(expectedInvocations);

            WHEN["a subordinate Messenger applies the event"] = () => {
                invocations.Clear();
                sub.ApplyChange((IEvent)Activator.CreateInstance(eventType));
            };
            THEN["the same handlers are invoked"] = () => invocations.Should().BeEquivalentTo(expectedInvocations);
        }