public void NullItem() { Builder builder = new Builder(); StrategyChain strategies = new StrategyChain(); Assert.Throws <ArgumentNullException>( delegate { builder.TearDown <object>(null, null, null, strategies, null); }); }
public void EmptyStrategies() { Builder builder = new Builder(); StrategyChain strategies = new StrategyChain(); Assert.Throws <ArgumentNullException>( delegate { builder.TearDown(null, null, null, strategies, new object()); }); }
public void StrategyStagesRunInProperOrder() { Builder builder = new Builder(); StrategyChain strategies = new StrategyChain(); strategies.Add(new StringConcatStrategy("1")); strategies.Add(new StringConcatStrategy("2")); strategies.Add(new StringConcatStrategy("3")); strategies.Add(new StringConcatStrategy("4")); string s = builder.BuildUp <string>(null, null, null, strategies, null, null); Assert.Equal("1234", s); }
public void StrategiesRunInReverseOrder() { Builder builder = new Builder(); StrategyChain strategies = new StrategyChain(); strategies.Add(new StringConcatStrategy("1")); strategies.Add(new StringConcatStrategy("2")); strategies.Add(new StringConcatStrategy("3")); strategies.Add(new StringConcatStrategy("4")); string s = builder.TearDown(null, null, null, strategies, ""); Assert.Equal("4321", s); }
public void InnerStrategiesComeBeforeOuterStrategiesInStrategyChain() { StagedStrategyChain <FakeStage> innerChain = new StagedStrategyChain <FakeStage>(); StagedStrategyChain <FakeStage> outerChain = new StagedStrategyChain <FakeStage>(innerChain); FakeStrategy innerStrategy = new FakeStrategy(); FakeStrategy outerStrategy = new FakeStrategy(); innerChain.Add(innerStrategy, FakeStage.Stage1); outerChain.Add(outerStrategy, FakeStage.Stage1); StrategyChain chain = outerChain.MakeStrategyChain(); AssertOrder(chain, innerStrategy, outerStrategy); }
public StrategyChain MakeStrategyChain() { lock (lockObject) { StrategyChain result = new StrategyChain(); foreach (TStageEnum stage in stageValues) { result.AddRange(GetStrategiesInStage(stage)); } return(result); } }
public void PoliciesSetDuringBuildUpDoNotPersistAfterBuildUpComplete() { Builder builder = new Builder(); PolicyList policies = new PolicyList(); StrategyChain strategies = new StrategyChain(); PolicySettingStrategy setStrategy = new PolicySettingStrategy(); PolicyGettingStrategy getStrategy = new PolicyGettingStrategy(); strategies.Add(setStrategy); strategies.Add(getStrategy); builder.BuildUp <object>(null, null, policies, strategies, null, null); Assert.Same(setStrategy.Policy, getStrategy.Policy); Assert.Null(policies.Get <FakePolicy>(typeof(object))); }
public void MultipleChildContainers() { StagedStrategyChain <FakeStage> innerChain = new StagedStrategyChain <FakeStage>(); StagedStrategyChain <FakeStage> outerChain = new StagedStrategyChain <FakeStage>(innerChain); StagedStrategyChain <FakeStage> superChain = new StagedStrategyChain <FakeStage>(outerChain); FakeStrategy innerStrategy = new FakeStrategy(); FakeStrategy outerStrategy = new FakeStrategy(); FakeStrategy superStrategy = new FakeStrategy(); innerChain.Add(innerStrategy, FakeStage.Stage1); outerChain.Add(outerStrategy, FakeStage.Stage1); superChain.Add(superStrategy, FakeStage.Stage1); StrategyChain chain = superChain.MakeStrategyChain(); AssertOrder(chain, innerStrategy, outerStrategy, superStrategy); }
public void OrderingAcrossStagesForStrategyChain() { StagedStrategyChain <FakeStage> innerChain = new StagedStrategyChain <FakeStage>(); StagedStrategyChain <FakeStage> outerChain = new StagedStrategyChain <FakeStage>(innerChain); FakeStrategy innerStage1 = new FakeStrategy(); FakeStrategy innerStage2 = new FakeStrategy(); FakeStrategy outerStage1 = new FakeStrategy(); FakeStrategy outerStage2 = new FakeStrategy(); innerChain.Add(innerStage1, FakeStage.Stage1); innerChain.Add(innerStage2, FakeStage.Stage2); outerChain.Add(outerStage1, FakeStage.Stage1); outerChain.Add(outerStage2, FakeStage.Stage2); StrategyChain chain = outerChain.MakeStrategyChain(); AssertOrder(chain, innerStage1, outerStage1, innerStage2, outerStage2); }
public IBuilderStrategy FindStrategy(Predicate <IBuilderStrategy> match) { // TODO: This is pretty non-optimal; chains should be enumerable, even staged chains StrategyChain chain = strategies.MakeStrategyChain(); IBuilderStrategy strategy = chain.Head; while (strategy != null) { if (match(strategy)) { return(strategy); } strategy = chain.GetNext(strategy); } return(null); }