public async Task IsContentReady_should_be_true_after_LoadAsync_returns() { var vm = new TestEditorViewModel(s_bonusBar); var dispatcher = new UnitTestThreadDispatcher(); await vm.LoadAsync(new FakeRegistryService()); vm.IsContentReady.Should().BeTrue(); }
public async Task LoadAsync_should_start_a_timer_for_the_progress_bar_then_run_the_action() { var dispatcher = new UnitTestThreadDispatcher(); var vm = new TestEditorViewModel(s_bonusBar, dispatcher); await vm.LoadAsync(new FakeRegistryService()); dispatcher.Runs.Should().ContainInOrder(DispatchRunKind.UIThreadDelayed, DispatchRunKind.BackgroundThread); }
public async Task IsIndeterminateProgressBarVisible_should_be_false_after_the_load_returns() { var vm = new TestEditorViewModel(s_bonusBar); var dispatcher = new UnitTestThreadDispatcher(); await vm.LoadAsync(new FakeRegistryService()); vm.IsIndeterminateProgressBarVisible.Should().BeFalse(); }
IsIndeterminateProgressBarVisible_should_be_true_after_a_delay_and_the_content_is_not_yet_ready() { var cancellationSource = new CancellationTokenSource(); CancellationToken cancellationToken = cancellationSource.Token; var dispatcher = new UnitTestThreadDispatcher(backgroundAsyncThreadInvoker: action => Task.Delay(-1, cancellationToken)); var vm = new TestEditorViewModel(s_bonusBar, dispatcher); Task task = vm.LoadAsync(new FakeRegistryService(), 0, cancellationToken); vm.IsIndeterminateProgressBarVisible.Should().BeTrue(); cancellationSource.Cancel(); Func <Task> func = async() => await task; await func.Should().ThrowExactlyAsync <TaskCanceledException>(); }
public async Task LoadAsync_should_pass_in_the_delay_to_the_delayInvoker() { const int delay = 1; var cancellationToken = new CancellationToken(); var dispatcher = new UnitTestThreadDispatcher( delayInvoker: (ms, token) => { ms.Should().Be(delay); token.Should() .NotBe(cancellationToken, "because the progress bar cancellation should be different"); return(Task.CompletedTask); }); var vm = new TestEditorViewModel(s_bonusBar, dispatcher); await vm.LoadAsync(new FakeRegistryService(), delay, cancellationToken); }