Exemplo n.º 1
0
        public void SimpleTest()
        {
            Context context = new Context();

            context.Action();
            context.Action();
            context.Action();
        }
Exemplo n.º 2
0
        public static void Launch_Strategy()
        {
            // Клиентский код выбирает конкретную стратегию и передаёт её в
            // контекст. Клиент должен знать о различиях между стратегиями,
            // чтобы сделать правильный выбор.
            var context = new Context();

            Console.WriteLine("Однозначное число");
            context.SetStrategy(new SingleDigit());
            context.Action();

            Console.WriteLine();

            Console.WriteLine("Двухзначное число");
            context.SetStrategy(new DoubleDigit());
            context.Action();

            Console.WriteLine();

            Console.WriteLine("Многозначное число");
            context.SetStrategy(new ManyDigit());
            context.Action();
        }
Exemplo n.º 3
0
        public void TestState()
        {
            var expectedFinalState = "Done(已完成)";
            var actualFinalState   = string.Empty;

            var context = new Context();

            while (context.CurrentState != null)
            {
                actualFinalState = context.CurrentState.ToString();
                Trace.WriteLine($"需求目前狀態={actualFinalState}");
                context.Action();
            }

            Assert.Equal(expectedFinalState, actualFinalState);
        }
Exemplo n.º 4
0
 public void ProcessKey(Gdk.ModifierType modifiers, Key key, char ch)
 {
     Context.Build(modifiers, key, ch);
     if (Context.Error != null)
     {
         Reset(Context.Error);
     }
     else if (Context.Action != null)
     {
         Context.Action(this);
         Reset("");
     }
     else
     {
         Message = Context.Message;
     }
 }