コード例 #1
0
        public void InvokeCommandAgainstReactiveCommandInTargetPassesTheSpecifiedValueToExecute()
        {
            int executeReceived           = 0;
            ReactiveCommandHolder fixture = new ReactiveCommandHolder();
            Subject <int>         source  = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);
            fixture.TheCommand = ReactiveCommand.Create <int>(x => executeReceived = x, outputScheduler: ImmediateScheduler.Instance);

            source.OnNext(42);
            Assert.Equal(42, executeReceived);
        }
コード例 #2
0
        public void InvokeCommandAgainstReactiveCommandInTargetPassesTheSpecifiedValueToExecute()
        {
            var executeReceived = 0;
            var fixture         = new ReactiveCommandHolder();
            var source          = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);
            fixture.TheCommand = ReactiveCommand.Create <int>(x => executeReceived = x);

            source.OnNext(42);
            Assert.Equal(42, executeReceived);
        }
コード例 #3
0
        public void InvokeCommandAgainstReactiveCommandInTargetInvokesTheCommand()
        {
            int executionCount            = 0;
            ReactiveCommandHolder fixture = new ReactiveCommandHolder();
            Subject <int>         source  = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);
            fixture.TheCommand = ReactiveCommand.Create <int>(_ => { ++executionCount; }, outputScheduler: ImmediateScheduler.Instance);

            source.OnNext(0);
            Assert.Equal(1, executionCount);

            source.OnNext(0);
            Assert.Equal(2, executionCount);
        }
コード例 #4
0
        public void InvokeCommandAgainstReactiveCommandInTargetInvokesTheCommand()
        {
            var executionCount = 0;
            var fixture        = new ReactiveCommandHolder();
            var source         = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);
            fixture.TheCommand = ReactiveCommand.Create <int>(_ => { ++executionCount; });

            source.OnNext(0);
            Assert.Equal(1, executionCount);

            source.OnNext(0);
            Assert.Equal(2, executionCount);
        }
コード例 #5
0
        public void InvokeCommandAgainstReactiveCommandInTargetRespectsCanExecute()
        {
            bool executed = false;
            BehaviorSubject <bool> canExecute = new BehaviorSubject <bool>(false);
            ReactiveCommandHolder  fixture    = new ReactiveCommandHolder();
            Subject <int>          source     = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);
            fixture.TheCommand = ReactiveCommand.Create <int>(_ => executed = true, canExecute, ImmediateScheduler.Instance);

            source.OnNext(0);
            Assert.False(executed);

            canExecute.OnNext(true);
            source.OnNext(0);
            Assert.True(executed);
        }
コード例 #6
0
        public void InvokeCommandAgainstReactiveCommandInTargetRespectsCanExecute()
        {
            var executed   = false;
            var canExecute = new BehaviorSubject <bool>(false);
            var fixture    = new ReactiveCommandHolder();
            var source     = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);
            fixture.TheCommand = ReactiveCommand.Create <int>(_ => executed = true, canExecute);

            source.OnNext(0);
            Assert.False(executed);

            canExecute.OnNext(true);
            source.OnNext(0);
            Assert.True(executed);
        }
コード例 #7
0
        public void InvokeCommandAgainstReactiveCommandInTargetRespectsCanExecuteWindow()
        {
            bool executed = false;
            BehaviorSubject <bool> canExecute = new BehaviorSubject <bool>(false);
            ReactiveCommandHolder  fixture    = new ReactiveCommandHolder();
            Subject <int>          source     = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);
            fixture.TheCommand = ReactiveCommand.Create <int>(_ => executed = true, canExecute, ImmediateScheduler.Instance);

            source.OnNext(0);
            Assert.False(executed);

            // The execution window re-opens, but the above execution request should not be instigated because
            // it occurred when the window was closed. Execution requests do not queue up when the window is closed.
            canExecute.OnNext(true);
            Assert.False(executed);
        }
コード例 #8
0
        public void InvokeCommandAgainstReactiveCommandInTargetSwallowsExceptions()
        {
            var count   = 0;
            var fixture = new ReactiveCommandHolder();

            fixture.TheCommand = ReactiveCommand.Create <int>(
                _ => {
                ++count;
                throw new InvalidOperationException();
            });
            fixture.TheCommand.ThrownExceptions.Subscribe();
            var source = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);

            source.OnNext(0);
            source.OnNext(0);

            Assert.Equal(2, count);
        }
コード例 #9
0
        public void InvokeCommandAgainstReactiveCommandInTargetSwallowsExceptions()
        {
            int count = 0;
            ReactiveCommandHolder fixture = new ReactiveCommandHolder
            {
                TheCommand = ReactiveCommand.Create <int>(
                    _ =>
                {
                    ++count;
                    throw new InvalidOperationException();
                },
                    outputScheduler: ImmediateScheduler.Instance)
            };

            fixture.TheCommand.ThrownExceptions.Subscribe();
            Subject <int> source = new Subject <int>();

            source.InvokeCommand(fixture, x => x.TheCommand);

            source.OnNext(0);
            source.OnNext(0);

            Assert.Equal(2, count);
        }