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 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 CurrentValue_WhenInitialized_ShouldBeDefault( [Frozen] ThrowingTestScheduler scheduler, ObservableViewModel <object> sut) { //assert sut.CurrentValue.Should().BeNull(); }
public void Convert_ObservableShouldReturnValue(ThrowingTestScheduler scheduler) { string expected = "Test"; IObservable<string> observableSource = Observable.Return(expected); object observableObject = observableSource; IObservable<object> result = observableObject.Convert<object>(); var actual = scheduler.Start(() => result).Values().First(); actual.Should().Be(expected); }
public void Convert_ObservableShouldReturnValue(ThrowingTestScheduler scheduler) { string expected = "Test"; IObservable <string> observableSource = Observable.Return(expected); object observableObject = observableSource; IObservable <object> result = observableObject.Convert <object>(); var actual = scheduler.Start(() => result).Values().First(); actual.Should().Be(expected); }
public void AsObservableCollectionWithNotifications_ShouldReturnObservableCollection( IEnumerable <object> sut, IObservable <object> notifications, ThrowingTestScheduler scheduler) { //arrange ObservableCollection <object> observableCollection; //act sut.AsObservableCollectionWithNotifications(notifications, (o, objects) => () => { }, scheduler, scheduler, out observableCollection); //assert observableCollection.ShouldAllBeEquivalentTo(sut); }
public void AsObservableCollectionWithNotifications_ShouldReturnObservableCollection( IEnumerable<object> sut, IObservable<object> notifications, ThrowingTestScheduler scheduler) { //arrange ObservableCollection<object> observableCollection; //act sut.AsObservableCollectionWithNotifications(notifications, (o, objects) => () => { }, scheduler, scheduler, out observableCollection); //assert observableCollection.ShouldAllBeEquivalentTo(sut); }
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 void ObserveCommandEvents_WithoutCommandAndWhenNotifyingOtherType_ShouldReturnCorrectValue( [Frozen] ThrowingTestScheduler scheduler, CommandEvents sut, TestCommandWithMultipleEvents command, string value) { //arrange scheduler.Schedule(TimeSpan.FromTicks(202), () => sut.NotifyEvent(command, value)); //act var result = scheduler.Start(() => sut.ObserveCommandEvents <TestCommandWithMultipleEvents, int>()); //assert result.AssertExceptions(); result.Values().Should().BeEmpty(); }
public void ObserveCommandEvents_ShouldReturnCorrectValue( [Frozen] ThrowingTestScheduler scheduler, CommandEvents sut, TestCommand command, string value) { //arrange scheduler.Schedule(TimeSpan.FromTicks(202), () => sut.NotifyEvent(command, value)); //act var result = scheduler.Start(() => sut.ObserveCommandEvents <TestCommand, string>()); //assert result.AssertExceptions(); result.Values().First().Should().Be(value); }
public async Task SetValue_ShouldCallAddOrUpdate( [Frozen] ThrowingTestScheduler scheduler, [Frozen] Mock <IAsyncStorage> table, Services.SettingsService sut, string key, object expected) { //arrange var verifiable = table.Setup(t => t.AddOrUpdate(key, expected, It.IsAny <CancellationToken>())).ReturnsDefaultTaskVerifiable(); //act await sut.SetValue(key, expected, CancellationToken.None); //assert verifiable.Verify(); }
public void RefreshOn_SetRefreshOn( ThrowingTestScheduler scheduler, object refreshValue, ObservableViewModelBuilderOptions <object> sut) { //arrange var refreshOn = new Subject <object>(); scheduler.Schedule(TimeSpan.FromTicks(201), () => refreshOn.OnNext(refreshValue)); //act var actual = sut.RefreshOn(refreshOn) .ToViewModel(); var result = scheduler.Start(() => actual.As <ObservableViewModel <object> >().RefreshOn); //assert result.Values().Should().HaveCount(1); }
public void RefreshOn_SetRefreshOn( ThrowingTestScheduler scheduler, object refreshValue, ObservableViewModelBuilderOptions<object> sut) { //arrange var refreshOn = new Subject<object>(); scheduler.Schedule(TimeSpan.FromTicks(201), () => refreshOn.OnNext(refreshValue)); //act var actual = sut.RefreshOn(refreshOn) .ToViewModel(); var result = scheduler.Start(() => actual.As<ObservableViewModel<object>>().RefreshOn); //assert result.Values().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 AsObservableCollectionWithNotifications_ShouldExecuteActionsOnNotifications( IEnumerable<object> sut, object[] itemsToAdd, ThrowingTestScheduler scheduler) { //arrange var notifications = scheduler.CreateColdObservable( itemsToAdd.Select((item, i) => OnNext(Subscribed + i + 1, item)) .ToArray()); ObservableCollection<object> observableCollection = null; //act scheduler.Start(() => sut.AsObservableCollectionWithNotifications( notifications, (o, objects) => () => objects.Add(o), scheduler, scheduler, out observableCollection)); var expected = sut.Concat(itemsToAdd); //assert observableCollection.ShouldAllBeEquivalentTo(expected); }
public void AsObservableCollectionWithNotifications_ShouldExecuteActionsOnNotifications( IEnumerable <object> sut, object[] itemsToAdd, ThrowingTestScheduler scheduler) { //arrange var notifications = scheduler.CreateColdObservable( itemsToAdd.Select((item, i) => OnNext(Subscribed + i + 1, item)) .ToArray()); ObservableCollection <object> observableCollection = null; //act scheduler.Start(() => sut.AsObservableCollectionWithNotifications( notifications, (o, objects) => () => objects.Add(o), scheduler, scheduler, out observableCollection)); var expected = sut.Concat(itemsToAdd); //assert observableCollection.ShouldAllBeEquivalentTo(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())); }