Exemple #1
0
        public void Test_demo()
        {
            Record record = new Record();

            StateA stateA = new StateA();
            StateB stateB = new StateB();

            DemoContext context = new DemoContext(stateA);

            {
                context.RequestA(record);
                Assert.That(record.HandlerType, Is.EqualTo(HandlerType.A));
                Assert.That(record.StateType, Is.EqualTo(StateType.A));
            }
            {
                context.RequestB(record);
                Assert.That(record.HandlerType, Is.EqualTo(HandlerType.B));
                Assert.That(record.StateType, Is.EqualTo(StateType.A));
            }

            context.TransitorTo(stateB);

            {
                context.RequestA(record);
                Assert.That(record.HandlerType, Is.EqualTo(HandlerType.A));
                Assert.That(record.StateType, Is.EqualTo(StateType.B));
            }
            {
                context.RequestB(record);
                Assert.That(record.HandlerType, Is.EqualTo(HandlerType.B));
                Assert.That(record.StateType, Is.EqualTo(StateType.B));
            }
        }