public void CanExecuteWithParameter() { int i = 5; var command = new ManualRelayCommand(_ => { }, o => i == (int)o); Assert.IsTrue(command.CanExecute(5)); Assert.IsFalse(command.CanExecute(4)); }
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); } }
public void MemoryLeak() { var command = new ManualRelayCommand(() => { }, () => true); var listener = new CommandListener(); var wr = new WeakReference(listener); command.CanExecuteChanged += listener.React; listener = null; GC.Collect(); Assert.IsFalse(wr.IsAlive); command.CanExecute(); // Touching it after to prevent GC }
public void MemoryLeak() { var command = new ManualRelayCommand <int>(x => { }, x => true); var listener = new CommandListener(); var wr = new WeakReference(listener); command.CanExecuteChanged += listener.React; //// ReSharper disable once RedundantAssignment listener = null; GC.Collect(); Assert.IsFalse(wr.IsAlive); command.CanExecute(0); // Touching it after to prevent GC }
public void MemoryLeak() { #if DEBUG return; // debugger keeps things alive. #endif #pragma warning disable CS0162 // Unreachable code detected var command = new ManualRelayCommand(() => { }, () => true); #pragma warning restore CS0162 // Unreachable code detected var listener = new CommandListener(); var wr = new WeakReference(listener); command.CanExecuteChanged += listener.React; //// ReSharper disable once RedundantAssignment listener = null; GC.Collect(); Assert.IsFalse(wr.IsAlive); _ = command.CanExecute(); // Touching it after to prevent GC }
public static void CanExecuteWithParameter(int i, int parameter, bool expected) { var command = new ManualRelayCommand <int>(x => { }, x => i == x); Assert.AreEqual(expected, command.CanExecute(parameter)); }
public void CanExecute(bool canExecute) { var command = new ManualRelayCommand(() => { }, () => canExecute); Assert.AreEqual(canExecute, command.CanExecute()); }