Beispiel #1
0
        public async Task NewStateMachine_Should_BeAbleToContinueFromGivenState()
        {
            var falseStep = new SettableStep(2, false);
            var steps     = new List <IStateMachineStep <int, DummyData> >
            {
                new SettableStep(0, true),
                new SettableStep(1, true),
                falseStep,
                new SettableStep(3, true),
                new SettableStep(4, true)
            };

            var data    = new DummyData();
            var machine = new StateMachine <int, DummyData>(steps, 0, data);

            Assert.True(await machine.MoveNextAsync());
            Assert.True(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());

            falseStep.Success = true;

            var state      = machine.State;
            var newMachine = new StateMachine <int, DummyData>(steps, state, data);

            Assert.True(await newMachine.MoveNextAsync());
            Assert.True(await newMachine.MoveNextAsync());
            Assert.False(await newMachine.MoveNextAsync());

            Assert.False(await newMachine.MoveNextAsync());
            Assert.False(await newMachine.MoveNextAsync());
        }
Beispiel #2
0
        public async Task MoveNextAsync_Should_KeepExecutingTheSameStepUntilReturnsTrue()
        {
            var falseStep = new SettableStep(2, false);
            var steps     = new List <IStateMachineStep <int, DummyData> >
            {
                new SettableStep(0, true),
                new SettableStep(1, true),
                falseStep,
                new SettableStep(3, true),
                new SettableStep(4, true)
            };

            var state   = new DummyData();
            var machine = new StateMachine <int, DummyData>(steps, 0, state);

            Assert.True(await machine.MoveNextAsync());
            Assert.True(await machine.MoveNextAsync());

            Assert.False(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());

            falseStep.Success = true;

            Assert.True(await machine.MoveNextAsync());
            Assert.True(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());

            //finished

            Assert.False(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());
            Assert.False(await machine.MoveNextAsync());
        }