public void compile_and_use_by_itself()
        {
            var variable = Expression.Variable(typeof(ITarget), "target");

            var expression = theActivator.ToExpression(Policies.Default(), Parameters.Context, variable);

            var lambdaType = typeof(Action<ITarget>);
            var lambda = Expression.Lambda(lambdaType, expression, variable);

            var action = lambda.Compile().As<Action<ITarget>>();

            var target = new Target();
            action(target);

            target.HasBeenActivated.ShouldBeTrue();
        }
        public void compile_and_use_by_itself_not_using_IBuildSession()
        {
            var variable = Expression.Variable(typeof (ITarget), "target");

            var expression = theInterceptor.ToExpression(Policies.Default(), Parameters.Session, variable);

            var lambdaType = typeof (Func<ITarget, ITarget>);
            var lambda = Expression.Lambda(lambdaType, expression, variable);

            var func = lambda.Compile().As<Func<ITarget, ITarget>>();

            var target = new Target();
            var decorated = func(target);

            decorated.ShouldBeOfType<DecoratedTarget>()
                .Inner.ShouldBeTheSameAs(target);
        }
        public void compile_and_use_by_itself_with_session()
        {
            var activator = new ActivatorInterceptor<Target>((s, t) => t.UseSession(s));
            var variable = Expression.Variable(typeof(Target), "target");

            var expression = activator.ToExpression(Policies.Default(), Parameters.Context, variable);

            var lambdaType = typeof(Action<IContext, Target>);
            var lambda = Expression.Lambda(lambdaType, expression, Parameters.Context, variable);

            var action = lambda.Compile().As<Action<IContext, Target>>();

            var target = new Target();
            var session = new FakeBuildSession();
            action(session, target);

            target.Session.ShouldBeTheSameAs(session);
        }
        public void compile_and_use_by_itself_using_IContext()
        {
            theInterceptor = new FuncInterceptor<ITarget>((c, t) => new ContextKeepingTarget(c, t));

            var variable = Expression.Variable(typeof (ITarget), "target");

            var expression = theInterceptor.ToExpression(Policies.Default(), Parameters.Context, variable);

            var lambdaType = typeof (Func<IContext, ITarget, ITarget>);
            var lambda = Expression.Lambda(lambdaType, expression, Parameters.Context, variable);

            var func = lambda.Compile().As<Func<IContext, ITarget, ITarget>>();

            var target = new Target();
            var session = new FakeBuildSession();
            var decorated = func(session, target).ShouldBeOfType<ContextKeepingTarget>();

            decorated
                .Inner.ShouldBeTheSameAs(target);

            decorated.Session.ShouldBeTheSameAs(session);
        }