public void RefreshAsync_WithTimeout_ShouldThrow( [Frozen] ThrowingTestScheduler scheduler, ObservableViewModel <object> sut) { //arrange var observer = scheduler.CreateObserver <ObservableViewModelNotification>(); sut.Subscribe(observer); scheduler.Schedule(TimeSpan.FromTicks(201), () => sut.Refresh()); //act scheduler.Start(); //await sut.RefreshAsync(); //assert var actual = observer.Values().ToArray(); var expected = new[] { new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Initialized, Value = null }, new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Updating, Value = null }, new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Timeout, Value = null } }; actual.ShouldAllBeEquivalentTo(expected); }
public async Task Refresh_SourceIsEmpty_ShouldReturnCorrectValue( [Frozen] ThrowingTestScheduler scheduler, [Frozen] IViewModel parent, ObservableViewModel <object> sut) { //arrange var observer = scheduler.CreateObserver <ObservableViewModelNotification>(); sut.Subscribe(observer); //act await sut.RefreshAsync(); //assert var actual = observer.Values().ToArray(); var expected = new[] { new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Initialized, Value = null }, new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Updating, Value = null }, new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Empty, Value = null } }; actual.ShouldAllBeEquivalentTo(expected); }
public void Execute_WithObservableYielding3Values_ShouldReturnCorrectResult( object value1, object value2, object value3, TestSchedulers schedulers, ThrowingTestScheduler scheduler) { //arrange var observable = scheduler.CreateColdObservable(OnNext(10, value1), OnNext(20, value2), OnNext(30, value3), OnCompleted(40, new object())); var observer = scheduler.CreateObserver <object>(); var sut = new ObservableMvvmCommand <object, object>(o => observable, schedulers, schedulers, "name", new AlwaysTrueCanExecuteStrategy <object>(), doObserver: () => observer, doScheduler: ImmediateScheduler.Instance); //act sut.Execute(null); //allow any work scheduled with the schedulers to advance schedulers.AdvanceBy(200); //allow notifications to advance scheduler.AdvanceBy(200); //assert observer.Messages.AssertEqual(OnNext(10, value1), OnNext(20, value2), OnNext(30, value3), OnCompleted(40, new object())); }
public void Dispose_ShouldYieldCompleted( [Frozen] ThrowingTestScheduler scheduler, ObservableViewModel <object> sut) { //arrange var observer = scheduler.CreateObserver <ObservableViewModelNotification>(); sut.Subscribe(observer); //act sut.Dispose(); //assert observer.Completed().Should().HaveCount(1); }
public async Task CurrentValue_SourceYieldError_ShouldReturnCorrectValue( [Frozen] ThrowingTestScheduler scheduler, [Frozen] Exception error, [Frozen] IViewModel parent, ObservableViewModel <object> sut) { //arrange var observer = scheduler.CreateObserver <ObservableViewModelNotification>(); sut.Subscribe(observer); //act await sut.RefreshAsync(); //assert var actual = sut.CurrentValue; actual.Should().BeNull(); }
public async Task ObserveValue_WhenCallSet_ShouldReturnValue( [Frozen] ThrowingTestScheduler scheduler, [Frozen] Mock <IAsyncStorage> table, Services.SettingsService sut, string key, object expected) { //arrange table.Setup(t => t.Contains <string, object>(key, It.IsAny <CancellationToken>())).ReturnsTask(false); table.Setup(t => t.AddOrUpdate(key, It.IsAny <object>(), It.IsAny <CancellationToken>())).ReturnsDefaultTask(); //act var observer = scheduler.CreateObserver <object>(); sut.ObserveValue(key, () => default(object)).Skip(1).Subscribe(observer); await sut.SetValue(key, expected, CancellationToken.None); //assert observer.Values().Last().Should().Be(expected); }
public void RefreshOn_ShouldRefresh( [Frozen] ThrowingTestScheduler scheduler, [Frozen] Subject <Unit> refreshOn, [Frozen] object value, ObservableViewModel <object> sut) { //arrange var observer = scheduler.CreateObserver <ObservableViewModelNotification>(); sut.Subscribe(observer); //act scheduler.Schedule(TimeSpan.FromTicks(201), () => refreshOn.OnNext(Unit.Default)); scheduler.Start(); //assert var expected = new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Value, Value = value }; observer.Values().Last().ShouldBeEquivalentTo(expected); }
public void Execute_WithObservableYielding3Values_ShouldReturnCorrectResult( object value1, object value2, object value3, TestSchedulers schedulers, ThrowingTestScheduler scheduler) { //arrange var observable = scheduler.CreateColdObservable(OnNext(10, value1), OnNext(20, value2), OnNext(30, value3), OnCompleted(40, new object())); var observer = scheduler.CreateObserver<object>(); var sut = new ObservableMvvmCommand<object, object>(o => observable, schedulers, schedulers, "name", new AlwaysTrueCanExecuteStrategy<object>(), doObserver: () => observer, doScheduler: ImmediateScheduler.Instance); //act sut.Execute(null); //allow any work scheduled with the schedulers to advance schedulers.AdvanceBy(200); //allow notifications to advance scheduler.AdvanceBy(200); //assert observer.Messages.AssertEqual(OnNext(10, value1), OnNext(20, value2), OnNext(30, value3), OnCompleted(40, new object())); }