Exemplo 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);
        }
Exemplo n.º 2
0
        public async Task CurrentValue_SourceYieldErrorThenValue_ShouldReturnCorrectValue(
            [Frozen] ThrowingTestScheduler scheduler,
            [Frozen] Exception error,
            [Frozen] IViewModel parent,
            [Frozen] object expected,
            ObservableViewModel <object> sut)
        {
            //arrange
            var observer = scheduler.CreateObserver <ObservableViewModelNotification>();

            sut.Subscribe(observer);

            //act
            //first refresh yield an error
            await sut.RefreshAsync();

            //second refresh yield a value
            await sut.RefreshAsync();

            //assert
            var actual = sut.CurrentValue;

            actual.Should().Be(expected);
        }
Exemplo n.º 3
0
        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);
        }