Files
spectre.console/src/Spectre.Console.Tests/Unit/RenderHookTests.cs
2020-12-04 07:29:48 +01:00

35 lines
936 B
C#

using System.Collections.Generic;
using System.Linq;
using Shouldly;
using Spectre.Console.Rendering;
using Xunit;
namespace Spectre.Console.Tests.Unit
{
public sealed class RenderHookTests
{
private sealed class HelloRenderHook : IRenderHook
{
public IEnumerable<IRenderable> Process(RenderContext context, IEnumerable<IRenderable> renderables)
{
return new IRenderable[] { new Text("Hello\n") }.Concat(renderables);
}
}
[Fact]
public void Should_Inject_Renderable_Before_Writing_To_Console()
{
// Given
var console = new PlainConsole();
console.Pipeline.Attach(new HelloRenderHook());
// When
console.Render(new Text("World"));
// Then
console.Lines[0].ShouldBe("Hello");
console.Lines[1].ShouldBe("World");
}
}
}