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); }
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); }
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); }
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); }
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); }