public void SetUp() { gateway1 = new StubbedGateway(); gateway2 = new StubbedGateway(); gateway3 = new StubbedGateway(); theSession = new FakeBuildSession(); theSession.LifecycledObjects[typeof (IGateway)][new FakeInstance()] = gateway1; theSession.LifecycledObjects[typeof (IGateway)][new FakeInstance()] = gateway2; theSession.LifecycledObjects[typeof (IGateway)][new FakeInstance()] = gateway3; }
public AllPossibleEnumerableDependency_resolution_Tester() { gateway1 = new StubbedGateway(); gateway2 = new StubbedGateway(); gateway3 = new StubbedGateway(); theSession = new FakeBuildSession(); theSession.LifecycledObjects[typeof(IGateway)][new FakeInstance()] = gateway1; theSession.LifecycledObjects[typeof(IGateway)][new FakeInstance()] = gateway2; theSession.LifecycledObjects[typeof(IGateway)][new FakeInstance()] = gateway3; }
public void can_resolve_through_build_session() { var session = new FakeBuildSession(); var gateway = new StubbedGateway(); session.SetDefault<IGateway>(gateway); var build = new ConcreteBuild<GuyWhoUsesGateway>(); build.ConstructorArgs(new DefaultDependencySource(typeof(IGateway))); build.Build<GuyWhoUsesGateway>(session) .Gateway.ShouldBeTheSameAs(gateway); }
public void try_a_simple_constructor_with_all_constants() { var step = ConcreteBuild<CtorTarget>.For(() => new CtorTarget("", 0)); step.Constructor.Add(Constant.For("Jeremy")); step.Constructor.Add(Constant.For(39)); var context = new FakeBuildSession(); var target = step.Build<CtorTarget>(context); target.Name.ShouldBe("Jeremy"); target.Age.ShouldBe(39); }
public void SetUp() { theTarget = new BuildTarget(); theInstance = new ObjectInstance(theTarget); theInterceptors = new IInterceptor[0]; theInner = Constant.For(theTarget); _plan = new Lazy<BuildPlan>(() => new BuildPlan(typeof (IBuildTarget), theInstance, theInner, new Policies(), theInterceptors)); theSession = new FakeBuildSession(); }
public void can_resolve_through_build_session() { var session = new FakeBuildSession(); var gateway = new StubbedGateway(); var gateway2 = new StubbedGateway(); session.NamedObjects[typeof(IGateway)]["Red"] = gateway; session.NamedObjects[typeof(IGateway)]["Blue"] = gateway2; var build = new ConcreteBuild<GuyWhoUsesGateway>(); build.ConstructorArgs(new ReferencedDependencySource(typeof(IGateway), "Blue")); build.Build<GuyWhoUsesGateway>(session) .Gateway.ShouldBeTheSameAs(gateway2); }
public BuildPlanTester() { theTarget = new BuildTarget(); theInstance = new ObjectInstance(theTarget); theInterceptors = new IInterceptor[0]; theInner = Constant.For(theTarget); plan = new Lazy<BuildPlan>( () => new BuildPlan(typeof(IBuildTarget), theInstance, theInner, Policies.Default(), theInterceptors)); theSession = new FakeBuildSession(); }
public void SetUp() { var build = new ConcreteBuild<Game>(); build.Constructor.Add(new ConcreteBuild<SportsTeam>() .ConstructorArgs("San Diego", "Chargers")); build.Constructor.Add(new ConcreteBuild<SportsTeam>() .ConstructorArgs("Kansas City", "Chiefs")); build.Set(x => x.Stadium, "Qualcomm Stadium"); build.Set(x => x.Referee, new ConcreteBuild<Referee>().ConstructorArgs("John", "Smith")); var session = new FakeBuildSession(); game = build.Build(session, session).As<Game>(); }
public void can_use_lifecyle_resolver_for_dependency() { var build = new ConcreteBuild<LifecycleTarget>(); var gateway = new StubbedGateway(); var instance = new ObjectInstance(gateway); var session = new FakeBuildSession(); session.LifecycledObjects[typeof (IGateway)][instance] = gateway; var arg = new LifecycleDependencySource(typeof (IGateway), instance); build.ConstructorArgs(arg); var target = build.Build<LifecycleTarget>(session); target.Gateway.ShouldBeTheSameAs(gateway); }
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 can_build_setters_on_an_existing_object() { var target = new SetterTarget(); var gateway = new StubbedGateway(); var session = new FakeBuildSession(); session.SetDefault<IGateway>(gateway); var plan = new BuildUpPlan<SetterTarget>(); plan.Set(x => x.Color, "Red"); plan.Set(x => x.Direction, "Green"); plan.Set(x => x.Gateway, new DefaultDependencySource(typeof (IGateway))); plan.BuildUp(session, session, target); target.Color.ShouldBe("Red"); target.Direction.ShouldBe("Green"); target.Gateway.ShouldBeTheSameAs(gateway); }
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); }
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); }