diff --git a/test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs b/test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs deleted file mode 100644 index 819be34f0..000000000 --- a/test/PowerShellEditorServices.Test/Console/ChoicePromptHandlerTests.cs +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Extensions.Logging.Abstractions; -using Xunit; - -namespace Microsoft.PowerShell.EditorServices.Test.Console -{ - /* - public class ChoicePromptHandlerTests - { - private readonly ChoiceDetails[] Choices = - new ChoiceDetails[] - { - new ChoiceDetails("&Apple", ""), - new ChoiceDetails("Ba&nana", ""), - new ChoiceDetails("&Orange", "") - }; - - private const int DefaultChoice = 1; - - [Trait("Category", "Prompt")] - [Fact(Skip = "This test fails often and is not designed well...")] - public void ChoicePromptReturnsCorrectIdForChoice() - { - TestChoicePromptHandler choicePromptHandler = new TestChoicePromptHandler(); - Task promptTask = - choicePromptHandler.PromptForChoiceAsync( - "Test prompt", - "Message is irrelevant", - Choices, - DefaultChoice, - CancellationToken.None); - - choicePromptHandler.ReturnInputString("apple"); - - // Wait briefly for the prompt task to complete - promptTask.Wait(1000); - - Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); - Assert.Equal(0, promptTask.Result); - Assert.Equal(1, choicePromptHandler.TimesPrompted); - } - - [Trait("Category", "Prompt")] - [Fact(Skip = "Hotkeys are not exposed while VSCode ignores them")] - public void ChoicePromptReturnsCorrectIdForHotKey() - { - TestChoicePromptHandler choicePromptHandler = new TestChoicePromptHandler(); - Task promptTask = - choicePromptHandler.PromptForChoiceAsync( - "Test prompt", - "Message is irrelevant", - Choices, - DefaultChoice, - CancellationToken.None); - - // Try adding whitespace to ensure it works - choicePromptHandler.ReturnInputString(" N "); - - // Wait briefly for the prompt task to complete - promptTask.Wait(1000); - - Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); - Assert.Equal(1, promptTask.Result); - Assert.Equal(1, choicePromptHandler.TimesPrompted); - } - - [Trait("Category", "Prompt")] - [Fact] - public async Task ChoicePromptRepromptsOnInvalidInput() - { - TestChoicePromptHandler choicePromptHandler = - new TestChoicePromptHandler(); - - Task promptTask = - choicePromptHandler.PromptForChoiceAsync( - "Test prompt", - "Message is irrelevant", - Choices, - DefaultChoice, - CancellationToken.None); - - // Choice is invalid, should reprompt - choicePromptHandler.ReturnInputString("INVALID"); - - // Give time for the prompt to reappear. - await Task.Delay(1000).ConfigureAwait(false); - - Assert.Equal(TaskStatus.WaitingForActivation, promptTask.Status); - Assert.Equal(2, choicePromptHandler.TimesPrompted); - } - } - - internal class TestChoicePromptHandler : ChoicePromptHandler - { - private TaskCompletionSource linePromptTask; - - public int TimesPrompted { get; private set; } - - public TestChoicePromptHandler() : base(NullLogger.Instance) - { - } - - public void ReturnInputString(string inputString) - { - this.linePromptTask.SetResult(inputString); - } - - protected override Task ReadInputStringAsync(CancellationToken cancellationToken) - { - this.linePromptTask = new TaskCompletionSource(); - return this.linePromptTask.Task; - } - - protected override void ShowPrompt(PromptStyle promptStyle) - { - // No action needed, just count the prompts. - this.TimesPrompted++; - } - } - */ -} - diff --git a/test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs b/test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs deleted file mode 100644 index 2aadb3658..000000000 --- a/test/PowerShellEditorServices.Test/Console/InputPromptHandlerTests.cs +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System.Collections; -using System.Collections.Generic; -using System.Threading.Tasks; -using Xunit; -using System; -using System.Threading; -using System.Security; -using Microsoft.Extensions.Logging.Abstractions; - -namespace Microsoft.PowerShell.EditorServices.Test.Console -{ - // TODO: Bring these tests back when we've mocked more of the O# LSP middleware - - /* - public class InputPromptHandlerTests - { - const string NameField = "Name"; - const string NameValue = "John Doe"; - - const string AgeField = "Age"; - const int AgeValue = 67; - - const string BooksField = "Books"; - static readonly ArrayList BookItems = new ArrayList(new string[] { "Neuromancer", "Tao Te Ching" }); - - private readonly FieldDetails[] Fields = - new FieldDetails[] - { - new FieldDetails(NameField, "Name", typeof(string), false, "Default Name"), - new FieldDetails(AgeField, "Age", typeof(int), true, 30), - new CollectionFieldDetails(BooksField, "Favorite Books", typeof(IList), false, null) - }; - - [Trait("Category", "Prompt")] - [Fact] - public async Task InputPromptHandlerReturnsValuesOfCorrectType() - { - TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); - Task> promptTask = - inputPromptHandler.PromptForInputAsync( - "Test Prompt", - "Message is irrelevant", - Fields, - CancellationToken.None); - - Assert.Equal(NameField, inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString(NameValue).ConfigureAwait(false); - - Assert.Equal(AgeField, inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString(AgeValue.ToString()).ConfigureAwait(false); - - Assert.Equal(BooksField + "[0]", inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString((string)BookItems[0]).ConfigureAwait(false); - Assert.Equal(BooksField + "[1]", inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString((string)BookItems[1]).ConfigureAwait(false); - Assert.Equal(BooksField + "[2]", inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString("").ConfigureAwait(false); - - // Make sure the right results are returned - Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); - Dictionary fieldValues = promptTask.Result; - Assert.Equal(NameValue, fieldValues[NameField]); - Assert.Equal(AgeValue, fieldValues[AgeField]); - Assert.Equal(BookItems, fieldValues[BooksField]); - } - - [Trait("Category", "Prompt")] - [Fact] - public async Task InputPromptHandlerAcceptsArrayOfNonStringValues() - { - TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); - Task> promptTask = - inputPromptHandler.PromptForInputAsync( - "Test Prompt", - "Message is irrelevant", - new FieldDetails[] - { - new CollectionFieldDetails("Numbers", "Numbers", typeof(int[]), false, null) - }, - CancellationToken.None); - - Assert.Equal("Numbers[0]", inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString("1").ConfigureAwait(false); - await inputPromptHandler.ReturnInputString("").ConfigureAwait(false); - - // Make sure the right results are returned - Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); - Dictionary fieldValues = promptTask.Result; - Assert.Equal(new int[] { 1 }, fieldValues["Numbers"]); - } - - [Trait("Category", "Prompt")] - [Fact] - public async Task InputPromptRetriesWhenCannotCastValue() - { - TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); - Task> promptTask = - inputPromptHandler.PromptForInputAsync( - "Test Prompt", - "Message is irrelevant", - Fields, - CancellationToken.None); - - Assert.Equal(NameField, inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString(NameValue).ConfigureAwait(false); - - // Intentionally give a non-integer string to cause an error - Assert.Equal(AgeField, inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString(NameValue).ConfigureAwait(false); - Assert.NotNull(inputPromptHandler.LastError); - - // Give the right value the next time - Assert.Equal(AgeField, inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString(AgeValue.ToString()).ConfigureAwait(false); - - Assert.Equal(BooksField + "[0]", inputPromptHandler.LastField.Name); - await inputPromptHandler.ReturnInputString("").ConfigureAwait(false); - - // Make sure the right results are returned - Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); - Dictionary fieldValues = promptTask.Result; - Assert.Equal(AgeValue, fieldValues[AgeField]); - } - } - - internal class TestInputPromptHandler : InputPromptHandler - { - private TaskCompletionSource linePromptTask; - private TaskCompletionSource securePromptTask; - - public FieldDetails LastField { get; private set; } - - public Exception LastError { get; private set; } - - public TestInputPromptHandler() : base(NullLogger.Instance) - { - } - - public Task ReturnInputString(string inputString) - { - this.linePromptTask.SetResult(inputString); - - // TODO: refactor tests to not need this Delay. There seems to be a race condition - // in how this test cleans up after SetResult is run. - return Task.Delay(300); - } - - public void ReturnSecureString(SecureString secureString) - { - this.securePromptTask.SetResult(secureString); - } - - protected override Task ReadInputStringAsync(CancellationToken cancellationToken) - { - this.linePromptTask = new TaskCompletionSource(); - return this.linePromptTask.Task; - } - - protected override Task ReadSecureStringAsync(CancellationToken cancellationToken) - { - this.securePromptTask = new TaskCompletionSource(); - return this.securePromptTask.Task; - } - - protected override void ShowPromptMessage(string caption, string message) - { - } - - protected override void ShowFieldPrompt(FieldDetails fieldDetails) - { - this.LastField = fieldDetails; - } - - protected override void ShowErrorMessage(Exception e) - { - this.LastError = e; - } - } - */ -}