public void OperatesAfterCollection() { var view = new DependencyObject(); var cmd = new CommandAction(view, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); GC.Collect(); View.SetActionTarget(view, this.target); cmd.Execute(null); Assert.IsTrue(this.target.DoSomethingCalled); }
public void ExecuteThrowsIfTargetIsDefault() { View.SetActionTarget(this.subject, View.InitialActionTarget); var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); Assert.Throws<ActionNotSetException>(() => cmd.Execute(null)); }
public void DoesNotRetainTarget() { var view = new DependencyObject(); var weakView = new WeakReference(view); View.SetActionTarget(view, this.target); var cmd = new CommandAction(view, null, "DoSomethingWithGuard", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); view = null; cmd = null; GC.Collect(); Assert.False(weakView.IsAlive); }
public void PropagatesGuardPropertException() { var cmd = new CommandAction(this.subject, null, "DoSomethingWithUnsuccessfulGuardMethod", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); var e = Assert.Throws<InvalidOperationException>(() => cmd.CanExecute(null)); Assert.AreEqual("foo", e.Message); }
public void ControlIsEnabledIfTargetIsDefault() { View.SetActionTarget(this.subject, View.InitialActionTarget); var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); Assert.True(cmd.CanExecute(null)); }
public void ThrowsIfActionNonExistentBehaviourIsThrowAndActionIsNonExistent() { var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); Assert.DoesNotThrow(() => View.SetActionTarget(this.subject, new Target2())); Assert.Throws<ActionNotFoundException>(() => cmd.Execute(null)); }
public void EnablesIfTargetAndActionExistAndNoGuardMethod() { var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); Assert.True(cmd.CanExecute(null)); }
public void ExecuteDoesNothingIfActionIsNull() { var cmd = new CommandAction(this.subject, null, "DoesNotExist", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); View.SetActionTarget(this.subject, null); Assert.DoesNotThrow(() => cmd.Execute(null)); }
public void ExecuteCallsMethod() { var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); cmd.Execute(null); Assert.True(this.target.DoSomethingCalled); }
public void RaisesEventWhenGuardValueChanges() { this.target.CanDoSomethingWithGuard = false; var cmd = new CommandAction(this.subject, null, "DoSomethingWithGuard", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); bool eventRaised = false; cmd.CanExecuteChanged += (o, e) => eventRaised = true; this.target.CanDoSomethingWithGuard = true; Assert.True(eventRaised); }
public void RaisesEventWhenTargetChanges() { var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Disable, ActionUnavailableBehaviour.Disable); bool eventRaised = false; cmd.CanExecuteChanged += (o, e) => eventRaised = true; View.SetActionTarget(this.subject, null); Assert.True(eventRaised); }
public void ChangesEnabledStateWhenGuardChanges() { this.target.CanDoSomethingWithGuard = false; var cmd = new CommandAction(this.subject, null, "DoSomethingWithGuard", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); Assert.False(cmd.CanExecute(null)); this.target.CanDoSomethingWithGuard = true; Assert.True(cmd.CanExecute(null)); }
public void IgnoresGuardIfGuardDoesNotReturnBool() { var cmd = new CommandAction(this.subject, null, "DoSomethingWithBadGuard", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); Assert.True(cmd.CanExecute(true)); }
public void DisablesIfTargetAndActionExistAndGuardMethodReturnsFalse() { this.target.CanDoSomethingWithGuard = false; var cmd = new CommandAction(this.subject, null, "DoSomethingWithGuard", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); Assert.False(cmd.CanExecute(null)); }
public void ThrowsIfTargetNullBehaviourIsThrowAndTargetBecomesNull() { var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Disable); Assert.Throws<ActionTargetNullException>(() => View.SetActionTarget(this.subject, null)); }
public void ExecutePassesArgumentIfGiven() { var cmd = new CommandAction(this.subject, null, "DoSomethingWithArgument", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); var arg = "hello"; cmd.Execute(arg); Assert.AreEqual("hello", this.target.DoSomethingArgument); }
public void EnablesIfTargetNullBehaviourIsEnableAndTargetIsNull() { var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Disable); View.SetActionTarget(this.subject, null); Assert.True(cmd.CanExecute(null)); }
public void PropagatesActionException() { var cmd = new CommandAction(this.subject, null, "DoSomethingUnsuccessfully", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable); var e = Assert.Throws<InvalidOperationException>(() => cmd.Execute(null)); Assert.AreEqual("woo", e.Message); }
public void UsesBackupSubjectIfActionTargetNotAvailable() { var view = new DependencyObject(); var backupView = new DependencyObject(); var cmd = new CommandAction(view, backupView, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw); View.SetActionTarget(backupView, this.target); view.SetValue(FrameworkElement.DataContextProperty, this.target); cmd.Execute(null); Assert.IsTrue(this.target.DoSomethingCalled); }
public void EnablesIfActionNonExistentBehaviourIsThrowAndActionIsNonExistent() { var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Enable); View.SetActionTarget(this.subject, new Target2()); Assert.True(cmd.CanExecute(null)); }