예제 #1
0
    public void StartNotInOpenedOrUnlocked()
    {
        StateChart chart = GetChart();

        Assert.IsFalse(chart.IsInState("opened"));
        Assert.IsFalse(chart.IsInState("unlocked"));
    }
예제 #2
0
    public void StartInClosedAndLocked()
    {
        StateChart chart = GetChart();

        Assert.IsTrue(chart.IsInState("closed"));
        Assert.IsTrue(chart.IsInState("locked"));
    }
예제 #3
0
    public void TransitionsToAnotherState()
    {
        StateChart chart = new StateChart((builder) => {
            Action <string, Action> State = builder.State;

            State("State-1", () => {
                builder.Transition <SomeEvt>("State-1-2");

                State("State-1-1", () => {
                    State("State-1-1-1", () => { });
                    State("State-1-1-2", () => { });
                });

                State("State-1-2", () => { });
            });
        });

        chart.Trigger(new SomeEvt());
        chart.Tick();
        Assert.IsTrue(chart.IsInState("State-1"));
        Assert.IsFalse(chart.IsInState("State-1-1"));
        Assert.IsFalse(chart.IsInState("State-1-1-1"));
        Assert.IsFalse(chart.IsInState("State-1-1-2"));
        Assert.IsTrue(chart.IsInState("State-1-2"));
    }
예제 #4
0
    public void ProperlyQueuesEvents()
    {
        StateChart chart = GetChart2();

        Assert.IsTrue(chart.IsInState("closed"));
        chart.Tick();
        Assert.IsTrue(chart.IsInState("opened"));
    }
예제 #5
0
    public void DoesNotTransitionIfGuardFnIsFalse()
    {
        StateChart chart = GetChart();

        chart.Trigger(new Evt_DoorUnlock(false));
        chart.Tick();
        Assert.IsFalse(chart.IsInState("unlocked"));
        Assert.IsTrue(chart.IsInState("closed"));
        Assert.IsFalse(chart.IsInState("opened"));
        Assert.IsTrue(chart.IsInState("locked"));
    }
예제 #6
0
    public void DoesNotTransitionIfNoTransitionHandlerExistsForCongiuration()
    {
        StateChart chart = GetChart();

        chart.Trigger(new Evt_DoorOpen());
        chart.Tick();
        Assert.IsFalse(chart.IsInState("opened"));
        Assert.IsTrue(chart.IsInState("closed"));
        Assert.IsTrue(chart.IsInState("locked"));
        Assert.IsFalse(chart.IsInState("unlocked"));
    }
예제 #7
0
    public void MovesToUnlockedFromClosedWithUnlockEvent()
    {
        StateChart chart = GetChart();

        chart.Trigger(new Evt_DoorUnlock());
        chart.Tick();
        Assert.IsTrue(chart.IsInState("unlocked"));
        Assert.IsTrue(chart.IsInState("closed"));
        Assert.IsFalse(chart.IsInState("opened"));
        Assert.IsFalse(chart.IsInState("locked"));
    }
예제 #8
0
    public void StateChart_SpecSimplePasses()
    {
        StateChart chart = new StateChart((builder) => {
            Action <string, Action> State = builder.State;

            State("State-1", () => {
                State("State-1-1", () => {
                    State("State-1-1-1", () => { });
                    State("State-1-1-2", () => { });
                });
                State("State-1-2", () => { });
            });
        });

        Assert.IsTrue(chart.IsInState("State-1"));
        Assert.IsTrue(chart.IsInState("State-1-1"));
        Assert.IsTrue(chart.IsInState("State-1-1-1"));
        Assert.IsFalse(chart.IsInState("State-1-1-2"));
        Assert.IsFalse(chart.IsInState("State-1-2"));
    }
예제 #9
0
    public void MovesFromClosedAndUnlockedToOpenedAndBackToClosedLocked()
    {
        StateChart chart = GetChart();

        chart.Trigger(new Evt_DoorUnlock());
        chart.Trigger(new Evt_DoorOpen());
        chart.Tick();
        Assert.IsTrue(chart.IsInState("opened"));
        Assert.IsFalse(chart.IsInState("closed"));
        Assert.IsFalse(chart.IsInState("locked"));
        Assert.IsFalse(chart.IsInState("unlocked"));
        chart.Trigger(new Evt_DoorClose());
        chart.Tick();
        Assert.IsFalse(chart.IsInState("opened"));
        Assert.IsTrue(chart.IsInState("closed"));
        Assert.IsFalse(chart.IsInState("locked"));
        Assert.IsTrue(chart.IsInState("unlocked"));
    }