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); }
public void HostUserInterfaceReadkey() { Mock <NuGetRawUserInterface> mockRawUI; Mock <NuGetHostUserInterface> mockUI; ConsoleDispatcher dispatcher; InteractiveHelper.InitializeConsole(out mockRawUI, out mockUI, out dispatcher); var postedKey = VsKeyInfo.Create(Key.Z, 'z', 90); dispatcher.PostKey(postedKey); // queue a cancel operation to prevent test getting "stuck" // should the following ReadKey call fail var cancelWasQueued = InteractiveHelper.TryQueueCancelWaitKey(dispatcher, TimeSpan.FromSeconds(5)); Assert.True(cancelWasQueued); KeyInfo keyInfo = mockRawUI.Object.ReadKey(); Assert.Equal(keyInfo.Character, 'z'); Assert.Equal(keyInfo.VirtualKeyCode, 90); Assert.Equal(keyInfo.ControlKeyState, default(ControlKeyStates)); }