Esempio n. 1
0
        public void hook_receives_mediator_and_mediatedItem()
        {
            SupportView mediatedItem     = new SupportView();
            object      injectedMediator = null;
            object      injectedView     = null;

            injector.Map(typeof(Action <MediatorHook>), "callback").ToValue((Action <MediatorHook>) delegate(MediatorHook hook) {
                injectedMediator = hook.mediator;
                injectedView     = hook.mediatedItem;
            });

            MediatorMapping mapping = new MediatorMapping(CreateTypeFilter(
                                                              new Type[1] {
                typeof(SupportView)
            }),
                                                          typeof(ViewInjectedMediator));

            mapping.WithHooks(typeof(MediatorHook));

            factory.CreateMediators(mediatedItem, typeof(SupportView), new List <IMediatorMapping> {
                mapping
            });

            Assert.That(injectedMediator, Is.InstanceOf <ViewInjectedMediator>());
            Assert.That(injectedView, Is.EqualTo(mediatedItem));
        }
Esempio n. 2
0
        /*============================================================================*/
        /* Private Functions                                                          */
        /*============================================================================*/

        private int HookCallCount(params object[] hooks)
        {
            int    hookCallCount = 0;
            Action hookCallback  = delegate() {
                hookCallCount++;
            };

            injector.Map(typeof(Action), "hookCallback").ToValue(hookCallback);

            MediatorMapping mapping = new MediatorMapping(CreateTypeFilter(new Type[1] {
                typeof(SupportView)
            }), typeof(CallbackMediator));

            mapping.WithHooks(hooks);
            factory.CreateMediators(new SupportView(), typeof(SupportView), new List <IMediatorMapping> {
                mapping
            });
            return(hookCallCount);
        }