public void InvokeCommandAgainstICommandInTargetPassesTheSpecifiedValueToCanExecuteAndExecute() { ICommandHolder fixture = new ICommandHolder(); Subject <int> source = new Subject <int>(); source.InvokeCommand(fixture, x => x.TheCommand); FakeCommand command = new FakeCommand(); fixture.TheCommand = command; source.OnNext(42); Assert.Equal(42, command.CanExecuteParameter); Assert.Equal(42, command.ExecuteParameter); }
public void InvokeCommandAgainstICommandInTargetInvokesTheCommand() { int executionCount = 0; ICommandHolder fixture = new ICommandHolder(); Subject <Unit> source = new Subject <Unit>(); source.InvokeCommand(fixture, x => x.TheCommand); fixture.TheCommand = ReactiveCommand.Create(() => ++ executionCount, outputScheduler: ImmediateScheduler.Instance); source.OnNext(Unit.Default); Assert.Equal(1, executionCount); source.OnNext(Unit.Default); Assert.Equal(2, executionCount); }
public void InvokeCommandAgainstICommandInTargetInvokesTheCommand() { var executionCount = 0; var fixture = new ICommandHolder(); var source = new Subject <Unit>(); source.InvokeCommand(fixture, x => x.TheCommand); fixture.TheCommand = ReactiveCommand.Create(() => ++ executionCount); source.OnNext(Unit.Default); Assert.Equal(1, executionCount); source.OnNext(Unit.Default); Assert.Equal(2, executionCount); }
public void InvokeCommandAgainstICommandInTargetRespectsCanExecute() { bool executed = false; BehaviorSubject <bool> canExecute = new BehaviorSubject <bool>(false); ICommandHolder fixture = new ICommandHolder(); Subject <Unit> source = new Subject <Unit>(); source.InvokeCommand(fixture, x => x.TheCommand); fixture.TheCommand = ReactiveCommand.Create(() => executed = true, canExecute, ImmediateScheduler.Instance); source.OnNext(Unit.Default); Assert.False(executed); canExecute.OnNext(true); source.OnNext(Unit.Default); Assert.True(executed); }
public void InvokeCommandAgainstICommandInTargetRespectsCanExecuteWindow() { bool executed = false; BehaviorSubject <bool> canExecute = new BehaviorSubject <bool>(false); ICommandHolder fixture = new ICommandHolder(); Subject <Unit> source = new Subject <Unit>(); source.InvokeCommand(fixture, x => x.TheCommand); fixture.TheCommand = ReactiveCommand.Create(() => executed = true, canExecute, ImmediateScheduler.Instance); source.OnNext(Unit.Default); 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); }
public void InvokeCommandAgainstICommandInTargetSwallowsExceptions() { var count = 0; var fixture = new ICommandHolder(); var command = ReactiveCommand.Create( () => { ++count; throw new InvalidOperationException(); }); command.ThrownExceptions.Subscribe(); fixture.TheCommand = command; var source = new Subject <Unit>(); source.InvokeCommand(fixture, x => x.TheCommand); source.OnNext(Unit.Default); source.OnNext(Unit.Default); Assert.Equal(2, count); }
public void InvokeCommandAgainstICommandInTargetSwallowsExceptions() { int count = 0; ICommandHolder fixture = new ICommandHolder(); ReactiveCommand <Unit, Unit> command = ReactiveCommand.Create( () => { ++count; throw new InvalidOperationException(); }, outputScheduler: ImmediateScheduler.Instance); command.ThrownExceptions.Subscribe(); fixture.TheCommand = command; Subject <Unit> source = new Subject <Unit>(); source.InvokeCommand(fixture, x => x.TheCommand); source.OnNext(Unit.Default); source.OnNext(Unit.Default); Assert.Equal(2, count); }