Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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);
            }