public void Report()
{
var elevator = new PassiveStateMachine<States, Events>("Elevator");
elevator.DefineHierarchyOn(States.Healthy)
.WithHistoryType(HistoryType.Deep)
.WithInitialSubState(States.OnFloor)
.WithSubState(States.Moving);
elevator.DefineHierarchyOn(States.Moving)
.WithHistoryType(HistoryType.Shallow)
.WithInitialSubState(States.MovingUp)
.WithSubState(States.MovingDown);
elevator.DefineHierarchyOn(States.OnFloor)
.WithHistoryType(HistoryType.None)
.WithInitialSubState(States.DoorClosed)
.WithSubState(States.DoorOpen);
elevator.In(States.Healthy)
.On(Events.ErrorOccured).Goto(States.Error);
elevator.In(States.Error)
.On(Events.Reset).Goto(States.Healthy)
.On(Events.ErrorOccured);
elevator.In(States.OnFloor)
.ExecuteOnEntry(AnnounceFloor)
.ExecuteOnExit(Beep)
.ExecuteOnExit(Beep)
.On(Events.CloseDoor).Goto(States.DoorClosed)
.On(Events.OpenDoor).Goto(States.DoorOpen)
.On(Events.GoUp)
.If(CheckOverload).Goto(States.MovingUp)
.Otherwise()
.Execute(AnnounceOverload)
.Execute(Beep)
.On(Events.GoDown)
.If(CheckOverload).Goto(States.MovingDown)
.Otherwise().Execute(AnnounceOverload);
elevator.In(States.Moving)
.On(Events.Stop).Goto(States.OnFloor);
elevator.Initialize(States.OnFloor);
elevator.Report(this.testee);
string statesReport;
string transitionsReport;
this.stateStream.Position = 0;
using (var reader = new StreamReader(this.stateStream))
{
statesReport = reader.ReadToEnd();
}
this.transitionsStream.Position = 0;
using (var reader = new StreamReader(this.transitionsStream))
{
transitionsReport = reader.ReadToEnd();
}
const string ExpectedTransitionsReport = "Source;Event;Guard;Target;ActionsHealthy;ErrorOccured;;Error;OnFloor;CloseDoor;;DoorClosed;OnFloor;OpenDoor;;DoorOpen;OnFloor;GoUp;CheckOverload;MovingUp;OnFloor;GoUp;;internal transition;AnnounceOverload, BeepOnFloor;GoDown;CheckOverload;MovingDown;OnFloor;GoDown;;internal transition;AnnounceOverloadMoving;Stop;;OnFloor;Error;Reset;;Healthy;Error;ErrorOccured;;internal transition;";
const string ExpectedStatesReport = "Source;Entry;Exit;ChildrenHealthy;;;OnFloor, MovingOnFloor;AnnounceFloor;Beep, Beep;DoorClosed, DoorOpenMoving;;;MovingUp, MovingDownMovingUp;;;MovingDown;;;DoorClosed;;;DoorOpen;;;Error;;;";
statesReport.Replace("\n", string.Empty).Replace("\r", string.Empty)
.Should().Be(ExpectedStatesReport.Replace("\n", string.Empty).Replace("\r", string.Empty));
transitionsReport.Replace("\n", string.Empty).Replace("\r", string.Empty)
.Should().Be(ExpectedTransitionsReport.Replace("\n", string.Empty).Replace("\r", string.Empty));
}