private Action startStateMachineAndPrepareSecondStart(StateResult first, StateResult second) { var observable = stateMachineFinised(); StateMachine.Start(first.Transition()); observable.Wait(); return(() => StateMachine.Start(second.Transition())); }
public void DoesNotGetStuckInADeadlockWhenSomeTransitionTimeOuts(int n) { Reset(); var someResult = new StateResult(); var lastResult = PrepareTransitions(someResult, n); Transitions.ConfigureTransition(lastResult, new TestSyncState(Observable.Never <ITransition>)); var observable = stateMachineFinised(); StateMachine.Start(someResult.Transition()); ((TestScheduler)Scheduler).AdvanceBy(TimeSpan.FromSeconds(62).Ticks); observable.Wait(); Action secondStart = () => StateMachine.Start(someResult.Transition()); secondStart.Should().NotThrow <InvalidOperationException>(); }
public void ReturnsHandlerThatCallsProvidedGenericStateFactory() { var stateResult = new StateResult <object>(); var expectedResult = Substitute.For <IObservable <ITransition> >(); provider.ConfigureTransition(stateResult, _ => expectedResult); var handler = provider.GetTransitionHandler(stateResult); var actualResult = handler(stateResult.Transition(null)); actualResult.Should().Be(expectedResult); }
public void ReturnsHandlerThatCallsProvidedGenericStateFactoryWithCorrectArgument() { var stateResult = new StateResult <object>(); var expectedArgument = new object(); object actualArgument = null; provider.ConfigureTransition(stateResult, obj => { actualArgument = obj; return(null); }); var handler = provider.GetTransitionHandler(stateResult); handler(stateResult.Transition(expectedArgument)); actualArgument.Should().Be(expectedArgument); }
public static IObservable <ITransition> OnErrorReturnResult <T>(this IObservable <ITransition> observable, StateResult <T> errorResult) where T : Exception => observable.Catch((T exception) => Observable.Return(errorResult.Transition(exception)));