public static ConcreteBuild BuildSource(Type pluggedType, ConstructorInfo constructor, DependencyCollection dependencies, Policies policies) { ConcreteBuild plan = null; try { var ctorStep = BuildConstructorStep(pluggedType, constructor, dependencies, policies); plan = new ConcreteBuild(pluggedType, ctorStep); determineSetterSources(pluggedType, dependencies, policies, plan); } catch (StructureMapException e) { e.Push("Attempting to create a build plan for concrete type " + pluggedType.GetFullName()); throw; } catch (Exception e) { throw new StructureMapConfigurationException( "Attempting to create a build plan for concrete type " + pluggedType.GetFullName(), e); } return plan; }
public void ConcreteBuild_accepts_Visitor() { var build = new ConcreteBuild<StubbedGateway>(); build.AcceptVisitor(theVisitor); theVisitor.AssertWasCalled(x => x.Concrete(build)); }
public void ConcreteBuild_accepts_Visitor() { var build = new ConcreteBuild<StubbedGateway>(); build.AcceptVisitor(theVisitor); theVisitor.Received().Concrete(build); }
public void ConcreteBuild_accepts_Visitor() { var build = new ConcreteBuild <StubbedGateway>(); build.AcceptVisitor(theVisitor); theVisitor.Received().Concrete(build); }
public void ConcreteBuild_accepts_Visitor() { var build = new ConcreteBuild <StubbedGateway>(); build.AcceptVisitor(theVisitor); theVisitor.AssertWasCalled(x => x.Concrete(build)); }
public void can_build_with_list_dependency() { var build = new ConcreteBuild <GatewayListUser>(); build.ConstructorArgs(new AllPossibleValuesDependencySource(typeof(List <IGateway>))); var arrayUser = build.Build <GatewayListUser>(theSession); arrayUser.Gateways.ShouldHaveTheSameElementsAs(gateway1, gateway2, gateway3); }
public void happily_throws_build_exception_with_description_of_the_constructor() { var ex = Exception <StructureMapBuildException> .ShouldBeThrownBy(() => { var build = new ConcreteBuild <ClassThatBlowsUp>(); var session = new StubBuildSession(); build.Build(session, session); }); Debug.WriteLine(ex); }
public void happily_throws_build_exception_with_description_of_the_constructor() { var ex = Exception<StructureMapBuildException>.ShouldBeThrownBy(() => { var build = new ConcreteBuild<ClassThatBlowsUp>(); var session = new StubBuildSession(); build.Build(session, session); }); Debug.WriteLine(ex); }
public void can_build_with_ienumerable_dependency() { var build = new ConcreteBuild <GatewayEnumerableUser>(); build.ConstructorArgs(new AllPossibleValuesDependencySource(typeof(IEnumerable <IGateway>))); var enumerableUser = build.Build <GatewayEnumerableUser>(theSession); enumerableUser.Gateways.ShouldHaveTheSameElementsAs(gateway1, gateway2, gateway3); }
public void can_build_with_ienumerable_dependency() { var build = new ConcreteBuild<GatewayEnumerableUser>(); build.ConstructorArgs(new AllPossibleValuesDependencySource(typeof(IEnumerable<IGateway>))); var enumerableUser = build.Build<GatewayEnumerableUser>(theSession); enumerableUser.Gateways.ShouldHaveTheSameElementsAs(gateway1, gateway2, gateway3); }
public void can_build_with_list_dependency() { var build = new ConcreteBuild<GatewayListUser>(); build.ConstructorArgs(new AllPossibleValuesDependencySource(typeof(List<IGateway>))); var arrayUser = build.Build<GatewayListUser>(theSession); arrayUser.Gateways.ShouldHaveTheSameElementsAs(gateway1, gateway2, gateway3); }
public void simple_creation_of_properties_with_only_constants() { var step = new ConcreteBuild<SetterTarget>(); step.Set(x => x.Color, "Red"); step.Set(x => x.Direction, "North"); var target = step.Build<SetterTarget>(new FakeBuildSession()); target.Color.ShouldBe("Red"); target.Direction.ShouldBe("North"); }
public void simple_creation_of_properties_with_only_constants() { var step = new ConcreteBuild<SetterTarget>(); step.Set(x => x.Color, "Red"); step.Set(x => x.Direction, "North"); var builder = (Func<IContext, SetterTarget>) step.ToDelegate(); SetterTarget target = builder(new FakeContext()); target.Color.ShouldEqual("Red"); target.Direction.ShouldEqual("North"); }
public void simple_creation_of_fields_with_only_constants() { var step = new ConcreteBuild <FieldTarget>(); step.Set(x => x.Color, "Red"); step.Set(x => x.Direction, "North"); var target = step.Build <FieldTarget>(new FakeBuildSession()); target.Color.ShouldBe("Red"); target.Direction.ShouldBe("North"); }
public void simple_creation_of_fields_with_only_constants() { var step = new ConcreteBuild <FieldTarget>(); step.Set(x => x.Color, "Red"); step.Set(x => x.Direction, "North"); var builder = (Func <IContext, FieldTarget>)step.ToDelegate(); FieldTarget target = builder(new FakeContext()); target.Color.ShouldEqual("Red"); target.Direction.ShouldEqual("North"); }
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 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 <int>(39)); var context = new FakeBuildSession(); var target = step.Build <CtorTarget>(context); target.Name.ShouldEqual("Jeremy"); target.Age.ShouldEqual(39); }
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 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 <int>(39)); var context = new FakeContext(); var builder = (Func <IContext, CtorTarget>)step.ToDelegate(); var target = builder(context); target.Name.ShouldEqual("Jeremy"); target.Age.ShouldEqual(39); }
public void with_all_constants() { var build = new ConcreteBuild<MixedTarget>(); build.Constructor.Add(Constant.For("Jeremy")); build.Constructor.Add(Constant.For("Red")); build.Set(x => x.Direction, "South"); build.Set(x => x.Description, "Something"); var target = build.Build<MixedTarget>(new FakeBuildSession()); target.Name.ShouldEqual("Jeremy"); target.Color.ShouldEqual("Red"); target.Direction.ShouldEqual("South"); target.Description.ShouldEqual("Something"); }
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 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 with_all_constants() { var build = new ConcreteBuild <MixedTarget>(); build.Constructor.Add(Constant.For("Jeremy")); build.Constructor.Add(Constant.For("Red")); build.Set(x => x.Direction, "South"); build.Set(x => x.Description, "Something"); var target = build.Build <MixedTarget>(new FakeBuildSession()); target.Name.ShouldEqual("Jeremy"); target.Color.ShouldEqual("Red"); target.Direction.ShouldEqual("South"); target.Description.ShouldEqual("Something"); }
public void can_build_with_list_dependency() { var gateway1 = new StubbedGateway(); var gateway2 = new StubbedGateway(); var gateway3 = new StubbedGateway(); var build = new ConcreteBuild <GatewayListUser>(); var array = new ListDependencySource(typeof(IGateway), Constant.For(gateway1), Constant.For(gateway2), Constant.For(gateway3)); build.ConstructorArgs(array); var arrayUser = build.Build <GatewayListUser>(new FakeBuildSession()); arrayUser.Gateways.ShouldHaveTheSameElementsAs(gateway1, gateway2, gateway3); }
public void with_all_constants() { var build = new ConcreteBuild<MixedTarget>(); build.Constructor.Add(Constant.For("Jeremy")); build.Constructor.Add(Constant.For("Red")); build.Set(x => x.Direction, "South"); build.Set(x => x.Description, "Something"); var builder = build.ToDelegate().As<Func<IContext, MixedTarget>>(); var target = builder(new FakeContext()); target.Name.ShouldEqual("Jeremy"); target.Color.ShouldEqual("Red"); target.Direction.ShouldEqual("South"); target.Description.ShouldEqual("Something"); }
public void can_build_with_list_dependency() { var gateway1 = new StubbedGateway(); var gateway2 = new StubbedGateway(); var gateway3 = new StubbedGateway(); var build = new ConcreteBuild<GatewayListUser>(); var array = new ListDependencySource(typeof (IGateway), Constant.For(gateway1), Constant.For(gateway2), Constant.For(gateway3)); build.ConstructorArgs(array); var arrayUser = build.Build<GatewayListUser>(new FakeBuildSession()); arrayUser.Gateways.ShouldHaveTheSameElementsAs(gateway1, gateway2, gateway3); }
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 with_all_constants() { var build = new ConcreteBuild <MixedTarget>(); build.Constructor.Add(Constant.For("Jeremy")); build.Constructor.Add(Constant.For("Red")); build.Set(x => x.Direction, "South"); build.Set(x => x.Description, "Something"); var builder = build.ToDelegate().As <Func <IContext, MixedTarget> >(); var target = builder(new FakeContext()); target.Name.ShouldEqual("Jeremy"); target.Color.ShouldEqual("Red"); target.Direction.ShouldEqual("South"); target.Description.ShouldEqual("Something"); }
public void Concrete(ConcreteBuild build) { _writer.Line(build.Description); }
public void Concrete(ConcreteBuild build) { _writer.Line(build.Description); }