public void execute_pauses_if_context_is_paused() { var delayService = new DelayServiceMock(); var delayCallCount = 0; using (var context = new ExecutionContext()) { delayService .When(x => x.Delay(It.IsAny <TimeSpan>())) .Do(() => context.IsPaused = delayCallCount++ == 2) .Return(Observable.Return(Unit.Default)); var sut = new WaitActionBuilder() .WithDelayService(delayService) .WithDelay(TimeSpan.FromSeconds(50)) .Build(); sut .Execute(context) .Subscribe(); Assert.True(context.IsPaused); delayService .Verify(x => x.Delay(It.IsAny <TimeSpan>())) .WasCalledExactly(times: 3); } }
public void execute_async_bails_out_if_context_is_cancelled() { var delayService = new DelayServiceMock(); var delayCallCount = 0; using (var context = new ExecutionContext()) { delayService .When(x => x.DelayAsync(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>())) .Do( () => { if (delayCallCount++ == 2) { context.Cancel(); } }) .Return(Observable.Return(Unit.Default)); var sut = new WaitActionBuilder() .WithDelayService(delayService) .WithDelay(TimeSpan.FromSeconds(50)) .Build(); sut.ExecuteAsync(context); Assert.True(context.IsCancelled); delayService .Verify(x => x.DelayAsync(It.IsAny <TimeSpan>(), It.IsAny <CancellationToken>())) .WasCalledExactly(times: 3); } }