Files
spectreconsole-examples/examples/Cli/Testing/ConsoleTests.cs
Frank Ray b030977c0a Add CommandApp unit testing example (#2)
* Added console interactivity test
* Added `Should_Render_Panel` test
2025-04-08 16:59:47 +02:00

43 lines
951 B
C#

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");
}
}