public void DisposeWillNotFailIfHotKeyWasAlreadyDisposed() { using (var dummyWindow = DummyWindow.Create()) { // Arrange var hotKeyModifier = HotKeyModifier.Alt | HotKeyModifier.Control | HotKeyModifier.Shift; var virtualKeyCode = (UInt32)65; // A JanHafner.Toolkit.Windows.HotKey.GlobalHotKey globalHotKey = null; using (globalHotKey = JanHafner.Toolkit.Windows.HotKey.GlobalHotKey.Register(dummyWindow.WindowHandle, hotKeyModifier, virtualKeyCode)) { } // Act, Assert globalHotKey.Invoking(ghk => ghk.Dispose()).Should().NotThrow <ObjectDisposedException>(); } }
public void UnregisterWillFailIfWindowHandleIsInvalid() { // Arrange var windowHandle = IntPtr.Zero; var hotKeyModifier = HotKeyModifier.Alt | HotKeyModifier.Control | HotKeyModifier.Shift; var virtualKeyCode = (UInt32)65; // A JanHafner.Toolkit.Windows.HotKey.GlobalHotKey globalHotKey = null; using (var dummyWindow = DummyWindow.Create()) { windowHandle = dummyWindow.WindowHandle; globalHotKey = JanHafner.Toolkit.Windows.HotKey.GlobalHotKey.Register(windowHandle, hotKeyModifier, virtualKeyCode); } globalHotKey.Invoking(ghk => ghk.Unregister()).Should().Throw <Win32Exception>(); }