Example #1
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()));
        }
Example #2
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);
        }
Example #3
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);
		}
		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()));
		}