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 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));
        }
        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 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));
        }
        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 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));
        }
        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));
        }
        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);
        }
        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);
        }
        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);
        }