コード例 #1
0
        public static void Main()
        {
            var context = new StrategyContext(new FirstStrategy());

            context.Execute();
            context.Strategy = new SecondStrategy();
            context.Execute();
        }
コード例 #2
0
        public void DoStuff()
        {
            var context = new StrategyContext(new Strategy0());

            context.Execute();

            context.SetStrategy(new Strategy1());
            context.Execute();
        }
コード例 #3
0
        public void ConcreteStrategyMultiplyTest()
        {
            //arrange
            var             a            = 8;
            var             b            = 3;
            var             properResult = 24;
            IStrategy       strategy     = new Multiply();
            StrategyContext context      = new StrategyContext(strategy);

            //act
            var result = context.Execute(a, b);

            //assert
            Assert.AreEqual(properResult, result);
        }
コード例 #4
0
        public void ConcreteStrategySubtractTest()
        {
            //arrange
            var             a            = 128;
            var             b            = 64;
            var             properResult = 64;
            IStrategy       strategy     = new Subtract();
            StrategyContext context      = new StrategyContext(strategy);

            //act
            var result = context.Execute(a, b);

            //assert
            Assert.AreEqual(properResult, result);
        }