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 void RefreshOn_WithOverlappingRefresh_ShouldReturnCorrectValue( [Frozen] TestSchedulers scheduler, [Frozen] Subject <Unit> refreshOn, object value) { //arrange var observer = scheduler.CreateObserver <ObservableViewModelNotification>(); var i = 0; var sut = new ObservableViewModel <object>(c => { if (++i == 1) { refreshOn.OnNext(Unit.Default); } return(Task.FromResult(value)); }, _ => false, refreshOn, TimeSpan.Zero, new CompositeDisposable(), scheduler); sut.Subscribe(observer); //act refreshOn.OnNext(Unit.Default); scheduler.Start(); //assert var expected = new ObservableViewModelNotification() { Status = ObservableViewModelStatus.Value, Value = value }; observer.Values().Last().ShouldBeEquivalentTo(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 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 ChainEmptyPredicate_WhenPredicateReturnsFalse_OvmStateShouldBeValue( [Frozen] TestSchedulers schedulers, ObservableViewModel <object> sut) { //arrange Func <object, bool> predicate = o => false; var observer = schedulers.CreateObserver <ObservableViewModelNotification>(); sut.ChainEmptyPredicate(predicate); sut.Subscribe(observer); //act await sut.RefreshAsync(); //assert observer.Values().Last().Should().Match <ObservableViewModelNotification>(n => n.Status == ObservableViewModelStatus.Value); }
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 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); }