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 RegisteringNullListenerThrowsException()
 {
     var controller = new WindowsHookRegistrationController();
     Assert.Throws<ArgumentNullException>(() => controller.Register(null));
 }