public void then_input_bindings_keys_mapped_to_commands()
        {
            var converter = new KeyGestureConverter();
            var commandAndGestures = elementContainer.InputBindings.OfType<InputBinding>()
                .Select(x =>
                            new
                            {
                                x.Command,
                                Gesture = converter.ConvertTo((KeyGesture)x.Gesture, typeof(string))
                            });

            Assert.IsTrue(commandAndGestures.Any(x => policy.Commands.Any(y => y == x.Command && y.KeyGesture == x.Gesture.ToString())));
        }
예제 #2
0
 protected override string ConvertTo(ModifierKeys value, Type type = null) {
     KeyGestureConverter c = new KeyGestureConverter();
     return (string)c.ConvertTo(new KeyGesture(Key.None, value), type ?? typeof(string));
 }
예제 #3
0
        public void ConverterTest2() {
            KeyGesture keyGesture;
            KeyGestureConverter c = new KeyGestureConverter();
            keyGesture = (KeyGesture)c.ConvertFrom(" CTRL +  alt + wIN + a");
            Assert.AreEqual(ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Windows, keyGesture.ModifierKeys);
            Assert.AreEqual(Key.A, keyGesture.Key);

            keyGesture = (KeyGesture)c.ConvertFrom(" CTRL +  wIN + f10 + alt");
            Assert.AreEqual(ModifierKeys.Control | ModifierKeys.Alt | ModifierKeys.Windows, keyGesture.ModifierKeys);
            Assert.AreEqual(Key.F10, keyGesture.Key);

            keyGesture = (KeyGesture)c.ConvertFrom("Ctrl+Enter");
            Assert.AreEqual(ModifierKeys.Control, keyGesture.ModifierKeys);
            Assert.AreEqual(Key.Enter, keyGesture.Key);

            Assert.AreEqual("Ctrl+A", c.ConvertTo(new KeyGesture(Key.A, ModifierKeys.Control), typeof(string)));

            AssertHelper.AssertThrows<NotSupportedException>(() => {
                c.ConvertFrom(" CTRL +  wIN + f10 + alt + b");
            });
            AssertHelper.AssertThrows<NotSupportedException>(() => {
                c.ConvertTo(new KeyGesture(Key.A, ModifierKeys.Control), typeof(int));
            });
        }