Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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()));
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 public void CurrentValue_WhenInitialized_ShouldBeDefault(
     [Frozen] ThrowingTestScheduler scheduler,
     ObservableViewModel <object> sut)
 {
     //assert
     sut.CurrentValue.Should().BeNull();
 }
Esempio n. 5
0
		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);
		}
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
		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);
		}
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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();
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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();
        }
Esempio n. 13
0
        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);
		}
Esempio n. 15
0
        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();
        }
Esempio n. 16
0
        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);
        }
Esempio n. 17
0
		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);
		}
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
		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()));
		}