Example #1
0
        public void ReceivingNativeInput_WhenHooked_CallsFactoryWithReceivedInput()
        {
            // Arrange
            Action <NativeKeyboardInput> nativeInputCallback = null;

            _nativeKeyboardHookServiceMock.Setup(f => f.Hook(It.IsAny <Action <NativeKeyboardInput> >())).Callback <Action <NativeKeyboardInput> >(a => nativeInputCallback = a);
            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>()));

            var keyboardInput = new KeyboardInput(
                KeyboardInputKey.A,
                KeyboardInputDirection.KeyDown,
                new KeyboardInputLocks(false, false, false),
                new KeyboardInputModifiers(!false, false, false));

            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>())).Returns(keyboardInput);

            var keyboardEventConfiguration = new KeyboardEventConfiguration(
                new KeyboardInputKeyConfiguration(KeyboardInputKey.AllKeys.ToArray()),
                ModifierConfiguration.CreateNotApplicable(),
                LockConfiguration.CreateNotApplicable());

            _receiverMock.Setup(f => f.ReceiveAsync(It.IsAny <KeyboardInput>())).Returns(Task.FromResult(true));
            _receiverMock.Setup(f => f.Configuration).Returns(keyboardEventConfiguration);
            _sut.HookKeyboard();

            var nativeKeyboardInput = new NativeKeyboardInput(Keys.A, NativeKeyboardInputDirection.KeyDown);

            // Act
            nativeInputCallback(nativeKeyboardInput);

            // Assert
            _keyboardInputFactoryMock.Verify(f => f.Create(nativeKeyboardInput), Times.Once);
        }
Example #2
0
        public void ReceivingNativeInput_ReceiverNotConfiguredForEvent_DoesNotCallReceiver()
        {
            // Arrange
            const bool ScrollLockMustBeActive = true;

            var keyboardInput = new KeyboardInput(
                KeyboardInputKey.A,
                KeyboardInputDirection.KeyDown,
                new KeyboardInputLocks(false, false, false),
                new KeyboardInputModifiers(!ScrollLockMustBeActive, false, false));

            var keyboardEventConfiguration = new KeyboardEventConfiguration(
                new KeyboardInputKeyConfiguration(KeyboardInputKey.AllKeys.ToArray()),
                ModifierConfiguration.CreateNotApplicable(),
                new LockConfiguration(ScrollLockMustBeActive, false, false));

            _receiverMock.Setup(f => f.ReceiveAsync(It.IsAny <KeyboardInput>())).Returns(Task.FromResult(true));
            _receiverMock.Setup(f => f.Configuration).Returns(keyboardEventConfiguration);

            _keyboardInputFactoryMock.Setup(f => f.Create(It.IsAny <NativeKeyboardInput>())).Returns(keyboardInput);

            Action <NativeKeyboardInput> nativeInputCallback = null;

            _nativeKeyboardHookServiceMock.Setup(f => f.Hook(It.IsAny <Action <NativeKeyboardInput> >())).Callback <Action <NativeKeyboardInput> >(a => nativeInputCallback = a);

            _sut.HookKeyboard();
            var nativeKeyboardInput = new NativeKeyboardInput(Keys.Alt, NativeKeyboardInputDirection.KeyUp);

            // Act
            nativeInputCallback(nativeKeyboardInput);

            // Assert
            _receiverMock.Verify(f => f.ReceiveAsync(It.IsAny <KeyboardInput>()), Times.Never);
        }