public static void ExecuteWithParameter() { var invokeCount = 0; var command = new ManualRelayCommand <int>(o => invokeCount = o, _ => true); command.Execute(4); Assert.AreEqual(4, invokeCount); }
public void ExecuteNoParameter() { int invokeCount = 0; var command = new ManualRelayCommand(_ => invokeCount++, _ => true); command.Execute(null); Assert.AreEqual(1, invokeCount); }
public void ExecuteNotifies() { var invokeCount = 0; var isExecutingCount = 0; var command = new ManualRelayCommand(() => invokeCount++, () => true); command.ObservePropertyChangedSlim(nameof(command.IsExecuting), false) .Subscribe(_ => isExecutingCount++); Assert.IsFalse(command.IsExecuting); Assert.True(command.CanExecute()); command.Execute(); Assert.IsFalse(command.IsExecuting); Assert.True(command.CanExecute()); Assert.AreEqual(1, invokeCount); Assert.AreEqual(2, isExecutingCount); }
public static void ExecuteNotifies() { var invokeCount = 0; var isExecutingCount = 0; var command = new ManualRelayCommand <int>(i => invokeCount += i, _ => true); using (command.ObservePropertyChangedSlim(nameof(command.IsExecuting), signalInitial: false) .Subscribe(_ => isExecutingCount++)) { Assert.IsFalse(command.IsExecuting); Assert.True(command.CanExecute(1)); command.Execute(1); Assert.IsFalse(command.IsExecuting); Assert.True(command.CanExecute(1)); Assert.AreEqual(1, invokeCount); Assert.AreEqual(2, isExecutingCount); } }