public CommandsViewModel() { ManualRelayCommandNoCondition = new ManualRelayCommand(() => Executed = "ManualRelayCommandNoCondition"); ManualRelayCommand = new ManualRelayCommand(() => Executed = "ManualRelayCommand", () => CanExecute); ManualRelayCommandWithParameter = new ManualRelayCommand <string>(x => Executed = "ManualRelayCommandWithParameter: " + x, _ => CanExecute); RelayCommandNoCondition = new RelayCommand(() => Executed = "RelayCommandNoCondition"); RelayCommand = new RelayCommand(() => Executed = "RelayCommand", () => CanExecute); RelayCommandWithParamater = new RelayCommand <string>(x => Executed = "RelayCommandWithParamater: " + x, x => CanExecute); ObservingRelayCommand = new ObservingRelayCommand(() => Executed = "ObservingRelayCommand", () => CanExecute, this.ObservePropertyChanged(x => x.CanExecute)); ObservingRelayCommandWithParameter = new ObservingRelayCommand <string>(x => Executed = "ObservingRelayCommandWithParameter:" + x, x => CanExecute, this.ObservePropertyChanged(x => x.CanExecute)); var condition = new Condition(this.ObservePropertyChanged(x => x.CanExecute), () => CanExecute); ConditionRelayCommand = new ConditionRelayCommand(() => Executed = "ObservingRelayCommand", condition); ConditionRelayCommandWithParameter = new ConditionRelayCommand <string>(x => Executed = "ConditionRelayCommandWithParameter: " + x, condition); RaiseCanExecuteCommand = new RelayCommand(RaiseCanExecute); RaiseCanExecuteOnOtherThread = new RelayCommand(() => Task.Run(() => RaiseCanExecute())); DelayedToggleCanExecute = new RelayCommand(async() => { await Task.Delay(500).ConfigureAwait(false); CanExecute = !CanExecute; }); }
public void Execute() { var i = 0; var command = new ConditionRelayCommand <int>(x => i = x, _condition); command.Execute(1); Assert.AreEqual(1, i); }
public void Execute() { var i = 0; var command = new ConditionRelayCommand(() => i++, _condition); command.Execute(); Assert.AreEqual(1, i); }
public void SetUp() { _fake = new Fake { IsTrueOrNull = false }; _observable = _fake.ObservePropertyChanged(x => x.IsTrueOrNull); _condition = new Condition(_observable, () => _fake.IsTrueOrNull); _command = new ConditionRelayCommand(() => { }, _condition); }
public void CanExecute(bool expected) { var fake = new Fake { IsTrue = false }; using var condition = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrue), () => fake.IsTrue); using var command = new ConditionRelayCommand(() => { }, condition); fake.IsTrue = expected; Assert.AreEqual(expected, command.CanExecute()); }
public void Execute() { var i = 0; var fake = new Fake { IsTrueOrNull = false }; using var condition = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrueOrNull), () => fake.IsTrueOrNull); using var command = new ConditionRelayCommand <int>(x => i = x, condition); command.Execute(1); Assert.AreEqual(1, i); }
public void Execute() { var fake = new Fake { IsTrue = true }; using var condition = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrue), () => fake.IsTrue); var i = 0; using var command = new ConditionRelayCommand(() => i++, condition); command.Execute(); Assert.AreEqual(1, i); }
public void CanExecute() { var fake = new FakeInpc { Prop1 = false }; var observable = fake.ToObservable(x => x.Prop1); var condition = new Condition(observable, () => fake.Prop1); var command = new ConditionRelayCommand(_ => { }, condition, false); Assert.IsFalse(command.CanExecute(null)); fake.Prop1 = true; Assert.IsTrue(command.CanExecute(null)); }
public void NotifiesOnConditionChanged() { var fake = new FakeInpc { Prop1 = false }; var observable = fake.ToObservable(x => x.Prop1); var condition = new Condition(observable, () => fake.Prop1); var command = new ConditionRelayCommand(_ => { }, condition, false); int count = 0; command.CanExecuteChanged += (sender, args) => count++; fake.Prop1 = true; Assert.AreEqual(1, count); }
public async Task NotifiesOnConditionChanged() { var count = 0; var fake = new Fake { IsTrueOrNull = false }; using var condition = new Condition(fake.ObservePropertyChangedSlim(x => x.IsTrueOrNull), () => fake.IsTrueOrNull); using var command = new ConditionRelayCommand <int>(x => { }, condition); command.CanExecuteChanged += (sender, args) => count++; fake.IsTrueOrNull = true; await Application.Current.Dispatcher.SimulateYield(); Assert.AreEqual(1, count); }
public void CanExecute(bool expected) { var fake = new Fake { IsTrueOrNull = false }; using (var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrueOrNull), () => fake.IsTrueOrNull)) { using (var command = new ConditionRelayCommand <int>(x => { }, condition)) { fake.IsTrueOrNull = expected; Assert.AreEqual(expected, command.CanExecute(0)); } } }
private void RaiseCanExecute() { ManualRelayCommandNoCondition.RaiseCanExecuteChanged(); ManualRelayCommand.RaiseCanExecuteChanged(); ManualRelayCommandWithParameter.RaiseCanExecuteChanged(); RelayCommandNoCondition.RaiseCanExecuteChanged(); RelayCommand.RaiseCanExecuteChanged(); RelayCommandWithParamater.RaiseCanExecuteChanged(); ObservingRelayCommand.RaiseCanExecuteChanged(); ObservingRelayCommandWithParameter.RaiseCanExecuteChanged(); ConditionRelayCommand.RaiseCanExecuteChanged(); ConditionRelayCommandWithParameter.RaiseCanExecuteChanged(); }
public MappingViewViewModel() { Ints = _ints.AsDispatchingView(); FilteredMappedInts = _ints.AsReadOnlyFilteredView(x => x % 2 == 0).AsMappingView(x => new MappedVm { Value = x }, WpfSchedulers.Dispatcher); MappedInts = _ints.AsMappingView(x => new MappedVm { Value = x }, WpfSchedulers.Dispatcher); MappedIndexedInts = _ints.AsMappingView((x, i) => new MappedVm { Value = x, Index = i }, WpfSchedulers.Dispatcher); FilteredMappedMapped = MappedInts.AsReadOnlyFilteredView(x => x.Value % 2 == 0) .AsMappingView(x => new MappedVm { Value = x.Value * 2 }, WpfSchedulers.Dispatcher); MappedMapped = MappedInts.AsMappingView(x => new MappedVm { Value = x.Value * 2 }, WpfSchedulers.Dispatcher); MappedMappedIndexed = MappedInts.AsMappingView((x, i) => new MappedVm { Value = x.Value * 2, Index = i }, WpfSchedulers.Dispatcher); MappedMappedUpdateIndexed = MappedInts.AsMappingView((x, i) => new MappedVm { Value = x.Value * 2, Index = i }, (x, i) => x.UpdateIndex(i), WpfSchedulers.Dispatcher); MappedMappedUpdateNewIndexed = MappedInts.AsMappingView((x, i) => new MappedVm { Value = x.Value * 2, Index = i }, (x, i) => new MappedVm { Value = x.Value * 2, Index = i }, WpfSchedulers.Dispatcher); AddOneToSourceCommand = new RelayCommand(() => _ints.Add(_ints.Count + 1)); AddOneToSourceOnOtherThreadCommand = new RelayCommand(() => Task.Run(() => _ints.Add(_ints.Count + 1))); ClearCommand = new ConditionRelayCommand( () => _ints.Clear(), new Condition(() => _ints.Any(), _ints.ObserveCollectionChanged())); RemoveAtCommand = new ConditionRelayCommand( () => _ints.RemoveAt(RemoveAt >= _ints.Count ? _ints.Count - 1 : RemoveAt), new Condition(() => _ints.Any(), _ints.ObserveCollectionChanged())); }
public void NotifiesOnConditionChanged() { int count = 0; var fake = new Fake { IsTrue = false }; var observable = fake.ObservePropertyChanged(x => x.IsTrue); var condition = new Condition(observable, () => fake.IsTrue); var command = new ConditionRelayCommand(() => { }, condition); command.CanExecuteChanged += (sender, args) => count++; Assert.AreEqual(0, count); Assert.IsFalse(command.CanExecute()); fake.IsTrue = true; Assert.AreEqual(1, count); Assert.IsTrue(command.CanExecute()); }
private ConditionsViewModel() { _conditions = new List <ICondition> { IsLeftDoorOpenCondition, IsLeftDoorClosedCondition, IsMotorRunningCondition, new IsAnyDoorOpen(), new IsAnyDoorOpen().Negate(), CanStartCondition, CanStartCondition.Negate(), new SyncErrorCondition() }; StartCommand = new ConditionRelayCommand(() => ConditionState.Instance.IsMotorRunning = true, CanStartCondition); StopCommand = new ConditionRelayCommand(() => ConditionState.Instance.IsMotorRunning = false, CanStopCondition); }
public ViewModel() { this.Condition1 = new Condition(this.ToObservable(x => x.IsDoorClosed), () => this.IsDoorClosed) { Name = "Door open" }; this.Condition2 = new Condition(this.ToObservable(x => x.IsMotorRunning), () => this.IsMotorRunning) { Name = "Motor running" }; DependingCondition = new AndCondition(Condition1, Condition2) { Name = "Can start" }; NegatedCondition1 = Condition1.Negate(); _conditions = new List <ICondition> { Condition1, Condition2, DependingCondition, NegatedCondition1 }; StartCommand = new ConditionRelayCommand(o => MessageBox.Show("Clicked " + o), DependingCondition); OtherCommand = new ConditionRelayCommand(o => MessageBox.Show("Clicked " + o), Condition1); }
public async Task NotifiesOnConditionChanged() { var count = 0; var fake = new Fake { IsTrue = false }; using (var condition = new Condition(fake.ObservePropertyChanged(x => x.IsTrue), () => fake.IsTrue)) { using (var command = new ConditionRelayCommand(() => { }, condition)) { command.CanExecuteChanged += (sender, args) => count++; Assert.AreEqual(0, count); Assert.IsFalse(command.CanExecute()); fake.IsTrue = true; await Application.Current.Dispatcher.SimulateYield(); Assert.AreEqual(1, count); Assert.IsTrue(command.CanExecute()); } } }