예제 #1
0
        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);
        }
예제 #2
0
 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));
 }
예제 #3
0
        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);
        }
예제 #4
0
 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);
 }
예제 #5
0
 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));
 }
예제 #6
0
 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));
 }
예제 #7
0
 public void EnablesIfTargetAndActionExistAndNoGuardMethod()
 {
     var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw);
     Assert.True(cmd.CanExecute(null));
 }
예제 #8
0
 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));
 }
예제 #9
0
 public void ExecuteCallsMethod()
 {
     var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Enable, ActionUnavailableBehaviour.Enable);
     cmd.Execute(null);
     Assert.True(this.target.DoSomethingCalled);
 }
예제 #10
0
 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);
 }
예제 #11
0
 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);
 }
예제 #12
0
 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));
 }
예제 #13
0
 public void IgnoresGuardIfGuardDoesNotReturnBool()
 {
     var cmd = new CommandAction(this.subject, null, "DoSomethingWithBadGuard", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw);
     Assert.True(cmd.CanExecute(true));
 }
예제 #14
0
 public void DisablesIfTargetAndActionExistAndGuardMethodReturnsFalse()
 {
     this.target.CanDoSomethingWithGuard = false;
     var cmd = new CommandAction(this.subject, null, "DoSomethingWithGuard", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Throw);
     Assert.False(cmd.CanExecute(null));
 }
예제 #15
0
 public void ThrowsIfTargetNullBehaviourIsThrowAndTargetBecomesNull()
 {
     var cmd = new CommandAction(this.subject, null, "DoSomething", ActionUnavailableBehaviour.Throw, ActionUnavailableBehaviour.Disable);
     Assert.Throws<ActionTargetNullException>(() => View.SetActionTarget(this.subject, null));
 }
예제 #16
0
 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);
 }
예제 #17
0
 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));
 }
예제 #18
0
 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);
 }
예제 #19
0
        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);
        }
예제 #20
0
 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));
 }