Пример #1
0
        public void BuildIgnoresClassWithoutInterface()
        {
            var strategy = new BuilderAwareStrategy();
            var context = new MockBuilderContext();
            var obj = new Ignorant();

            context.Strategies.Add(strategy);

            context.ExecuteBuildUp(new NamedTypeBuildKey<Ignorant>(), obj);

            Assert.IsFalse(obj.OnBuiltUp__Called);
            Assert.IsFalse(obj.OnTearingDown__Called);
        }
Пример #2
0
        public void BuildChecksConcreteTypeAndNotRequestedType()
        {
            var strategy = new BuilderAwareStrategy();
            var context = new MockBuilderContext();
            var obj = new Aware();

            context.Strategies.Add(strategy);

            context.ExecuteBuildUp(new NamedTypeBuildKey<Aware>(), obj);

            Assert.IsTrue(obj.OnBuiltUp__Called);
            Assert.IsFalse(obj.OnTearingDown__Called);
        }
Пример #3
0
        public void StrategyGetsBuildPlanFromPolicySet()
        {
            MockBuilderContext context = new MockBuilderContext();
            context.Strategies.Add(new BuildPlanStrategy());
            object instance = new object();
            ReturnInstanceBuildPlan plan = new ReturnInstanceBuildPlan(instance);

            context.Policies.Set<IBuildPlanPolicy>(plan, new NamedTypeBuildKey<object>());

            object result = context.ExecuteBuildUp(new NamedTypeBuildKey<object>(), null);

            Assert.IsTrue(plan.BuildUpCalled);
            Assert.AreSame(instance, result);
        }
Пример #4
0
        public void BuildCallsClassWithInterface()
        {
            var strategy = new BuilderAwareStrategy();
            var context = new MockBuilderContext();
            var obj = new Aware();

            context.Strategies.Add(strategy);

            context.ExecuteBuildUp(new NamedTypeBuildKey<Aware>(), obj);

            Assert.IsTrue(obj.OnBuiltUp__Called);
            Assert.IsFalse(obj.OnTearingDown__Called);
            Assert.AreEqual(new NamedTypeBuildKey<Aware>(), obj.OnBuiltUp_BuildKey);
        }
Пример #5
0
        public void StrategyCreatesBuildPlanWhenItDoesntExist()
        {
            MockBuilderContext context = new MockBuilderContext();
            context.Strategies.Add(new BuildPlanStrategy());
            MockBuildPlanCreatorPolicy policy = new MockBuildPlanCreatorPolicy();
            context.Policies.SetDefault<IBuildPlanCreatorPolicy>(policy);

            object result = context.ExecuteBuildUp(new NamedTypeBuildKey<object>(), null);

            Assert.IsNotNull(result);
            Assert.IsTrue(policy.PolicyWasCreated);

            IBuildPlanPolicy plan = context.Policies.Get<IBuildPlanPolicy>(new NamedTypeBuildKey(typeof(object)));
            Assert.IsNotNull(plan);
        }