public void TestInvokeParameterCommandWithEventArgs()
        {
            var trigger = new EventToCommandStub();
            var rectangle = new Rectangle();
            ((IAttachedObject)trigger).Attach(rectangle);

            trigger.PassEventArgsToCommand = true;

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

#if SL3
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

            var args = new StringEventArgs("StringEventArgs");
            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(args.Parameter, vm.ParameterReceived);
        }
Exemplo n.º 2
0
        public void TestInvokeWithValueParameterNull()
        {
            var rectangle = new Rectangle();
            var trigger   = new EventToCommandStub();

            ((IAttachedObject)trigger).Attach(rectangle);

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

#if SILVERLIGHT
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

            trigger.CommandParameterValue = null;
            trigger.InvokeWithEventArgs(new StringEventArgs("Test"));

            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(null, vm.ParameterReceived);
        }
Exemplo n.º 3
0
        public void TestInvokeWithEventArgsAndBoundParameter()
        {
            var trigger   = new EventToCommandStub();
            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            trigger.PassEventArgsToCommand = true;

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

            var textBox = new TextBox
            {
                Text = "BoundParameter"
            };

            var bindingParameter = new Binding
            {
                Source = textBox,
                Path   = new PropertyPath("Text")
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            BindingOperations.SetBinding(trigger, EventToCommand.CommandParameterProperty, bindingParameter);

            var args = new StringEventArgs("StringEventArgs");

            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(textBox.Text, vm.ParameterReceived);
        }
Exemplo n.º 4
0
        public void TestInvokeWithEventArgsAndParameterValue()
        {
            var trigger   = new EventToCommandStub();
            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            trigger.PassEventArgsToCommand = true;

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

#if SILVERLIGHT
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

            const string CommandParameter = "CommandParameter";
            trigger.CommandParameterValue = CommandParameter;

            var args = new StringEventArgs("StringEventArgs");
            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(CommandParameter, vm.ParameterReceived);
        }
Exemplo n.º 5
0
        public void TestInvokeWithEventArgsAndParameterValueAndConverterAndConverterParameter()
        {
            var trigger   = new EventToCommandStub();
            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            const string prefix = "Test";

            trigger.PassEventArgsToCommand = true;
            trigger.EventArgsConverter     = new TestEventArgsConverter
            {
                TestPrefix = prefix
            };
            trigger.EventArgsConverterParameter = "Suffix";

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            const string commandParameter = "CommandParameter";

            trigger.CommandParameterValue = commandParameter;

            var args = new StringEventArgs("StringEventArgs");

            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(commandParameter, vm.ParameterReceived);
        }
        public void TestInvokeSimpleCommandWithEventArgsAndConverter()
        {
            var trigger   = new EventToCommandStub();
            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            const string prefix = "Test";

            trigger.PassEventArgsToCommand = true;
            trigger.EventArgsConverter     = new TestEventArgsConverter
            {
                TestPrefix = prefix
            };

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.SimpleCommand
            };

#if SL3
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

            var args = new StringEventArgs("StringEventArgs");
            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(null, vm.ParameterReceived);
        }
Exemplo n.º 7
0
        public void TestInvokeWithValueParameterNull()
        {
            var rectangle = new Rectangle();
            var trigger = new EventToCommandStub();
            ((IAttachedObject)trigger).Attach(rectangle);

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            trigger.CommandParameterValue = null;
            trigger.InvokeWithEventArgs(new StringEventArgs("Test"));

            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(null, vm.ParameterReceived);
        }
Exemplo n.º 8
0
        public void TestInvokeWithEventArgsAndNoParameter()
        {
            var trigger   = new EventToCommandStub();
            var rectangle = new Rectangle();

            ((IAttachedObject)trigger).Attach(rectangle);

            trigger.PassEventArgsToCommand = true;

            var vm      = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.CommandWithEventArgs
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            var args = new StringEventArgs("StringEventArgs");

            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(args.Parameter, vm.ParameterReceived);
        }
        public void TestInvokeWithEventArgsAndBoundParameterAndConverterAndConverterParameter()
        {
            var trigger = new EventToCommandStub();
            var rectangle = new Rectangle();
            ((IAttachedObject)trigger).Attach(rectangle);

            const string prefix = "Test";
            trigger.PassEventArgsToCommand = true;
            trigger.EventArgsConverter = new TestEventArgsConverter
            {
                TestPrefix = prefix
            };
            trigger.EventArgsConverterParameter = "Suffix";

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

            var textBox = new TextBox
            {
                Text = "BoundParameter"
            };

            var bindingParameter = new Binding
            {
                Source = textBox,
                Path = new PropertyPath("Text")
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            BindingOperations.SetBinding(trigger, EventToCommand.CommandParameterProperty, bindingParameter);

            var args = new StringEventArgs("StringEventArgs");
            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(textBox.Text, vm.ParameterReceived);
        }
        public void TestInvokeWithEventArgsAndParameterValueAndConverter()
        {
            var trigger = new EventToCommandStub();
            var rectangle = new Rectangle();
            ((IAttachedObject)trigger).Attach(rectangle);

            const string prefix = "Test";
            trigger.PassEventArgsToCommand = true;
            trigger.EventArgsConverter = new TestEventArgsConverter
            {
                TestPrefix = prefix
            };

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);

            const string commandParameter = "CommandParameter";
            trigger.CommandParameterValue = commandParameter;

            var args = new StringEventArgs("StringEventArgs");
            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(commandParameter, vm.ParameterReceived);
        }
        public void TestInvokeSimpleCommandWithEventArgsAndConverterAndConverterParameter()
        {
            var trigger = new EventToCommandStub();
            var rectangle = new Rectangle();
            ((IAttachedObject)trigger).Attach(rectangle);

            const string prefix = "Test";
            trigger.PassEventArgsToCommand = true;
            trigger.EventArgsConverter = new TestEventArgsConverter
            {
                TestPrefix = prefix
            };
            trigger.EventArgsConverterParameter = "Suffix";

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.SimpleCommand
            };

#if SL3
            trigger.Command = binding;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
#endif

            var args = new StringEventArgs("StringEventArgs");
            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(null, vm.ParameterReceived);
        }
        public void TestInvokeWithEventArgsAndBoundParameter()
        {
            var trigger = new EventToCommandStub();
            var rectangle = new Rectangle();
            ((IAttachedObject)trigger).Attach(rectangle);

            trigger.PassEventArgsToCommand = true;

            var vm = new TestViewModel();
            var binding = new Binding
            {
                Source = vm.ParameterCommand
            };

            var textBox = new TextBox
            {
                Text = "BoundParameter"
            };

            var bindingParameter = new Binding
            {
                Source = textBox,
                Path = new PropertyPath("Text")
            };

#if SILVERLIGHT
            trigger.Command = binding;
            trigger.CommandParameter = bindingParameter;
#else
            BindingOperations.SetBinding(trigger, EventToCommand.CommandProperty, binding);
            BindingOperations.SetBinding(trigger, EventToCommand.CommandParameterProperty, bindingParameter);
#endif

            var args = new StringEventArgs("StringEventArgs");
            trigger.InvokeWithEventArgs(args);
            Assert.IsTrue(vm.CommandExecuted);
            Assert.AreEqual(textBox.Text, vm.ParameterReceived);
        }