Example #1
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 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);
        }
Example #2
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 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);
        }
Example #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);
        }
Example #4
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);
        }
Example #5
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);
        }
Example #6
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 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);
        }
Example #7
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")
            };

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