public void ShouldNotExecuteCommandOnKeyDifferentThanEnter()
        {
            var textBox = new TextBox();
            textBox.Text = "MyParameter";
            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);
            var command = new MockCommand();
            behavior.Command = command;

            behavior.InvokeKeyPressed(Key.Space);

            Assert.IsFalse(command.ExecuteCalled);
        }
        public void ShouldSetEmptyTextAfterCommandExecution()
        {
            var textBox = new TextBox();
            var command = new MockCommand();

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);
            behavior.Command = command;
            behavior.DefaultTextAfterCommandExecution = "MyDefaultText";

            behavior.InvokeKeyPressed(Key.Enter);

            Assert.AreEqual(string.Empty, textBox.Text);
        }
        public void ShouldNotExecuteCommandOnKeyDifferentThanEnter()
        {
            var textBox = new TextBox();

            textBox.Text = "MyParameter";
            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);
            var command = new MockCommand();

            behavior.Command = command;

            behavior.InvokeKeyPressed(Key.Space);

            Assert.IsFalse(command.ExecuteCalled);
        }
        public void ShouldSetEmptyTextAfterCommandExecution()
        {
            var textBox = new TextBox();
            var command = new MockCommand();

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);

            behavior.Command = command;
            behavior.DefaultTextAfterCommandExecution = "MyDefaultText";

            behavior.InvokeKeyPressed(Key.Enter);

            Assert.AreEqual(string.Empty, textBox.Text);
        }
        public void ShouldClearTextOnFocus()
        {
            var textBox = new TextBox();
            textBox.Text = "DefaultText";
            var command = new MockCommand();

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);
            behavior.Command = command;
            behavior.DefaultTextAfterCommandExecution = "DefaultText";

            textBox.Focus();

            Assert.AreEqual(string.Empty, textBox.Text);
        }
        public void ShouldClearTextOnFocus()
        {
            var textBox = new TextBox();

            textBox.Text = "DefaultText";
            var command = new MockCommand();

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);

            behavior.Command = command;
            behavior.DefaultTextAfterCommandExecution = "DefaultText";

            textBox.Focus();

            Assert.AreEqual(string.Empty, textBox.Text);
        }
        public void ShouldExecuteCommandOnEnter()
        {
            var textBox = new TextBox();
            textBox.Text = "MyParameter";
            textBox.AcceptsReturn = true;
            var command = new MockCommand();
            Assert.IsTrue(textBox.AcceptsReturn);

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);
            Assert.IsFalse(textBox.AcceptsReturn);
            behavior.Command = command;

            behavior.InvokeKeyPressed(Key.Enter);

            Assert.IsTrue(command.ExecuteCalled);
            Assert.AreEqual("MyParameter", command.ExecuteParameter);
        }
        public void ShouldExecuteCommandOnEnter()
        {
            var textBox = new TextBox();

            textBox.Text          = "MyParameter";
            textBox.AcceptsReturn = true;
            var command = new MockCommand();

            Assert.IsTrue(textBox.AcceptsReturn);

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);

            Assert.IsFalse(textBox.AcceptsReturn);
            behavior.Command = command;

            behavior.InvokeKeyPressed(Key.Enter);

            Assert.IsTrue(command.ExecuteCalled);
            Assert.AreEqual("MyParameter", command.ExecuteParameter);
        }
        public void ShouldResetTextOnLostFocus()
        {
            var textBox = new TextBox();
            var textBox2 = new TextBox();
            var grid = new Grid();
            grid.Children.Add(textBox);
            grid.Children.Add(textBox2);
            var command = new MockCommand();

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);
            behavior.Command = command;
            behavior.DefaultTextAfterCommandExecution = "DefaultText";

            textBox.Focus();

            DependencyObject scope = FocusManager.GetFocusScope(textBox);
            FocusManager.SetFocusedElement(scope, textBox2 as IInputElement);

            Assert.AreEqual("DefaultText", textBox.Text);
        }
        public void ShouldResetTextOnLostFocus()
        {
            var textBox  = new TextBox();
            var textBox2 = new TextBox();
            var grid     = new Grid();

            grid.Children.Add(textBox);
            grid.Children.Add(textBox2);
            var command = new MockCommand();

            TestableReturnCommandBehavior behavior = new TestableReturnCommandBehavior(textBox);

            behavior.Command = command;
            behavior.DefaultTextAfterCommandExecution = "DefaultText";

            textBox.Focus();

            DependencyObject scope = FocusManager.GetFocusScope(textBox);

            FocusManager.SetFocusedElement(scope, textBox2 as IInputElement);

            Assert.AreEqual("DefaultText", textBox.Text);
        }