Inheritance: ICommand
        public void ShouldDisableButtonIfCanExecuteFalse()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand() { CanExecuteReturnValue = false };

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            Assert.IsTrue(clickableObject.IsEnabled);

            behavior.Command = command;
            Assert.IsFalse(clickableObject.IsEnabled);
        }
Ejemplo n.º 2
0
        public void ShouldHookUpClickCommandBehaviorWhenSettingProperty()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            Click.SetCommand(clickableObject, command);
            Assert.IsFalse(command.ExecuteCalled);

            clickableObject.RaiseClick();

            Assert.IsTrue(command.ExecuteCalled);
            Assert.AreSame(command, Click.GetCommand(clickableObject));
        }
        public void ShouldObserveClickEvent()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;
            Assert.IsFalse(command.ExecuteCalled);

            clickableObject.RaiseClick();

            Assert.IsTrue(command.ExecuteCalled);
        }
Ejemplo n.º 4
0
        public void WhenChangingProperty_ThenUpdatesCommand()
        {
            var someControl = new TextBox();
            var oldCommand = new MockCommand();
            var newCommand = new MockCommand();
            var commandAction = new InvokeCommandAction();
            commandAction.Attach(someControl);
            commandAction.Command = oldCommand;
            commandAction.Command = newCommand;
            commandAction.Invoke();

            Assert.IsTrue(newCommand.ExecuteCalled);
            Assert.IsFalse(oldCommand.ExecuteCalled);
        }
        public void ShouldReEnableButtonIfCanExecuteChangedRaises()
        {
            var clickableObject = new MockClickableObject();
            var mockCommand = new MockCommand() { CanExecuteReturnValue = false };

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = mockCommand;
            Assert.IsFalse(clickableObject.IsEnabled);

            mockCommand.CanExecuteReturnValue = true;
            mockCommand.RaiseCanExecuteChanged();

            Assert.IsTrue(clickableObject.IsEnabled);
        }
Ejemplo n.º 6
0
        public void ShouldUpdateCommandOnBehaviorWhenChangingProperty()
        {
            var clickableObject = new MockClickableObject();
            var oldCommand = new MockCommand();
            var newCommand = new MockCommand();

            Click.SetCommand(clickableObject, oldCommand);
            Click.SetCommand(clickableObject, newCommand);

            clickableObject.RaiseClick();

            Assert.IsTrue(newCommand.ExecuteCalled);
            Assert.IsFalse(oldCommand.ExecuteCalled);
        }
Ejemplo n.º 7
0
        public void WhenCommandPropertyIsSet_ThenHooksUpCommandBehavior()
        {
            var someControl = new TextBox();
            var commandAction = new InvokeCommandAction();
            var command = new MockCommand();
            commandAction.Attach(someControl);
            commandAction.Command = command;

            Assert.IsFalse(command.ExecuteCalled);

            commandAction.Invoke();

            Assert.IsTrue(command.ExecuteCalled);
            Assert.AreSame(command, commandAction.GetValue(InvokeCommandAction.CommandProperty));
        }
Ejemplo n.º 8
0
        public void WhenAttachedAfterCommandPropertyIsSetAndInvoked_ThenInvokesCommand()
        {
            var someControl = new TextBox();
            var commandAction = new InvokeCommandAction();
            var command = new MockCommand();
            commandAction.Command = command;
            commandAction.Attach(someControl);

            Assert.IsFalse(command.ExecuteCalled);

            commandAction.Invoke();

            Assert.IsTrue(command.ExecuteCalled);
            Assert.AreSame(command, commandAction.GetValue(InvokeCommandAction.CommandProperty));
        }
Ejemplo n.º 9
0
        public void ShouldExecuteWithCommandParameter()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();
            var parameter = new object();

            Click.SetCommand(clickableObject, command);
            Click.SetCommandParameter(clickableObject, parameter);
            Assert.IsNull(command.ExecuteParameter);

            clickableObject.RaiseClick();

            Assert.IsTrue(command.ExecuteCalled);
            Assert.IsNotNull(command.ExecuteParameter);
            Assert.AreSame(parameter, command.ExecuteParameter);
        }
Ejemplo n.º 10
0
        public void ShouldCallCanExecuteOnParameterChange()
        {
            var clickableObject = new MockClickableObject();

            var command = new MockCommand();
            var parameter = new object();
            Click.SetCommand(clickableObject, command);
            Assert.IsNull(command.CanExecuteParameter);
            Assert.IsTrue(clickableObject.IsEnabled);

            command.CanExecuteReturnValue = false;
            Click.SetCommandParameter(clickableObject, parameter);

            Assert.IsNotNull(command.CanExecuteParameter);
            Assert.AreSame(parameter, command.CanExecuteParameter);
            Assert.IsFalse(clickableObject.IsEnabled);
        }
Ejemplo n.º 11
0
        public void WhenInvokedWithCommandParameter_ThenPassesCommandParaeterToExecute()
        {
            var someControl = new TextBox();
            var command = new MockCommand();
            var parameter = new object();
            var commandAction = new InvokeCommandAction();
            commandAction.Attach(someControl);
            commandAction.Command = command;
            commandAction.CommandParameter = parameter;

            Assert.IsNull(command.ExecuteParameter);

            commandAction.Invoke();

            Assert.IsTrue(command.ExecuteCalled);
            Assert.IsNotNull(command.ExecuteParameter);
            Assert.AreSame(parameter, command.ExecuteParameter);
        }
Ejemplo n.º 12
0
        public void WhenDetatched_ThenSetsCommandAndCommandParameterToNull()
        {
            var someControl = new TextBox();
            var command = new MockCommand();
            var parameter = new object();
            var commandAction = new InvokeCommandAction();
            commandAction.Attach(someControl);
            commandAction.Command = command;
            commandAction.CommandParameter = parameter;

            Assert.IsNotNull(commandAction.Command);
            Assert.IsNotNull(commandAction.CommandParameter);

            commandAction.Detach();

            Assert.IsNull(commandAction.Command);
            Assert.IsNull(commandAction.CommandParameter);
        }
        public void ShouldCallCanExecuteWithParameterWhenSettingCommand()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();
            var parameter = new object();
            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            command.CanExecuteReturnValue = false;
            behavior.CommandParameter = parameter;
            Assert.IsNull(command.CanExecuteParameter);
            Assert.IsTrue(clickableObject.IsEnabled);

            behavior.Command = command;

            Assert.IsNotNull(command.CanExecuteParameter);
            Assert.AreSame(parameter, command.CanExecuteParameter);
            Assert.IsFalse(clickableObject.IsEnabled);
        }
        public void ShouldExecuteWithCommandParameter()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();
            var parameter = new object();
            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;
            behavior.CommandParameter = parameter;
            Assert.IsNull(command.ExecuteParameter);

            clickableObject.RaiseClick();

            Assert.IsTrue(command.ExecuteCalled);
            Assert.IsNotNull(command.ExecuteParameter);
            Assert.AreSame(parameter, command.ExecuteParameter);
        }
        public void DisposedControlStopsMonitoringCommandAfterFirstCanExecuteChanged()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            clickableObject = null;
            WeakReference commandReference = new WeakReference(command);
            GC.Collect();

            command.CanExecuteReturnValue = false;
            command.RaiseCanExecuteChanged();
            command = null;

            GC.Collect();

            Assert.IsFalse(commandReference.IsAlive);
        }
        public void DisposedControlDoesNotThrowOnCanExecuteChanged()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            WeakReference controlWeakReference = new WeakReference(clickableObject);
            clickableObject = null;
            behavior = null;
            GC.Collect();

            command.CanExecuteReturnValue = false;
            command.RaiseCanExecuteChanged();
        }
        public void CommandShouldNotKeepButtonAlive()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            WeakReference controlWeakReference = new WeakReference(clickableObject);
            clickableObject = null;
            behavior = null;
            GC.Collect();

            Assert.IsFalse(controlWeakReference.IsAlive);
            GC.KeepAlive(command);
        }
        public void ShouldNotMonitorCanExecuteChangedOnDisconnectedCommand()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            behavior.Command = null;

            Assert.IsTrue(clickableObject.IsEnabled);
            command.CanExecuteReturnValue = false;
            command.RaiseCanExecuteChanged();
            Assert.IsTrue(clickableObject.IsEnabled);
        }
        public void ShouldNotThrowWhenCommandSetToNull()
        {
            var clickableObject = new MockClickableObject();
            var command = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = command;

            behavior.Command = null;
            clickableObject.RaiseClick();
        }
Ejemplo n.º 20
0
        public void WhenCommandIsSetAndThenBehaviorIsAttached_ThenCommandsCanExecuteIsCalledOnce()
        {
            var someControl = new TextBox();
            var command = new MockCommand();
            var commandAction = new InvokeCommandAction();
            commandAction.Command = command;
            commandAction.Attach(someControl);

            Assert.AreEqual(1, command.CanExecuteTimesCalled);
        }
Ejemplo n.º 21
0
        public void WhenCommandAndCommandParameterAreSetPriorToBehaviorBeingAttached_ThenCommandIsExecutedCorrectlyOnInvoke()
        {
            var someControl = new TextBox();
            var command = new MockCommand();
            var parameter = new object();
            var commandAction = new InvokeCommandAction();
            commandAction.Command = command;
            commandAction.CommandParameter = parameter;
            commandAction.Attach(someControl);

            commandAction.Invoke();
           
            Assert.IsTrue(command.ExecuteCalled);
        }
        public void ChangingCommandsShouldExecuteOnNewCommand()
        {
            var clickableObject = new MockClickableObject();
            var originalCommand = new MockCommand() { CanExecuteReturnValue = true };
            var newCommand = new MockCommand() { CanExecuteReturnValue = true };

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);
            behavior.Command = originalCommand;

            clickableObject.RaiseClick();
            Assert.IsFalse(newCommand.ExecuteCalled);

            behavior.Command = newCommand;
            clickableObject.RaiseClick();
            Assert.IsTrue(newCommand.ExecuteCalled);
        }
Ejemplo n.º 23
0
        public void WhenCommandParameterChanged_ThenUpdatesIsEnabledState()
        {
            var someControl = new TextBox();
            var command = new MockCommand();
            var parameter = new object();
            var commandAction = new InvokeCommandAction();
            commandAction.Attach(someControl);
            commandAction.Command = command;

            Assert.IsNull(command.CanExecuteParameter);
            Assert.IsTrue(someControl.IsEnabled);

            command.CanExecuteReturnValue = false;
            commandAction.CommandParameter = parameter;

            Assert.IsNotNull(command.CanExecuteParameter);
            Assert.AreSame(parameter, command.CanExecuteParameter);
            Assert.IsFalse(someControl.IsEnabled);
        }