public void SimplePostKeyWaitKey() { var privateWpfConsole = new Mock <IPrivateWpfConsole>(); var dispatcher = new ConsoleDispatcher(privateWpfConsole.Object); var postedKey = VsKeyInfo.Create(Key.Z, 'z', 0); dispatcher.PostKey(postedKey); // test key available Assert.True(dispatcher.IsKeyAvailable); // queue a cancel operation to prevent test getting "stuck" // should the following WaitKey call fail bool cancelWasQueued = InteractiveHelper.TryQueueCancelWaitKey(dispatcher, timeout: TimeSpan.FromSeconds(5)); Assert.True(cancelWasQueued); // blocking VsKeyInfo keyInfo = dispatcher.WaitKey(); Assert.Equal(keyInfo, postedKey); // queue should be empty Assert.False(dispatcher.IsKeyAvailable); }
internal static void PostKeys(ConsoleDispatcher dispatcher, string line, bool appendCarriageReturn = false, TimeSpan timeout = default(TimeSpan)) { IntPtr pKeybLayout = NativeMethods.GetKeyboardLayout(0); foreach (char keyChar in line) { short keyScan = NativeMethods.VkKeyScanEx(keyChar, pKeybLayout); byte virtualKey = (byte)(keyScan & 0x00ff); VsKeyInfo keyInfo = VsKeyInfo.Create( KeyInterop.KeyFromVirtualKey(virtualKey), keyChar, virtualKey); dispatcher.PostKey(keyInfo); } if (appendCarriageReturn) { dispatcher.PostKey(VsKeyInfo.Enter); } // queue a cancel operation to prevent test getting "stuck" if (timeout != TimeSpan.Zero) { var cancelWasQueued = TryQueueCancelWaitKey(dispatcher, timeout); Assert.True(cancelWasQueued); } }
internal static NuGetPSHost InitializeConsole( out Mock<NuGetRawUserInterface> mockRawUI, out Mock<NuGetHostUserInterface> mockUI, out ConsoleDispatcher dispatcher) { var console = new Mock<IConsole>(); console.Setup(o => o.Write("text")); console.Setup(o => o.Write("text", null, null)); var privateWpfConsole = new Mock<IPrivateWpfConsole>(); dispatcher = new ConsoleDispatcher(privateWpfConsole.Object); console.SetupGet(o => o.Dispatcher).Returns(dispatcher); var host = new NuGetPSHost("Test") { ActiveConsole = console.Object }; mockRawUI = new Mock<NuGetRawUserInterface>(host); mockRawUI.CallBase = true; mockUI = new Mock<NuGetHostUserInterface>(host); mockUI.CallBase = true; mockUI.SetupGet(o => o.RawUI).Returns(mockRawUI.Object); return host; }
internal static NuGetPSHost InitializeConsole( out Mock <NuGetRawUserInterface> mockRawUI, out Mock <NuGetHostUserInterface> mockUI, out ConsoleDispatcher dispatcher) { var console = new Mock <IConsole>(); console.Setup(o => o.Write("text")); console.Setup(o => o.Write("text", null, null)); var privateWpfConsole = new Mock <IPrivateWpfConsole>(); dispatcher = new ConsoleDispatcher(privateWpfConsole.Object); console.SetupGet(o => o.Dispatcher).Returns(dispatcher); var host = new NuGetPSHost("Test") { ActiveConsole = console.Object }; mockRawUI = new Mock <NuGetRawUserInterface>(host); mockRawUI.CallBase = true; mockUI = new Mock <NuGetHostUserInterface>(host); mockUI.CallBase = true; mockUI.SetupGet(o => o.RawUI).Returns(mockRawUI.Object); return(host); }
public ControlConsole() { InitializeComponent(); dispatcher = new ConsoleDispatcher(); dispatcher.Suspend = false;//This and everything else is from the old ConsoleWorkstation tcpIpConsole1.Dispatcher = dispatcher; tcpIpConsole1.SendTcpipCommand += new StringDelegate(tcpIpConsole1_SendTcpipCommand); messageCenter1.OnMessageChanged += new MessageCenter.OnMessageChangedHandler(messageCenter1_OnMessageChanged); }
internal static bool TryQueueCancelWaitKey(ConsoleDispatcher dispatcher, TimeSpan timeout) { bool cancelWasQueued = ThreadPool.QueueUserWorkItem( state => { Thread.Sleep(timeout); dispatcher.CancelWaitKey(); }); return cancelWasQueued; }
internal static bool TryQueueCancelWaitKey(ConsoleDispatcher dispatcher, TimeSpan timeout) { bool cancelWasQueued = ThreadPool.QueueUserWorkItem( state => { Thread.Sleep(timeout); dispatcher.CancelWaitKey(); }); return(cancelWasQueued); }
public void SimplePostKeyWaitKey() { var privateWpfConsole = new Mock<IPrivateWpfConsole>(); var dispatcher = new ConsoleDispatcher(privateWpfConsole.Object); var postedKey = VsKeyInfo.Create(Key.Z, 'z', 0); dispatcher.PostKey(postedKey); // test key available Assert.True(dispatcher.IsKeyAvailable); // queue a cancel operation to prevent test getting "stuck" // should the following WaitKey call fail bool cancelWasQueued = InteractiveHelper.TryQueueCancelWaitKey(dispatcher, timeout: TimeSpan.FromSeconds(5)); Assert.True(cancelWasQueued); // blocking VsKeyInfo keyInfo = dispatcher.WaitKey(); Assert.Equal(keyInfo, postedKey); // queue should be empty Assert.False(dispatcher.IsKeyAvailable); }