예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }