예제 #1
0
        public void CanExecute_ShouldReturnCorrectValue(
            IReactiveValue<object> value,
            bool canExecute,
            object arg)
        {
            //arrange
            var sut = new ReactiveMvvmCommand<object, object>(o => value, canExecutePredicate: o => canExecute);
            //act
            var actual = sut.CanExecute(arg);

            //assert
            actual.Should().Be(canExecute);
        }
예제 #2
0
        public void CanExecute_ShouldReturnCorrectValue(
            IReactiveValue <object> value,
            bool canExecute,
            object arg)
        {
            //arrange
            var sut = new ReactiveMvvmCommand <object, object>(o => value, canExecutePredicate: o => canExecute);
            //act
            var actual = sut.CanExecute(arg);

            //assert
            actual.Should().Be(canExecute);
        }
예제 #3
0
        public void Execute_ShouldCallOnError(
            Exception expected)
        {
            //arrange
            Exception actual = null;
            var       value  = Observable.Throw <object>(expected, ImmediateScheduler.Instance).AsReactiveValue();
            var       sut    = new ReactiveMvvmCommand <object, object>(o => value, onError: o => actual = o, onErrorScheduler: ImmediateScheduler.Instance);

            //act
            sut.Execute(null);

            //assert
            actual.Should().Be(expected);
        }
예제 #4
0
        public void Execute_ShouldCallCallback(
            object expected)
        {
            //arrange
            object actual = null;
            var    value  = ReactiveValue.Return(expected, ImmediateScheduler.Instance);
            var    sut    = new ReactiveMvvmCommand <object, object>(o => value, o => actual = o, ImmediateScheduler.Instance);

            //act
            sut.Execute(null);

            //assert
            actual.Should().Be(expected);
        }
예제 #5
0
        public void Sut_TestDefaultValues(
            Func<object, IReactiveValue<object>> factory)
        {
            //arrange
            var sut = new ReactiveMvvmCommand<object, object>(factory);

            //act

            //assert
            sut.Callback.Should().NotBeNull();
            sut.OnError.Should().NotBeNull();
            sut.CallbackScheduler.Should().NotBeNull();
            sut.OnErrorScheduler.Should().NotBeNull();
            sut.CanExecutePredicate(null).Should().BeTrue();
        }
예제 #6
0
        public void Execute_ShouldExecuteObservable()
        {
            //arrange
            bool observableCalled = false;
            var  value            = ReactiveValue.Return(System.Reactive.Unit.Default, ImmediateScheduler.Instance)
                                    .Do(unit => observableCalled = true)
                                    .AsReactiveValue();
            var sut = new ReactiveMvvmCommand <object, System.Reactive.Unit>(o => value);

            //act
            sut.Execute(null);

            //assert
            observableCalled.Should().BeTrue();
        }
예제 #7
0
        public void Sut_TestDefaultValues(
            Func <object, IReactiveValue <object> > factory)
        {
            //arrange
            var sut = new ReactiveMvvmCommand <object, object>(factory);

            //act

            //assert
            sut.Callback.Should().NotBeNull();
            sut.OnError.Should().NotBeNull();
            sut.CallbackScheduler.Should().NotBeNull();
            sut.OnErrorScheduler.Should().NotBeNull();
            sut.CanExecutePredicate(null).Should().BeTrue();
        }
예제 #8
0
        public void CanExecute_AfterExecutingCommand_ShouldBePreviousState(
            object obj)
        {
            //arrange
            var value = ReactiveValue.Return(obj, ImmediateScheduler.Instance);
            var sut   = new ReactiveMvvmCommand <object, object>(_ => value, canExecutePredicate: o => false);

            sut.Execute(null);

            //act
            var actual = sut.CanExecute(null);

            //assert
            actual.Should().BeFalse();
        }
예제 #9
0
        public void Execute_ShouldRaiseCanExecuteChangedTwice(
            object obj)
        {
            //arrange
            var value = ReactiveValue.Return(obj, ImmediateScheduler.Instance);
            var sut   = new ReactiveMvvmCommand <object, object>(_ => value);

            sut.MonitorEvents();


            //act
            sut.Execute(null);

            //assert
            sut.ShouldRaise("CanExecuteChanged").Should().HaveCount(2);
        }
예제 #10
0
        public void CanExecute_WhenExecutingCommand_ShouldBeFalse(
            object obj)
        {
            //arrange
            var canExecuteValues = new List <bool>();
            var value            = ReactiveValue.Return(obj, ImmediateScheduler.Instance);
            var sut = new ReactiveMvvmCommand <object, object>(_ => value);

            sut.CanExecuteChanged += (sender, args) => canExecuteValues.Add(sut.CanExecute(null));

            //act
            sut.Execute(null);

            //assert
            canExecuteValues.First().Should().BeFalse();
        }
예제 #11
0
        public void Execute_ShouldBeCalledWithArg(
            IReactiveValue <object> value,
            object arg)
        {
            //arrange
            object actual = null;
            var    sut    = new ReactiveMvvmCommand <object, object>(o =>
            {
                actual = o;
                return(value);
            });

            //act
            sut.Execute(arg);

            //assert
            actual.Should().Be(arg);
        }
예제 #12
0
        public void Execute_ShouldBeCalledWithArg(
            IReactiveValue<object> value,
            object arg)
        {
            //arrange
            object actual = null;
            var sut = new ReactiveMvvmCommand<object, object>(o =>
            {
                actual = o;
                return value;
            });

            //act
            sut.Execute(arg);

            //assert
            actual.Should().Be(arg);
        }
예제 #13
0
        public void Execute_ShouldCallCallback(
            object expected)
        {
            //arrange
            object actual = null;
            var value = ReactiveValue.Return(expected, ImmediateScheduler.Instance);
            var sut = new ReactiveMvvmCommand<object, object>(o => value, o => actual = o, ImmediateScheduler.Instance);

            //act
            sut.Execute(null);

            //assert
            actual.Should().Be(expected);
        }
예제 #14
0
        public void Execute_ShouldRaiseCanExecuteChangedTwice(
            object obj)
        {
            //arrange
            var value = ReactiveValue.Return(obj, ImmediateScheduler.Instance);
            var sut = new ReactiveMvvmCommand<object, object>(_ => value);
            sut.MonitorEvents();


            //act
            sut.Execute(null);

            //assert
            sut.ShouldRaise("CanExecuteChanged").Should().HaveCount(2);
        }
예제 #15
0
        public void CanExecute_WhenExecutingCommand_ShouldBeFalse(
            object obj)
        {
            //arrange
            var canExecuteValues = new List<bool>();
            var value = ReactiveValue.Return(obj, ImmediateScheduler.Instance);
            var sut = new ReactiveMvvmCommand<object, object>(_ => value);
            sut.CanExecuteChanged += (sender, args) => canExecuteValues.Add(sut.CanExecute(null));

            //act
            sut.Execute(null);

            //assert
            canExecuteValues.First().Should().BeFalse();
        }
예제 #16
0
        public void Execute_ShouldCallOnError(
            Exception expected)
        {
            //arrange
            Exception actual = null;
            var value = Observable.Throw<object>(expected, ImmediateScheduler.Instance).AsReactiveValue();
            var sut = new ReactiveMvvmCommand<object, object>(o => value, onError: o => actual = o, onErrorScheduler: ImmediateScheduler.Instance);

            //act
            sut.Execute(null);

            //assert
            actual.Should().Be(expected);
        }
예제 #17
0
        public void Execute_ShouldExecuteObservable()
        {
            //arrange
            bool observableCalled = false;
            var value = ReactiveValue.Return(System.Reactive.Unit.Default, ImmediateScheduler.Instance)
                .Do(unit => observableCalled = true)
                .AsReactiveValue();
            var sut = new ReactiveMvvmCommand<object, System.Reactive.Unit>(o => value);

            //act
            sut.Execute(null);

            //assert
            observableCalled.Should().BeTrue();
        }
예제 #18
0
        public void CanExecute_AfterExecutingCommand_ShouldBePreviousState(
            object obj)
        {
            //arrange
            var value = ReactiveValue.Return(obj, ImmediateScheduler.Instance);
            var sut = new ReactiveMvvmCommand<object, object>(_ => value, canExecutePredicate: o => false);
            sut.Execute(null);

            //act
            var actual = sut.CanExecute(null);

            //assert
            actual.Should().BeFalse();
        }