浏览代码

Added failing test for #5054.

Steven Kirk 4 年之前
父节点
当前提交
6b94cc4ed9
共有 1 个文件被更改,包括 38 次插入1 次删除
  1. 38 1
      tests/Avalonia.Input.UnitTests/KeyboardDeviceTests.cs

+ 38 - 1
tests/Avalonia.Input.UnitTests/KeyboardDeviceTests.cs

@@ -1,5 +1,9 @@
-using Avalonia.Input.Raw;
+using System;
+using System.Windows.Input;
+using Avalonia.Controls;
+using Avalonia.Input.Raw;
 using Avalonia.Interactivity;
+using Avalonia.UnitTests;
 using Moq;
 using Xunit;
 
@@ -86,5 +90,38 @@ namespace Avalonia.Input.UnitTests
 
             focused.Verify(x => x.RaiseEvent(It.IsAny<TextInputEventArgs>()));
         }
+
+        [Fact]
+        public void Can_Change_KeyBindings_In_Keybinding_Event_Handler()
+        {
+            var target = new KeyboardDevice();
+            var button = new Button();
+            var root = new TestRoot(button);
+
+            button.KeyBindings.Add(new KeyBinding
+            {
+                Gesture = new KeyGesture(Key.O, KeyModifiers.Control),
+                Command = new DelegateCommand(() => button.KeyBindings.Clear()),
+            });
+
+            target.SetFocusedElement(button, NavigationMethod.Pointer, 0);
+            target.ProcessRawEvent(
+                new RawKeyEventArgs(
+                    target,
+                    0,
+                    root,
+                    RawKeyEventType.KeyDown,
+                    Key.O,
+                    RawInputModifiers.Control));
+        }
+
+        private class DelegateCommand : ICommand
+        {
+            private readonly Action _action;
+            public DelegateCommand(Action action) => _action = action;
+            public event EventHandler CanExecuteChanged;
+            public bool CanExecute(object parameter) => true;
+            public void Execute(object parameter) => _action();
+        }
     }
 }