public void ListenerHookPointerIsSetToZeroAfterUnregistering()
        {
            var listenerMock = MockRepository.GenerateMock<IHookListener>();
            var controller = new WindowsHookRegistrationController();

            controller.Unregister(listenerMock);

            listenerMock.AssertWasCalled(x => x.HookPointer = IntPtr.Zero,
                                         c => c.Repeat.Once());
        }
        public void ListenerHandlerMethodIsCalledWhenHookIsTriggered()
        {
            var listenerMock = MockRepository.GenerateMock<IHookListener>();
            listenerMock.Stub(x => x.HookId).Return((int)WindowsHooks.WH_KEYBOARD);
            var controller = new WindowsHookRegistrationController();

            controller.Register(listenerMock);

            //var virtualKeyboard = new Microsoft.VisualBasic.Devices.Keyboard();
            //virtualKeyboard.SendKeys("a");

            listenerMock.AssertWasCalled(x => x.HandleHookMessage(System.Windows.Forms.Keys.A),
                                         c => c.Repeat.Once());
        }
        public void ListenerHookPointerIsSetAfterRegistering()
        {
            var listenerMock = MockRepository.GenerateMock<IHookListener>();
            listenerMock.Stub(x => x.HookId).Return((int)WindowsHooks.WH_KEYBOARD_LL);
            var controller = new WindowsHookRegistrationController();

            controller.Register(listenerMock);

            try
            {
                listenerMock.AssertWasCalled(x => x.HookPointer = Arg<IntPtr>.Is.Anything,
                                             c => c.Repeat.Once());
            }
            catch
            {
                throw;
            }
            finally
            {
                controller.Unregister(listenerMock);
            }
        }
 public void UnregisteringNullListenerThrowsException()
 {
     var controller = new WindowsHookRegistrationController();
     Assert.Throws<ArgumentNullException>(() => controller.Unregister(null));
 }