public void ShouldNotThrowWhenCommandSetToNull()
        {
            var clickableObject = new MockClickableObject();
            var command         = new MockCommand();

            var behavior = new ButtonBaseClickCommandBehavior(clickableObject);

            behavior.Command = command;

            behavior.Command = null;
            clickableObject.RaiseClick();
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }
        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);
        }