public void is_pause_visible_cycles_correctly_if_start_command_is_executed() { var scheduler = new TestSchedulerService(); var action = new ActionMock(MockBehavior.Loose); action .When(x => x.Duration) .Return(TimeSpan.FromMinutes(1)); action .When(x => x.ExecuteAsync(It.IsAny <ExecutionContext>())) .Return <ExecutionContext>( ec => Observable .Return(Unit.Default) .Do(_ => { }) .Delay(TimeSpan.FromMinutes(1), scheduler.DefaultScheduler) .Do(_ => ec.AddProgress(TimeSpan.FromMinutes(1)))); var sut = new ExerciseProgramViewModelBuilder() .WithModel( new ExerciseProgramBuilder() .AddExercise( new ExerciseBuilder() .WithBeforeExerciseAction(action))) .WithSchedulerService(scheduler) .Build(); Assert.False(sut.IsPauseVisible); sut.StartCommand.Execute(null); scheduler.AdvanceMinimal(); Assert.True(sut.IsPauseVisible); scheduler.AdvanceBy(TimeSpan.FromMinutes(10)); Assert.False(sut.IsPauseVisible); }
public void delay_async_cancels_the_delay_if_cancellation_token_is_cancelled() { var scheduler = new TestSchedulerService(); var sut = new DelayServiceBuilder() .WithSchedulerService(scheduler) .Build(); var cts = new CancellationTokenSource(); Exception exception = null; var delayResult = sut .DelayAsync(TimeSpan.FromSeconds(5), cts.Token) .Subscribe( _ => { }, ex => exception = ex); scheduler.AdvanceBy(TimeSpan.FromSeconds(1)); Assert.Null(exception); cts.Cancel(); scheduler.AdvanceBy(TimeSpan.FromSeconds(5)); Assert.IsType <OperationCanceledException>(exception); }
public void delay_async_returns_observable_that_ticks_after_specified_delay() { var scheduler = new TestSchedulerService(); var sut = new DelayServiceBuilder() .WithSchedulerService(scheduler) .Build(); var completed = false; sut .DelayAsync(TimeSpan.FromSeconds(5)) .Subscribe(_ => completed = true); Assert.False(completed); scheduler.AdvanceBy(TimeSpan.FromSeconds(1)); Assert.False(completed); scheduler.AdvanceBy(TimeSpan.FromSeconds(2)); Assert.False(completed); scheduler.AdvanceBy(TimeSpan.FromSeconds(3)); Assert.True(completed); }
public void programs_is_populated_from_cache_whilst_document_from_cloud_loads() { var cacheDocument = "# First Program"; var cloudDocument = @" # First Program # Second Program"; var scheduler = new TestSchedulerService(); var exerciseDocumentService = new ExerciseDocumentServiceMock(MockBehavior.Loose); exerciseDocumentService .When(x => x.ExerciseDocument) .Return( Observable .Return(cloudDocument) .Delay(TimeSpan.FromSeconds(3), scheduler.TaskPoolScheduler)); var sut = new ExerciseProgramsViewModelBuilder() .WithExerciseDocumentService(exerciseDocumentService) .WithCachedDocument(cacheDocument) .WithSchedulerService(scheduler) .Build(); scheduler.AdvanceMinimal(); Assert.NotNull(sut.Programs); Assert.Equal(1, sut.Programs.Count); scheduler.AdvanceBy(TimeSpan.FromSeconds(2)); Assert.NotNull(sut.Programs); Assert.Equal(1, sut.Programs.Count); scheduler.AdvanceBy(TimeSpan.FromSeconds(2)); Assert.NotNull(sut.Programs); Assert.Equal(2, sut.Programs.Count); }
public void ShowGenericError_WithMessageAndNoException_CallsShowErrorInteractionWithDesiredMessage() { string expected = "Any error message"; string actual = null; _target .ShowError .RegisterHandler( ctx => { actual = ctx.Input; ctx.SetOutput(Unit.Default); }); _target .ShowGenericError(expected, null) .Subscribe(); _schedulerServiceMock.AdvanceBy(TimeSpan.FromSeconds(1)); Assert.AreSame(expected, actual); Assert.AreEqual(expected, actual); }