protected internal override IStateMachine <StateBase, EventBase> CreateSut() { var configuration = StateMachineConfigurationFactory.CreateEvent < StateBase, EventBase, GeneratedEventBase>(); configuration.ConfigureState <InitialState>(1) .Transition <TestCommand>((s, e) => new TestState()) .TransitionWithEvent <TransitionEventCommand>((s, e) => { if (e.GenerateEvent) { return(new TestState(), new FirstEvent()); } else { return(new TestState(), null); } }) .OnLeave(s => this.transitionsTester.Object.OnLeaveInitial(s)); configuration.ConfigureState <TestState>(1) .OnEnter(s => this.transitionsTester.Object.OnEnterTest(s)) .Transition <StartDetectionCommand>((s, e) => new DetectingState(false, new List <Device>())) .Transition <TestCommand>((s, e) => new TestState()) .OnLeave(s => this.transitionsTester.Object.OnLeaveTest(s)); configuration.ConfigureAsyncState <DetectingState>(6) .RunAsync(async s => { try { await this.detectionManager.Object.Detect(); return(new DetectionCompletedSuccess()); } catch (OperationCanceledException) { return(new DetectionCancelled()); } catch (Exception) { return(new DetectionCompletedFailure()); } }) .TransitionWithEvent <TransitionEventCommand>((s, e) => { if (e.GenerateEvent) { return(new DetectingState(s.WaitingCancellation, s.DetectedDevices), new FirstEvent()); } else { return(new DetectingState(s.WaitingCancellation, s.DetectedDevices), null); } }) .Transition <TestCommand>((s, e) => new DetectingState(s.WaitingCancellation, s.DetectedDevices)) .Transition <DeviceDetected>((s, e) => { s.DetectedDevices.Add(e.Device); return(new DetectingState(s.WaitingCancellation, s.DetectedDevices)); }) .Transition <DetectionCompletedSuccess>((s, e) => new DetectionSuccessState(s.DetectedDevices)) .OnLeave(s => this.transitionsTester.Object.OnLeaveDetecting(s)); configuration.ConfigureState <DetectionSuccessState>(2) .Transition <StartDetectionCommand>((s, e) => new DetectingState(false, new List <Device>())) .Transition <GoBackCommand>((s, e) => new InitialState()); return(StateMachineFactory.CreateEvent(new InitialState(), configuration)); }