public void ReceivingHotkeyEventWithInstalledHotkeyTriggersEvent() { var fakeInterception = Substitute.For <IHotkeyInterception>(); fakeInterception.InterceptionId.Returns(1337); fakeInterception.Key.Returns(Key.B); Container.Resolve <IHotkeyInterceptionFactory>() .CreateInterception(Arg.Any <Key>(), true, false) .Returns(fakeInterception); SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.A); SystemUnderTest.Install(IntPtr.Zero); var eventFired = false; SystemUnderTest.HotkeyFired += (sender, e) => { eventFired = e.Key == Key.B; }; SystemUnderTest.ReceiveMessageEvent( new WindowMessageReceivedArgument( IntPtr.Zero, Message.WM_HOTKEY, new IntPtr(1337), IntPtr.Zero)); Assert.IsTrue(eventFired); }
public void AddInterceptingKeyCreatesInterception() { SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.A); var fakeFactory = Container.Resolve <IHotkeyInterceptionFactory>(); fakeFactory.Received() .CreateInterception(Key.A, true, false); }
public void AddInterceptingKeyWithKeyAlreadyThereDoesNotDoAnything() { SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.A); SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.B); var fakeFactory = Container.Resolve <IHotkeyInterceptionFactory>(); fakeFactory.Received(1) .CreateInterception(Key.A, true, false); }
public void AddInterceptingKeyOnInstalledInterceptorInstallsInterception() { var fakeInterception = Substitute.For <IHotkeyInterception>(); Container.Resolve <IHotkeyInterceptionFactory>() .CreateInterception(Key.A, true, false) .Returns(fakeInterception); SystemUnderTest.Install(IntPtr.Zero); SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.A); fakeInterception.Received() .Start(IntPtr.Zero); }
public void InstallStartsInterceptions() { var fakeInterception1 = Substitute.For <IHotkeyInterception>(); var fakeInterception2 = Substitute.For <IHotkeyInterception>(); Container.Resolve <IHotkeyInterceptionFactory>() .CreateInterception(Arg.Any <Key>(), true, false) .Returns(fakeInterception1, fakeInterception2); SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.A); SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.B); SystemUnderTest.Install(IntPtr.Zero); fakeInterception1.Received() .Start(IntPtr.Zero); fakeInterception2.Received() .Start(IntPtr.Zero); }
public void ReceivingWindowShownEventInstallsHotkeys() { var fakeInterception = Substitute.For <IHotkeyInterception>(); Container.Resolve <IHotkeyInterceptionFactory>() .CreateInterception(Arg.Any <Key>(), true, false) .Returns(fakeInterception); SystemUnderTest.AddInterceptingKey(IntPtr.Zero, Key.A); SystemUnderTest.ReceiveMessageEvent( new WindowMessageReceivedArgument( IntPtr.Zero, Message.WM_SHOWWINDOW, new IntPtr(1), IntPtr.Zero)); fakeInterception.Received() .Start(IntPtr.Zero); }