Add CommandApp unit testing example (#2)

* Added console interactivity test
* Added `Should_Render_Panel` test
This commit is contained in:
Frank Ray
2025-04-08 15:59:47 +01:00
committed by GitHub
parent a3cc9f5f72
commit b030977c0a
5 changed files with 138 additions and 2 deletions

View File

@@ -0,0 +1,43 @@
using Spectre.Console;
using Spectre.Console.Testing;
namespace Testing;
[TestClass]
public class ConsoleTests
{
[TestMethod]
public void Should_Render_Panel()
{
// Given
var console = new TestConsole();
// When
console.Write(new Panel(new Text("Hello World")));
// Then
Assert.AreEqual(console.Output, """"
Hello World
"""");
}
[TestMethod]
public void Should_Select_Orange()
{
// Given
var console = new TestConsole();
console.Input.PushTextWithEnter("Orange");
// When
console.Prompt(
new TextPrompt<string>("Favorite fruit?")
.AddChoice("Banana")
.AddChoice("Orange"));
// Then
Assert.AreEqual(console.Output, "Favorite fruit? [Banana/Orange]: Orange\n");
}
}