From 6853538bc7cbdb693ea77f47adbca2a3713223a7 Mon Sep 17 00:00:00 2001 From: Vladimir Pecanac Date: Fri, 13 Nov 2026 14:14:21 +0100 Subject: [PATCH] Update UsingSpectreDotConsole to .NET 11 and Spectre.Console 0.57.2 Move both projects to net11.0 and the test packages to their current releases, drop [UsesVerify], make the age prompt test exercise its validation rules, add tests for the selection prompt and for MarkupLineInterpolated, regenerate the Verify snapshots and run every demo from Program.cs with the prompt behind an interactivity check. --- .../Tests/BasicUsagesTest.cs | 13 +++++++++++- ...nReturnErrorIfValidationFails.verified.txt | 8 +++++++- .../Tests/OtherUsagesTest.cs | 20 +++++++++++++++---- .../UsingSpectreDotConsole/Tests/Tests.csproj | 16 +++++++-------- .../UsingSpectreDotConsole/Program.cs | 20 +++++++++++++++++-- .../UsingSpectreDotConsole.csproj | 6 +++--- 6 files changed, 64 insertions(+), 19 deletions(-) diff --git a/dotnet-projects/UsingSpectreDotConsole/Tests/BasicUsagesTest.cs b/dotnet-projects/UsingSpectreDotConsole/Tests/BasicUsagesTest.cs index 9d1be56282..76d344c4c2 100644 --- a/dotnet-projects/UsingSpectreDotConsole/Tests/BasicUsagesTest.cs +++ b/dotnet-projects/UsingSpectreDotConsole/Tests/BasicUsagesTest.cs @@ -1,6 +1,5 @@ namespace Tests; -[UsesVerify] public class BasicUsagesTest { private static readonly List _students = StudentsGenerator.GenerateStudents(); @@ -13,6 +12,18 @@ public void WhenFormatCharacterIsEscaped_ThenRenderTextWithSquareBrackets() console.Output.ShouldBe("[Sabrina][George]"); } + [Fact] + public void WhenUserTextContainsBrackets_ThenInterpolatedMarkupEscapesIt() + { + var nickname = "[Sabrina]"; + var console = new TestConsole(); + + Should.Throw(() => console.MarkupLine($"[blue]{nickname}[/]")); + + console.MarkupLineInterpolated($"[blue]{nickname}[/]"); + console.Output.Trim().ShouldBe("[Sabrina]"); + } + [Fact] public Task WhenJsonDataIsPassed_ThenRenderBeautifiedStudentsDataJson() { diff --git a/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.WhenPromptingStudentForAge_ThenReturnErrorIfValidationFails.verified.txt b/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.WhenPromptingStudentForAge_ThenReturnErrorIfValidationFails.verified.txt index aa8f664a4c..a47395905a 100644 --- a/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.WhenPromptingStudentForAge_ThenReturnErrorIfValidationFails.verified.txt +++ b/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.WhenPromptingStudentForAge_ThenReturnErrorIfValidationFails.verified.txt @@ -1 +1,7 @@ -How old are you? 102 +How old are you? ABC +That's not a valid age +How old are you? 5 +You must be above 10 years +How old are you? 150 +You must be younger than that +How old are you? 22 diff --git a/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.cs b/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.cs index 101efbbb99..bd87869aa1 100644 --- a/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.cs +++ b/dotnet-projects/UsingSpectreDotConsole/Tests/OtherUsagesTest.cs @@ -1,6 +1,5 @@ namespace Tests; -[UsesVerify] public class OtherUsagesTest { [Fact] @@ -16,15 +15,28 @@ public Task WhenStudentDataIsPassed_ThenRenderStudentsTable() public Task WhenPromptingStudentForAge_ThenReturnErrorIfValidationFails() { var console = new TestConsole(); - console.Input.PushTextWithEnter("102"); console.Input.PushTextWithEnter("ABC"); - console.Input.PushTextWithEnter("99"); + console.Input.PushTextWithEnter("5"); + console.Input.PushTextWithEnter("150"); console.Input.PushTextWithEnter("22"); - console.Prompt(SpectreConsoleOtherUsages.GetAgeTextPrompt()); + var age = console.Prompt(SpectreConsoleOtherUsages.GetAgeTextPrompt()); + + age.ShouldBe(22); return Verify(console.Output); + } + + [Fact] + public void WhenStudentPressesDownThenEnter_ThenSelectSecondHostel() + { + var console = new TestConsole().Interactive(); + console.Input.PushKey(ConsoleKey.DownArrow); + console.Input.PushKey(ConsoleKey.Enter); + + var hostel = console.Prompt(SpectreConsoleOtherUsages.GetHostelSelectionPrompt()); + hostel.ShouldBe("Louisa"); } [Fact] diff --git a/dotnet-projects/UsingSpectreDotConsole/Tests/Tests.csproj b/dotnet-projects/UsingSpectreDotConsole/Tests/Tests.csproj index d746bfb4ad..262622b158 100644 --- a/dotnet-projects/UsingSpectreDotConsole/Tests/Tests.csproj +++ b/dotnet-projects/UsingSpectreDotConsole/Tests/Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net11.0 enable enable @@ -10,16 +10,16 @@ - - - - - - + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/Program.cs b/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/Program.cs index b3b4feb7f5..0b7b1f70da 100644 --- a/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/Program.cs +++ b/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/Program.cs @@ -1,3 +1,19 @@ -using UsingSpectreDotConsole; +using Spectre.Console; +using UsingSpectreDotConsole; -SpectreConsoleOtherUsages.DisplayProgress(); \ No newline at end of file +SpectreConsoleBasicUsages.SetTextColor(); +SpectreConsoleBasicUsages.SetBackgroundColor(); +SpectreConsoleBasicUsages.EscapeFormatCharacters(); +SpectreConsoleBasicUsages.BeautifyStudentsDataJson(); +SpectreConsoleBasicUsages.PrettyPrintCalendar(); + +SpectreConsoleOtherUsages.CreateStudentTable(); +SpectreConsoleOtherUsages.WriteReadableException(); +SpectreConsoleOtherUsages.CreateHostelBarChart(); +SpectreConsoleOtherUsages.DisplayProgress(); +SpectreConsoleOtherUsages.DisplayFiglet(); + +if (AnsiConsole.Profile.Capabilities.Interactive) +{ + SpectreConsoleOtherUsages.PromptStudent(); +} diff --git a/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/UsingSpectreDotConsole.csproj b/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/UsingSpectreDotConsole.csproj index b0434373b2..f6f82446ac 100644 --- a/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/UsingSpectreDotConsole.csproj +++ b/dotnet-projects/UsingSpectreDotConsole/UsingSpectreDotConsole/UsingSpectreDotConsole.csproj @@ -2,14 +2,14 @@ Exe - net8.0 + net11.0 enable enable - - + +