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_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);
        }
Exemplo n.º 3
0
        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);
        }