mirror of
https://github.com/spectreconsole/examples.git
synced 2025-10-25 15:19:18 +00:00
Add CommandApp unit testing example (#2)
* Added console interactivity test * Added `Should_Render_Panel` test
This commit is contained in:
43
examples/Cli/Testing/ConsoleTests.cs
Normal file
43
examples/Cli/Testing/ConsoleTests.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user