public void InputPromptRetriesWhenCannotCastValue() { TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); Task <Dictionary <string, object> > promptTask = inputPromptHandler.PromptForInput( "Test Prompt", "Message is irrelevant", Fields, CancellationToken.None); Assert.Equal(NameField, inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString(NameValue); // Intentionally give a non-integer string to cause an error Assert.Equal(AgeField, inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString(NameValue); Assert.NotNull(inputPromptHandler.LastError); // Give the right value the next time Assert.Equal(AgeField, inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString(AgeValue.ToString()); Assert.Equal(BooksField + "[0]", inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString(""); // Make sure the right results are returned Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); Dictionary <string, object> fieldValues = promptTask.Result; Assert.Equal(AgeValue, fieldValues[AgeField]); }
public void InputPromptHandlerReturnsValuesOfCorrectType() { TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); Task <Dictionary <string, object> > promptTask = inputPromptHandler.PromptForInput( "Test Prompt", "Message is irrelevant", Fields, CancellationToken.None); Assert.Equal(NameField, inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString(NameValue); Assert.Equal(AgeField, inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString(AgeValue.ToString()); Assert.Equal(BooksField + "[0]", inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString((string)BookItems[0]); Assert.Equal(BooksField + "[1]", inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString((string)BookItems[1]); Assert.Equal(BooksField + "[2]", inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString(""); // Make sure the right results are returned Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); Dictionary <string, object> fieldValues = promptTask.Result; Assert.Equal(NameValue, fieldValues[NameField]); Assert.Equal(AgeValue, fieldValues[AgeField]); Assert.Equal(BookItems, fieldValues[BooksField]); }
public void InputPromptHandlerReturnsValuesOfCorrectType() { TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); Task<Dictionary<string, object>> promptTask = inputPromptHandler.PromptForInput( "Test Prompt", "Message is irrelevant", Fields, CancellationToken.None); Assert.Equal(NameField, inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse(NameValue); Assert.Equal(AgeField, inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse(AgeValue.ToString()); Assert.Equal(BooksField + "[0]", inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse((string)BookItems[0]); Assert.Equal(BooksField + "[1]", inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse((string)BookItems[1]); Assert.Equal(BooksField + "[2]", inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse(""); // Make sure the right results are returned Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); Dictionary<string, object> fieldValues = promptTask.Result; Assert.Equal(NameValue, fieldValues[NameField]); Assert.Equal(AgeValue, fieldValues[AgeField]); Assert.Equal(BookItems, fieldValues[BooksField]); }
public void InputPromptHandlerAcceptsArrayOfNonStringValues() { TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); Task<Dictionary<string, object>> promptTask = inputPromptHandler.PromptForInput( "Test Prompt", "Message is irrelevant", new FieldDetails[] { new FieldDetails("Numbers", "Numbers", typeof(int[]), false, null) }, CancellationToken.None); Assert.Equal("Numbers[0]", inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse("1"); inputPromptHandler.HandleResponse(""); // Make sure the right results are returned Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); Dictionary<string, object> fieldValues = promptTask.Result; Assert.Equal(new int[] { 1 }, fieldValues["Numbers"]); }
public void InputPromptHandlerAcceptsArrayOfNonStringValues() { TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); Task <Dictionary <string, object> > promptTask = inputPromptHandler.PromptForInput( "Test Prompt", "Message is irrelevant", new FieldDetails[] { new CollectionFieldDetails("Numbers", "Numbers", typeof(int[]), false, null) }, CancellationToken.None); Assert.Equal("Numbers[0]", inputPromptHandler.LastField.Name); inputPromptHandler.ReturnInputString("1"); inputPromptHandler.ReturnInputString(""); // Make sure the right results are returned Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); Dictionary <string, object> fieldValues = promptTask.Result; Assert.Equal(new int[] { 1 }, fieldValues["Numbers"]); }
public void InputPromptRetriesWhenCannotCastValue() { TestInputPromptHandler inputPromptHandler = new TestInputPromptHandler(); Task<Dictionary<string, object>> promptTask = inputPromptHandler.PromptForInput( "Test Prompt", "Message is irrelevant", Fields, CancellationToken.None); Assert.Equal(NameField, inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse(NameValue); // Intentionally give a non-integer string to cause an error Assert.Equal(AgeField, inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse(NameValue); Assert.NotNull(inputPromptHandler.LastError); // Give the right value the next time Assert.Equal(AgeField, inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse(AgeValue.ToString()); Assert.Equal(BooksField + "[0]", inputPromptHandler.LastField.Name); inputPromptHandler.HandleResponse(""); // Make sure the right results are returned Assert.Equal(TaskStatus.RanToCompletion, promptTask.Status); Dictionary<string, object> fieldValues = promptTask.Result; Assert.Equal(AgeValue, fieldValues[AgeField]); }