public void EventsQueueing( IAsyncStateMachine <string, int> machine, AutoResetEvent signal) { const int firstEvent = 0; const int secondEvent = 1; "establish an active state machine with transitions".x(() => { signal = new AutoResetEvent(false); var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>(); stateMachineDefinitionBuilder.In("A").On(firstEvent).Goto("B"); stateMachineDefinitionBuilder.In("B").On(secondEvent).Goto("C"); stateMachineDefinitionBuilder.In("C").ExecuteOnEntry(() => signal.Set()); machine = stateMachineDefinitionBuilder .WithInitialState("A") .Build() .CreateActiveStateMachine(); }); "when firing an event onto the state machine".x(async() => { await machine.Fire(firstEvent); await machine.Fire(secondEvent); await machine.Start(); }); "it should queue event at the end".x(() => signal .WaitOne(1000) .Should() .BeTrue("state machine should arrive at destination state")); }
public void EventsQueueing( IAsyncStateMachine <string, int> machine) { const int FirstEvent = 0; const int SecondEvent = 1; var arrived = false; "establish a passive state machine with transitions".x(() => { var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>(); stateMachineDefinitionBuilder.In("A").On(FirstEvent).Goto("B"); stateMachineDefinitionBuilder.In("B").On(SecondEvent).Goto("C"); stateMachineDefinitionBuilder.In("C").ExecuteOnEntry(() => arrived = true); machine = stateMachineDefinitionBuilder .WithInitialState("A") .Build() .CreatePassiveStateMachine(); }); "when firing an event onto the state machine".x(() => { machine.Fire(FirstEvent); machine.Fire(SecondEvent); machine.Start(); }); "it should queue event at the end".x(() => arrived.Should().BeTrue("state machine should arrive at destination state")); }