Esempio n. 1
0
        public void UnregisteredHotKeyShoudNotReact()
        {
            var hotKey = HotKey.Create(Key.Escape, ModifierKeys.None);

            hotKey.Register();
            hotKey.Unregister();

            var toSend = new[]
            {
                new KeyEventArgs(Key.Escape, KeyState.KeyDown),
                new KeyEventArgs(Key.Escape, KeyState.KeyUp)
            };

            var actual = EventWaiter.WaitEvent(
                handler => hotKey.Pressed += handler,
                handler => hotKey.Pressed -= handler,
                () =>
            {
                _sender.Send(toSend);
            });

            hotKey.Unregister();

            Assert.False(actual);
            hotKey.Dispose();
        }
Esempio n. 2
0
        public void SendingKeyShouldFireKeyReceivedEvent()
        {
            var expected = new List <KeyEventArgs>
            {
                new KeyEventArgs(Key.Escape, KeyState.KeyDown),
                new KeyEventArgs(Key.Escape, KeyState.KeyUp)
            };

            var actual = EventWaiter.WaitEvent <KeyEventArgs>(
                handler => _receiver.KeyReceived += handler,
                handler => _receiver.KeyReceived -= handler,
                () => _sender.Send(expected),
                2);

            Assert.That(actual, Is.EquivalentTo(expected));
        }
Esempio n. 3
0
        public void SendingKeyShouldNotFireKeyReceivedWhenUninstalled()
        {
            var toSend = new List <KeyEventArgs>
            {
                new KeyEventArgs(Key.Escape, KeyState.KeyDown),
                new KeyEventArgs(Key.Escape, KeyState.KeyUp)
            };

            _receiver.Uninstall();

            var actual = EventWaiter.WaitEvent <KeyEventArgs>(
                handler => _receiver.KeyReceived += handler,
                handler => _receiver.KeyReceived -= handler,
                () => _sender.Send(toSend),
                2);

            Assert.That(actual, Is.Empty);
        }