public void mixed_activators_and_decorators_happy_path()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var decorator1 = new FuncInterceptor <ITarget>(t => new DecoratedTarget(t));
            var decorator2 = new FuncInterceptor <ITarget>(t => new BorderedTarget(t));
            var plan       = new InterceptionPlan(typeof(ITarget), inner, new Policies(), new IInterceptor[]
            {
                decorator1,
                decorator2,
                new ActivatorInterceptor <ITarget>(x => x.Activate()),
                new ActivatorInterceptor <Target>(x => x.TurnGreen())
            });

            var session = new StubBuildSession();

            plan.ToBuilder <ITarget>()(session, session)
            .ShouldBeOfType <BorderedTarget>()
            .Inner.ShouldBeOfType <DecoratedTarget>()
            .Inner.ShouldBeTheSameAs(target);

            target.Color.ShouldEqual("Green");
            target.HasBeenActivated.ShouldBeTrue();
        }
        public void single_decorator_happy_path_that_uses_the_plugin_type()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var decorator = new FuncInterceptor <ITarget>(t => new DecoratedTarget(t));
            var plan      = new InterceptionPlan(typeof(ITarget), inner, new Policies(), new IInterceptor[] { decorator });

            var session = new StubBuildSession();

            plan.ToBuilder <ITarget>()(session, session)
            .ShouldBeOfType <DecoratedTarget>()
            .Inner.ShouldBeTheSameAs(target);
        }
Пример #3
0
        public void intercept_happy_path_with_a_single_activation_that_uses_session()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(),
                new IInterceptor[] {new ActivatorInterceptor<Target>((session, x) => x.UseSession(session))});

            var theSession = new StubBuildSession();
            plan.ToBuilder<ITarget>()(theSession, theSession)
                .ShouldBeTheSameAs(target);

            target.Session.ShouldBeTheSameAs(theSession);
        }
        public void intercept_happy_path_with_a_single_activation_that_uses_session()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var plan = new InterceptionPlan(typeof(ITarget), inner, new Policies(),
                                            new IInterceptor[] { new ActivatorInterceptor <Target>((session, x) => x.UseSession(session)) });

            var theSession = new StubBuildSession();

            plan.ToBuilder <ITarget>()(theSession, theSession)
            .ShouldBeTheSameAs(target);

            target.Session.ShouldBeTheSameAs(theSession);
        }
        public void single_decorator_happy_path_that_uses_the_plugin_type_and_session()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var decorator = new FuncInterceptor <ITarget>((s, t) => new ContextKeepingTarget(s, t));
            var plan      = new InterceptionPlan(typeof(ITarget), inner, new Policies(), new IInterceptor[] { decorator });

            var theSession = new StubBuildSession();
            var result     = plan.ToBuilder <ITarget>()(theSession, theSession)
                             .ShouldBeOfType <ContextKeepingTarget>();

            result.Inner.ShouldBeTheSameAs(target);
            result.Session.ShouldBeTheSameAs(theSession);
        }
        public void intercept_sad_path_with_a_single_activation_that_uses_session()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var plan = new InterceptionPlan(typeof(ITarget), inner, new Policies(),
                                            new IInterceptor[] { new ActivatorInterceptor <Target>((session, x) => x.BlowUpOnSession(session)) });

            var theSession = new StubBuildSession();

            var ex =
                Exception <StructureMapInterceptorException> .ShouldBeThrownBy(
                    () => { plan.ToBuilder <ITarget>()(theSession, theSession); });

            ex.Message.ShouldContain("Target.BlowUpOnSession(IContext)");
        }
        public void multiple_decorators_happy_path()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var decorator1 = new FuncInterceptor <ITarget>(t => new DecoratedTarget(t));
            var decorator2 = new FuncInterceptor <ITarget>(t => new BorderedTarget(t));
            var plan       = new InterceptionPlan(typeof(ITarget), inner, new Policies(), new IInterceptor[] { decorator1, decorator2 });

            var session = new StubBuildSession();

            plan.ToBuilder <ITarget>()(session, session)
            .ShouldBeOfType <BorderedTarget>()
            .Inner.ShouldBeOfType <DecoratedTarget>()
            .Inner.ShouldBeTheSameAs(target);
        }
Пример #8
0
        public void single_decorator_sad_path_that_uses_the_plugin_type_and_session()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var decorator = new FuncInterceptor <ITarget>((s, t) => new SadContextKeepingTarget(s, t));
            var plan      = new InterceptionPlan(typeof(ITarget), inner, Policies.Default(), new IInterceptor[] { decorator });

            var theSession = new StubBuildSession();

            var ex =
                Exception <StructureMapInterceptorException> .ShouldBeThrownBy(
                    () => { plan.ToBuilder <ITarget>()(theSession, theSession); });

            ex.Message.ShouldContain("new SadContextKeepingTarget(IContext, ITarget)");
        }
        public void single_decorator_sad_path_that_uses_the_plugin_type()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var decorator = new FuncInterceptor <ITarget>(t => new ThrowsDecoratedTarget(t));
            var plan      = new InterceptionPlan(typeof(ITarget), inner, new Policies(), new IInterceptor[] { decorator });

            var ex =
                Exception <StructureMapInterceptorException> .ShouldBeThrownBy(
                    () => {
                var session = new StubBuildSession();
                plan.ToBuilder <ITarget>()(session, session);
            });

            ex.Message.ShouldContain("new ThrowsDecoratedTarget(ITarget)");
        }
Пример #10
0
        public void intercept_happy_path_with_a_single_activation()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(),
                new IInterceptor[]
                {
                    new ActivatorInterceptor<ITarget>(x => x.Activate())
                });

            var session = new StubBuildSession();
            plan.ToBuilder<ITarget>()(session, session)
                .ShouldBeTheSameAs(target);

            target.HasBeenActivated.ShouldBeTrue();
        }
Пример #11
0
        public void intercept_happy_path_with_a_single_activation()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var plan = new InterceptionPlan(typeof(ITarget), inner, new Policies(),
                                            new IInterceptor[]
            {
                new ActivatorInterceptor <ITarget>(x => x.Activate())
            });

            var session = new StubBuildSession();

            plan.ToBuilder <ITarget>()(session, session)
            .ShouldBeTheSameAs(target);

            target.HasBeenActivated.ShouldBeTrue();
        }
Пример #12
0
        public void multiple_activators_taking_different_accept_types()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var plan = new InterceptionPlan(typeof(ITarget), inner, new Policies(),
                                            new IInterceptor[]
            {
                new ActivatorInterceptor <ITarget>(x => x.Activate()),
                new ActivatorInterceptor <Target>(x => x.TurnGreen())
            });

            var session = new StubBuildSession();

            plan.ToBuilder <ITarget>()(session, session)
            .ShouldBeTheSameAs(target);

            target.HasBeenActivated.ShouldBeTrue();
            target.Color.ShouldEqual("Green");
        }
Пример #13
0
        public void activator_that_fails_gets_wrapped_in_descriptive_text()
        {
            var target = new Target();
            var inner  = Constant.For(target);

            var interceptor = new ActivatorInterceptor <Target>(x => x.ThrowUp());
            var plan        = new InterceptionPlan(typeof(ITarget), inner, new Policies(),
                                                   new IInterceptor[]
            {
                interceptor
            });

            var ex =
                Exception <StructureMapInterceptorException> .ShouldBeThrownBy(
                    () => {
                var session = new StubBuildSession();
                plan.ToBuilder <ITarget>()(session, session);
            });

            ex.Title.ShouldEqual("Activator interceptor failed during object creation.  See the inner exception for details.");
            ex.Message.ShouldContain(interceptor.Description);
        }
Пример #14
0
        public void intercept_sad_path_with_a_single_activation_that_uses_session()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(),
                new IInterceptor[] {new ActivatorInterceptor<Target>((session, x) => x.BlowUpOnSession(session))});

            var theSession = new StubBuildSession();

            var ex =
                Exception<StructureMapInterceptorException>.ShouldBeThrownBy(
                    () => { plan.ToBuilder<ITarget>()(theSession, theSession); });

            ex.Message.ShouldContain("Target.BlowUpOnSession(IContext)");
        }
        public void single_decorator_sad_path_that_uses_the_plugin_type()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var decorator = new FuncInterceptor<ITarget>(t => new ThrowsDecoratedTarget(t));
            var plan = new InterceptionPlan(typeof (ITarget), inner, new Policies(), new IInterceptor[] {decorator});

            var ex =
                Exception<StructureMapInterceptorException>.ShouldBeThrownBy(
                    () =>
                    {
                        var session = new StubBuildSession();
                        plan.ToBuilder<ITarget>()(session, session);
                    });

            ex.Message.ShouldContain("new ThrowsDecoratedTarget(ITarget)");
        }
Пример #16
0
        public void single_decorator_happy_path_that_uses_the_plugin_type_and_session()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var decorator = new FuncInterceptor<ITarget>((s, t) => new ContextKeepingTarget(s, t));
            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(), new IInterceptor[] {decorator});

            var theSession = new StubBuildSession();
            var result = plan.ToBuilder<ITarget>()(theSession, theSession)
                .ShouldBeOfType<ContextKeepingTarget>();

            result.Inner.ShouldBeTheSameAs(target);
            result.Session.ShouldBeTheSameAs(theSession);
        }
Пример #17
0
        public void single_decorator_sad_path_that_uses_the_plugin_type_and_session()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var decorator = new FuncInterceptor<ITarget>((s, t) => new SadContextKeepingTarget(s, t));
            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(), new IInterceptor[] {decorator});

            var theSession = new StubBuildSession();


            var ex =
                Exception<StructureMapInterceptorException>.ShouldBeThrownBy(
                    () => { plan.ToBuilder<ITarget>()(theSession, theSession); });

            ex.Message.ShouldContain("new SadContextKeepingTarget(IContext, ITarget)");
        }
Пример #18
0
        public void mixed_activators_and_decorators_happy_path()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var decorator1 = new FuncInterceptor<ITarget>(t => new DecoratedTarget(t));
            var decorator2 = new FuncInterceptor<ITarget>(t => new BorderedTarget(t));
            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(), new IInterceptor[]
            {
                decorator1,
                decorator2,
                new ActivatorInterceptor<ITarget>(x => x.Activate()),
                new ActivatorInterceptor<Target>(x => x.TurnGreen())
            });

            var session = new StubBuildSession();
            plan.ToBuilder<ITarget>()(session, session)
                .ShouldBeOfType<BorderedTarget>()
                .Inner.ShouldBeOfType<DecoratedTarget>()
                .Inner.ShouldBeTheSameAs(target);

            target.Color.ShouldBe("Green");
            target.HasBeenActivated.ShouldBeTrue();
        }
Пример #19
0
        public void multiple_decorators_happy_path()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var decorator1 = new FuncInterceptor<ITarget>(t => new DecoratedTarget(t));
            var decorator2 = new FuncInterceptor<ITarget>(t => new BorderedTarget(t));
            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(),
                new IInterceptor[] {decorator1, decorator2});

            var session = new StubBuildSession();
            plan.ToBuilder<ITarget>()(session, session)
                .ShouldBeOfType<BorderedTarget>()
                .Inner.ShouldBeOfType<DecoratedTarget>()
                .Inner.ShouldBeTheSameAs(target);
        }
Пример #20
0
        public void single_decorator_happy_path_that_uses_the_plugin_type()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var decorator = new FuncInterceptor<ITarget>(t => new DecoratedTarget(t));
            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(), new IInterceptor[] {decorator});

            var session = new StubBuildSession();
            plan.ToBuilder<ITarget>()(session, session)
                .ShouldBeOfType<DecoratedTarget>()
                .Inner.ShouldBeTheSameAs(target);
        }
Пример #21
0
        public void activator_that_fails_gets_wrapped_in_descriptive_text()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var interceptor = new ActivatorInterceptor<Target>(x => x.ThrowUp());
            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(),
                new IInterceptor[]
                {
                    interceptor
                });

            var ex =
                Exception<StructureMapInterceptorException>.ShouldBeThrownBy(
                    () =>
                    {
                        var session = new StubBuildSession();
                        plan.ToBuilder<ITarget>()(session, session);
                    });

            ex.Title.Trim().ShouldBe(
                "Activator interceptor failed during object creation.  See the inner exception for details.");
            ex.Message.ShouldContain(interceptor.Description);
        }
Пример #22
0
        public void multiple_activators_taking_different_accept_types()
        {
            var target = new Target();
            var inner = Constant.For(target);

            var plan = new InterceptionPlan(typeof (ITarget), inner, Policies.Default(),
                new IInterceptor[]
                {
                    new ActivatorInterceptor<ITarget>(x => x.Activate()),
                    new ActivatorInterceptor<Target>(x => x.TurnGreen())
                });

            var session = new StubBuildSession();
            plan.ToBuilder<ITarget>()(session, session)
                .ShouldBeTheSameAs(target);

            target.HasBeenActivated.ShouldBeTrue();
            target.Color.ShouldBe("Green");
        }