Beispiel #1
0
        public void Internal()
        {
            var move = new TestMove();

            move.Init(MoveMode.Immediately);
            var list = new Stack <MoveTestInternamMethodName>();

            move.InternalCalls += type => list.Push(type);
            move.Step();

            Assert.AreEqual(MoveTestInternamMethodName.OnCompleted, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnFinished, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnAction, list.Pop());

            move = new TestMove();
            move.Init(MoveMode.Infinity);
            list = new Stack <MoveTestInternamMethodName>();
            move.InternalCalls += type => list.Push(type);
            move.Step();

            Assert.AreEqual(MoveTestInternamMethodName.OnStart, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnAction, list.Pop());
            move.Step();
            Assert.AreEqual(MoveTestInternamMethodName.OnProgress, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnAction, list.Pop());
            move.Step();
            Assert.AreEqual(MoveTestInternamMethodName.OnProgress, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnAction, list.Pop());
            move.Finish();
            move.Step();
            Assert.AreEqual(MoveTestInternamMethodName.OnCompleted, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnFinished, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnAction, list.Pop());


            move = new TestMove();
            move.Init(MoveMode.Infinity);
            list = new Stack <MoveTestInternamMethodName>();
            move.InternalCalls += type => list.Push(type);
            move.Step();

            Assert.AreEqual(MoveTestInternamMethodName.OnStart, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnAction, list.Pop());
            move.Cancel();
            move.Step();
            Assert.AreEqual(MoveTestInternamMethodName.OnCanceled, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnFinished, list.Pop());
            Assert.AreEqual(MoveTestInternamMethodName.OnAction, list.Pop());
        }
Beispiel #2
0
        public void States()
        {
            var move = new TestMove();

            Assert.AreEqual(MoveState.Initial, move.State);

            move = new TestMove();
            move.Init(MoveMode.Immediately);
            Assert.AreEqual(MoveState.Initial, move.State);
            move.MarkInQueue();
            Assert.AreEqual(MoveState.InQueue, move.State);

            var result = move.Step();

            Assert.AreEqual(MoveState.Completed, move.State);
            Assert.AreEqual(MoveStepResult.ImmediatelyDone, result);

            //

            move = new TestMove();
            move.Init(MoveMode.OneStep);
            Assert.AreEqual(MoveState.Initial, move.State);
            move.MarkInQueue();
            Assert.AreEqual(MoveState.InQueue, move.State);

            result = move.Step();
            Assert.AreEqual(MoveState.Started, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            result = move.Step();
            Assert.AreEqual(MoveState.Completed, move.State);
            Assert.AreEqual(MoveStepResult.ImmediatelyDone, result);

            //

            move = new TestMove();
            move.Init(4);
            Assert.AreEqual(MoveState.Initial, move.State);
            move.MarkInQueue();
            Assert.AreEqual(MoveState.InQueue, move.State);

            result = move.Step();
            Assert.AreEqual(3, move.StepsLeft);
            Assert.AreEqual(MoveState.Started, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            result = move.Step();
            Assert.AreEqual(2, move.StepsLeft);
            Assert.AreEqual(MoveState.InProgress, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            result = move.Step();
            Assert.AreEqual(1, move.StepsLeft);
            Assert.AreEqual(MoveState.InProgress, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            result = move.Step();
            Assert.AreEqual(0, move.StepsLeft);
            Assert.AreEqual(MoveState.InProgress, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            result = move.Step();
            Assert.AreEqual(0, move.StepsLeft);
            Assert.AreEqual(MoveState.Completed, move.State);
            Assert.AreEqual(MoveStepResult.ImmediatelyDone, result);

            //

            move = new TestMove();
            move.Init(MoveMode.Infinity);
            Assert.AreEqual(MoveState.Initial, move.State);
            move.MarkInQueue();
            Assert.AreEqual(MoveState.InQueue, move.State);

            result = move.Step();
            Assert.AreEqual(MoveState.Started, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            result = move.Step();
            Assert.AreEqual(MoveState.InProgress, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            for (var i = 0; i < 100; i++)
            {
                result = move.Step();
            }

            Assert.AreEqual(MoveState.InProgress, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            move.Finish();

            result = move.Step();
            Assert.AreEqual(MoveState.Completed, move.State);
            Assert.AreEqual(MoveStepResult.ImmediatelyDone, result);


            //

            move = new TestMove();
            move.Init(MoveMode.Infinity);

            result = move.Step();
            Assert.AreEqual(MoveState.Started, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            for (var i = 0; i < 100; i++)
            {
                result = move.Step();
            }

            Assert.AreEqual(MoveState.InProgress, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            move.Cancel();

            result = move.Step();
            Assert.AreEqual(MoveState.Canceled, move.State);
            Assert.AreEqual(MoveStepResult.Skipped, result);

            //

            move = new TestMove();
            move.Init(MoveMode.Infinity);

            result = move.Step();
            Assert.AreEqual(MoveState.Started, move.State);
            Assert.AreEqual(MoveStepResult.Done, result);

            move.Cancel();

            result = move.Step();
            Assert.AreEqual(MoveState.Canceled, move.State);
            Assert.AreEqual(MoveStepResult.Skipped, result);

            //

            move = new TestMove();
            move.Init(MoveMode.Infinity);

            move.Cancel();

            result = move.Step();
            Assert.AreEqual(MoveState.Canceled, move.State);
            Assert.AreEqual(MoveStepResult.Skipped, result);

            //

            move = new TestMove();
            move.Init(MoveMode.OneStep);

            move.Cancel();

            result = move.Step();
            Assert.AreEqual(MoveState.Canceled, move.State);
            Assert.AreEqual(MoveStepResult.Skipped, result);
        }