Skip to content

What is the correct way to handle user input to IAnsiConsole when implementing unit tests? #1524

Answered by FrankRay78
wbaldoumas asked this question in Q&A
Discussion options

You must be logged in to vote

@wbaldoumas There are quite a few interactive unit tests located here, which you might find provide the pattern you are looking for: https://github.com/spectreconsole/spectre.console/tree/main/src/Tests/Spectre.Console.Tests/Unit/Prompts

Eg:

    [Fact]
    public void Should_Select_The_First_Leaf_Item()
    {
        // Given
        var console = new TestConsole();
        console.Profile.Capabilities.Interactive = true;
        console.Input.PushKey(ConsoleKey.Enter);

        // When
        var prompt = new SelectionPrompt<string>()
                .Title("Select one")
                .Mode(SelectionMode.Leaf)
                .AddChoiceGroup("Group one", "A", "B")
                .Add…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@wbaldoumas
Comment options

Answer selected by patriksvensson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants