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 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 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 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();
            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 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 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 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 can_build_with_array_dependency()
        {
            var gateway1 = new StubbedGateway();
            var gateway2 = new StubbedGateway();
            var gateway3 = new StubbedGateway();

            var build = new ConcreteBuild <GatewayArrayUser>();
            var array = new ArrayDependencySource(typeof(IGateway),
                                                  Constant.For(gateway1),
                                                  Constant.For(gateway2),
                                                  Constant.For(gateway3));

            build.ConstructorArgs(array);

            var arrayUser = build.Build <GatewayArrayUser>(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>();
        }
Esempio n. 13
0
        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);
        }