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