diff --git a/src/TUI.Engine/Attributes/Orientations/IWithOrientation.cs b/src/TUI.Engine/Attributes/Orientations/IWithOrientation.cs index 1d6f5e9..6b379f3 100644 --- a/src/TUI.Engine/Attributes/Orientations/IWithOrientation.cs +++ b/src/TUI.Engine/Attributes/Orientations/IWithOrientation.cs @@ -5,5 +5,6 @@ public interface IWithOrientation internal Orientation Orientation { get; } public void SetOrientationHorizontal(); + public void SetOrientationVertical(); } \ No newline at end of file diff --git a/src/TUI.Engine/Helper.cs b/src/TUI.Engine/Helper.cs index 8a73f30..b63adc9 100644 --- a/src/TUI.Engine/Helper.cs +++ b/src/TUI.Engine/Helper.cs @@ -3,7 +3,7 @@ using Pastel; using TUI.Engine.Attributes; using TUI.Engine.Nodes; -[assembly:InternalsVisibleTo("TUI.Engine.Tests", AllInternalsVisible = true)] +[assembly: InternalsVisibleTo("TUI.Engine.Tests", AllInternalsVisible = true)] namespace TUI.Engine; @@ -25,7 +25,7 @@ public static class Helper public static void ShowBackground(Position position, Size size) { - // return; + return; if (!Colors.Any()) { Init(); diff --git a/tests/TUI.Engine.Tests/DrawTests/ComponentAttributeTests.cs b/tests/TUI.Engine.Tests/Components/ComponentAttributeTests.cs similarity index 88% rename from tests/TUI.Engine.Tests/DrawTests/ComponentAttributeTests.cs rename to tests/TUI.Engine.Tests/Components/ComponentAttributeTests.cs index 06501fc..33797d0 100644 --- a/tests/TUI.Engine.Tests/DrawTests/ComponentAttributeTests.cs +++ b/tests/TUI.Engine.Tests/Components/ComponentAttributeTests.cs @@ -1,13 +1,15 @@ using FluentAssertions; using TUI.Engine.Attributes.Alignments; +using TUI.Engine.Components; using TUI.Engine.Tests.Stubs; using TUI.Engine.Theme; -namespace TUI.Engine.Tests.DrawTests; +namespace TUI.Engine.Tests.Components; public class ComponentAttributeTests { [Fact] + [Trait("Category", nameof(IComponent))] public void WhenUseChainingSaveAllChange() { var logo = new TestComponent(); @@ -24,6 +26,7 @@ public class ComponentAttributeTests } [Fact] + [Trait("Category", nameof(IComponent))] public void WhenSetPaddingsSaveAllChange() { var component = new TestComponent(); @@ -37,6 +40,7 @@ public class ComponentAttributeTests } [Theory] + [Trait("Category", nameof(IComponent))] [InlineData(Vertical.Bottom)] [InlineData(Vertical.Center)] [InlineData(Vertical.Top)] @@ -50,6 +54,7 @@ public class ComponentAttributeTests } [Theory] + [Trait("Category", nameof(IComponent))] [InlineData(Horizontal.Left)] [InlineData(Horizontal.Center)] [InlineData(Horizontal.Right)] diff --git a/tests/TUI.Engine.Tests/Draw/ComponentBaseTests.cs b/tests/TUI.Engine.Tests/Draw/ComponentBaseTests.cs new file mode 100644 index 0000000..7a5dd07 --- /dev/null +++ b/tests/TUI.Engine.Tests/Draw/ComponentBaseTests.cs @@ -0,0 +1,18 @@ +using TUI.Engine.Nodes; +using TUI.Engine.Rendering; +using TUI.Engine.Rendering.Canvas; +using TUI.Engine.Tests.Stubs; + +namespace TUI.Engine.Tests.Draw; + +public class ComponentBaseTests +{ + protected readonly TestComponent Component = Prepare.Component(); + + protected IDrawable Craftsman(ICanvas canvas) + { + var componentCraftsman = new ComponentCraftsman(canvas); + var containerCraftsman = new ContainerCraftsman(componentCraftsman); + return new DrawCraftsman(componentCraftsman, containerCraftsman); + } +} \ No newline at end of file diff --git a/tests/TUI.Engine.Tests/Draw/DrawAlignmentTests.cs b/tests/TUI.Engine.Tests/Draw/DrawAlignmentTests.cs new file mode 100644 index 0000000..32354c7 --- /dev/null +++ b/tests/TUI.Engine.Tests/Draw/DrawAlignmentTests.cs @@ -0,0 +1,89 @@ +using Moq; +using TUI.Engine.Attributes; +using TUI.Engine.Attributes.Alignments; +using TUI.Engine.Nodes; +using TUI.Engine.Rendering; +using TUI.Engine.Rendering.Canvas; + +namespace TUI.Engine.Tests.Draw; + +public class DrawAlignmentTests : ComponentBaseTests +{ + [Theory] + [Trait("Category", nameof(IDrawable.Draw))] + [InlineData(Horizontal.Left, "Lorem", 10, 0)] + [InlineData(Horizontal.Center, "Lorem", 10, 2)] + [InlineData(Horizontal.Center, "Lo", 10, 4)] + [InlineData(Horizontal.Center, "Lorem", 9, 2)] + [InlineData(Horizontal.Center, "Lorem", 11, 3)] + [InlineData(Horizontal.Right, "Lorem", 10, 5)] + [InlineData(Horizontal.Right, "Lo", 10, 8)] + public void DrawWithHorizontalAlignment(Horizontal alignment, string content, int canvasSize, + int expectedPosition) + { + var canvas = Mock.Of(w => w.Size == new Size(canvasSize, canvasSize)); + Component.SetContent(content); + Component.SetAlignment(Vertical.Top); + Component.SetAlignment(alignment); + + Craftsman(canvas).Draw(Component, Position.Default, canvas.Size); + + Mock.Get(canvas).Verify(w => w.Paint(content), Times.Once()); + Mock.Get(canvas).Verify(w => w.SetPencil(new Position(expectedPosition, 0)), Times.Once()); + } + + [Theory] + [Trait("Category", nameof(IDrawable.Draw))] + [InlineData(Vertical.Top, "v", 5, new[] { 0 })] + [InlineData(Vertical.Top, "v\nv", 5, new[] { 0, 1 })] + [InlineData(Vertical.Top, "v\nv\nv", 5, new[] { 0, 1, 2 })] + [InlineData(Vertical.Center, "v", 1, new[] { 0 })] + [InlineData(Vertical.Center, "v", 4, new[] { 1 })] + [InlineData(Vertical.Center, "v", 5, new[] { 2 })] + [InlineData(Vertical.Center, "v", 6, new[] { 2 })] + [InlineData(Vertical.Center, "v\nv", 4, new[] { 1, 2 })] + [InlineData(Vertical.Center, "v\nv", 5, new[] { 1, 2 })] + [InlineData(Vertical.Center, "v\nv", 6, new[] { 2, 3 })] + [InlineData(Vertical.Bottom, "v", 5, new[] { 4 })] + [InlineData(Vertical.Bottom, "v\nv", 2, new[] { 0, 1 })] + [InlineData(Vertical.Bottom, "v\nv", 3, new[] { 1, 2 })] + [InlineData(Vertical.Bottom, "v\nv\nv\nv", 5, new[] { 1, 2, 3, 4 })] + public void DrawWithVerticalAlignment(Vertical alignment, string content, int canvasSize, int[] expectedPositions) + { + var canvas = Mock.Of(w => w.Size == new Size(canvasSize, canvasSize)); + Component.SetContent(content); + Component.SetAlignment(Horizontal.Left); + Component.SetAlignment(alignment); + + Craftsman(canvas).Draw(Component, Position.Default, canvas.Size); + + foreach (var expectedPencilPosition in expectedPositions) + { + Mock.Get(canvas).VerifyPositionOnce(0, expectedPencilPosition); + } + } + + [Theory] + [Trait("Category", nameof(IDrawable.Draw))] + [InlineData(Horizontal.Left, Vertical.Top, 0, 0)] + [InlineData(Horizontal.Left, Vertical.Center, 0, 2)] + [InlineData(Horizontal.Left, Vertical.Bottom, 0, 4)] + [InlineData(Horizontal.Center, Vertical.Top, 2, 0)] + [InlineData(Horizontal.Center, Vertical.Center, 2, 2)] + [InlineData(Horizontal.Center, Vertical.Bottom, 2, 4)] + [InlineData(Horizontal.Right, Vertical.Top, 4, 0)] + [InlineData(Horizontal.Right, Vertical.Center, 4, 2)] + [InlineData(Horizontal.Right, Vertical.Bottom, 4, 4)] + public void DrawWithAlignment(Horizontal horizontal, Vertical vertical, int expectedLeft, + int expectedTop) + { + var canvas = Mock.Of(w => w.Size == new Size(6, 5)); + Component.SetContent("VV"); + Component.SetAlignment(horizontal); + Component.SetAlignment(vertical); + + Craftsman(canvas).Draw(Component, Position.Default, canvas.Size); + + Mock.Get(canvas).VerifyPositionOnce(expectedLeft, expectedTop); + } +} \ No newline at end of file diff --git a/tests/TUI.Engine.Tests/Draw/DrawOverloadTests.cs b/tests/TUI.Engine.Tests/Draw/DrawOverloadTests.cs new file mode 100644 index 0000000..6ea8d0f --- /dev/null +++ b/tests/TUI.Engine.Tests/Draw/DrawOverloadTests.cs @@ -0,0 +1,46 @@ +using Moq; +using TUI.Engine.Attributes; +using TUI.Engine.Nodes; +using TUI.Engine.Rendering; +using TUI.Engine.Rendering.Canvas; +using TUI.Engine.Tests.Stubs; + +namespace TUI.Engine.Tests.Draw; + +public class DrawOverloadTests : ComponentBaseTests +{ + [Fact] + [Trait("Category", nameof(IDrawable.Draw))] + public void DrawWithOverloadHorizontal() + { + var canvas = Mock.Of(w => w.Size == new Size(9, 1)); + var root = Prepare.Container(Component, Component); + root.SetOrientationHorizontal(); + + Craftsman(canvas).Draw(root, Position.Default, canvas.Size); + + Mock.Get(canvas).VerifyPositionOnce(Position.Default); + Mock.Get(canvas).VerifyPositionOnce(4, 0); + Mock.Get(canvas).Verify(w => w.Paint("Lore"), Times.Exactly(2)); + } + + [Theory] + [InlineData(4, 4, new[] { 0, 1, 2, 3 })] + [Trait("Category", nameof(IDrawable.Draw))] + public void DrawWithOverloadVertical(int rootWidth, int rootHeight, int[] expectedTopPositions) + { + var canvas = Mock.Of(w => w.Size == new Size(rootWidth, rootHeight)); + Component.SetContent("Lorem\nLorem\nLorem"); + var root = Prepare.Container(Component, Component); + root.SetOrientationVertical(); + + Craftsman(canvas).Draw(root, Position.Default, canvas.Size); + + foreach (var expectedTopPosition in expectedTopPositions) + { + Mock.Get(canvas).VerifyPositionOnce(0, expectedTopPosition); + } + + Mock.Get(canvas).Verify(w => w.Paint("Lore"), Times.Exactly(rootHeight)); + } +} \ No newline at end of file diff --git a/tests/TUI.Engine.Tests/DrawTests/DrawResizingTests.cs b/tests/TUI.Engine.Tests/Draw/DrawResizingTests.cs similarity index 77% rename from tests/TUI.Engine.Tests/DrawTests/DrawResizingTests.cs rename to tests/TUI.Engine.Tests/Draw/DrawResizingTests.cs index fbe3438..3505af5 100644 --- a/tests/TUI.Engine.Tests/DrawTests/DrawResizingTests.cs +++ b/tests/TUI.Engine.Tests/Draw/DrawResizingTests.cs @@ -6,35 +6,31 @@ using TUI.Engine.Rendering; using TUI.Engine.Rendering.Canvas; using TUI.Engine.Tests.Stubs; -namespace TUI.Engine.Tests.DrawTests; +namespace TUI.Engine.Tests.Draw; -public class DrawResizingTests +public class DrawResizingTests : ComponentBaseTests { - private readonly ICanvas _canvas; private readonly TestContainer _container; - private readonly ContainerCraftsman _craftsman; private readonly TestContainer _root; + private readonly ICanvas _canvas; public DrawResizingTests() { var component = Prepare.Component(); _canvas = Mock.Of(w => w.Size == new Size(20, 2)); _container = Prepare.Container(component); - _root = Prepare.Container(_container, component); _root.SetOrientationHorizontal(); - - var componentCraftsman = new ComponentCraftsman(_canvas); - _craftsman = new ContainerCraftsman(componentCraftsman); } [Fact] + [Trait("Category", nameof(IDrawable.Draw))] public void DrawResizingFixedContainer() { _container.SetFixed(Orientation.Horizontal, 6); _container.SetFixed(Orientation.Vertical, 2); - _craftsman.Draw(_root, Position.Default, _canvas.Size); + Craftsman(_canvas).Draw(_root, Position.Default, _canvas.Size); Mock.Get(_canvas).VerifyPositionOnce(Position.Default); Mock.Get(_canvas).VerifyPositionOnce(6, 0); @@ -42,11 +38,12 @@ public class DrawResizingTests } [Fact] + [Trait("Category", nameof(IDrawable.Draw))] public void DrawResizingAdaptiveContainer() { _container.SetAdaptive(Orientation.Horizontal); - _craftsman.Draw(_root, Position.Default, _canvas.Size); + Craftsman(_canvas).Draw(_root, Position.Default, _canvas.Size); Mock.Get(_canvas).VerifyPositionOnce(Position.Default); Mock.Get(_canvas).VerifyPositionOnce(10, 0); diff --git a/tests/TUI.Engine.Tests/Draw/DrawTests.cs b/tests/TUI.Engine.Tests/Draw/DrawTests.cs new file mode 100644 index 0000000..7734af2 --- /dev/null +++ b/tests/TUI.Engine.Tests/Draw/DrawTests.cs @@ -0,0 +1,87 @@ +using Moq; +using TUI.Engine.Attributes; +using TUI.Engine.Attributes.Orientations; +using TUI.Engine.Nodes; +using TUI.Engine.Rendering; +using TUI.Engine.Rendering.Canvas; +using TUI.Engine.Tests.Stubs; + +namespace TUI.Engine.Tests.Draw; + +public class DrawCraftsmanTests : ComponentBaseTests +{ + [Fact] + [Trait("Category", nameof(IDrawable.Draw))] + public void DrawSimple() + { + var canvas = Mock.Of(w => w.Size == new Size(9, 1)); + + Craftsman(canvas).Draw(Component, Position.Default, canvas.Size); + + Mock.Get(canvas).Verify(w => w.SetPencil(Position.Default), Times.Once()); + Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Once()); + } + + [Fact] + [Trait("Category", nameof(IDrawable.Draw))] + public void DrawVerticalWithDoubleComponent() + { + var canvas = Mock.Of(w => w.Size == new Size(10, 2)); + var root = Prepare.Container(Component, Component); + root.SetOrientationVertical(); + + Craftsman(canvas).Draw(root, Position.Default, canvas.Size); + + Mock.Get(canvas).VerifyPositionOnce(Position.Default); + Mock.Get(canvas).VerifyPositionOnce(0, 1); + Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(2)); + } + + [Fact] + [Trait("Category", nameof(IDrawable.Draw))] + public void DrawHorizontalWithDoubleComponent() + { + var canvas = Mock.Of(w => w.Size == new Size(10, 1)); + var container = Prepare.Container(Component, Component); + container.SetOrientationHorizontal(); + + Craftsman(canvas).Draw(container, Position.Default, canvas.Size); + + Mock.Get(canvas).VerifyPositionOnce(Position.Default); + Mock.Get(canvas).VerifyPositionOnce(5, 0); + Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(2)); + } + + [Fact] + [Trait("Category", nameof(IDrawable.Draw))] + public void DrawWithMultipleComponent() + { + var canvas = Mock.Of(w => w.Size == new Size(24, 1)); + var root = Prepare.Container(Component, Component, Component, Component); + + Craftsman(canvas).Draw(root, Position.Default, canvas.Size); + + Mock.Get(canvas).VerifyPositionOnce(Position.Default); + Mock.Get(canvas).VerifyPositionOnce(6, 0); + Mock.Get(canvas).VerifyPositionOnce(12, 0); + Mock.Get(canvas).VerifyPositionOnce(18, 0); + Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(4)); + } + + [Fact] + [Trait("Category", nameof(IDrawable.Draw))] + public void DrawWithContainerAndComponent() + { + var canvas = Mock.Of(w => w.Size == new Size(10, 2)); + var container = Prepare.Container(Component); + var root = Prepare.Container(container, Component); + root.SetAdaptive(Orientation.Vertical); + root.SetOrientationVertical(); + + Craftsman(canvas).Draw(root, Position.Default, canvas.Size); + + Mock.Get(canvas).VerifyPositionOnce(Position.Default); + Mock.Get(canvas).VerifyPositionOnce(0, 1); + Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(2)); + } +} \ No newline at end of file diff --git a/tests/TUI.Engine.Tests/DrawTests/DrawTests.cs b/tests/TUI.Engine.Tests/DrawTests/DrawTests.cs deleted file mode 100644 index 0ccd630..0000000 --- a/tests/TUI.Engine.Tests/DrawTests/DrawTests.cs +++ /dev/null @@ -1,218 +0,0 @@ -using Moq; -using TUI.Engine.Attributes; -using TUI.Engine.Attributes.Alignments; -using TUI.Engine.Attributes.Orientations; -using TUI.Engine.Containers; -using TUI.Engine.Nodes; -using TUI.Engine.Rendering; -using TUI.Engine.Rendering.Canvas; -using TUI.Engine.Tests.Stubs; - -namespace TUI.Engine.Tests.DrawTests; - -public class DrawCraftsmanTests -{ - public TestComponent _component; - - public DrawCraftsmanTests() - { - _component = Prepare.Component(); - } - - [Fact] - public void DrawSimple() - { - var canvas = Mock.Of(w => w.Size == new Size(9, 1)); - - var componentCraftsman = new ComponentCraftsman(canvas); - componentCraftsman.Draw(_component, Position.Default, canvas.Size); - - Mock.Get(canvas).Verify(w => w.SetPencil(Position.Default), Times.Once()); - Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Once()); - } - - [Theory] - [InlineData(Horizontal.Left, "Lorem", 10, 0)] - [InlineData(Horizontal.Center, "Lorem", 10, 2)] - [InlineData(Horizontal.Center, "Lo", 10, 4)] - [InlineData(Horizontal.Center, "Lorem", 9, 2)] - [InlineData(Horizontal.Center, "Lorem", 11, 3)] - [InlineData(Horizontal.Right, "Lorem", 10, 5)] - [InlineData(Horizontal.Right, "Lo", 10, 8)] - public void DrawWithHorizontalAlignment(Horizontal alignment, string content, int canvasSize, - int expectedPosition) - { - var canvas = Mock.Of(w => w.Size == new Size(canvasSize, canvasSize)); - var component = Prepare.Component(); - component.SetContent(content); - component.SetAlignment(Vertical.Top); - component.SetAlignment(alignment); - - var componentCraftsman = new ComponentCraftsman(canvas); - componentCraftsman.Draw(component, Position.Default, canvas.Size); - - Mock.Get(canvas).Verify(w => w.Paint(content), Times.Once()); - Mock.Get(canvas).Verify(w => w.SetPencil(new Position(expectedPosition, 0)), Times.Once()); - } - - [Theory] - [InlineData(Vertical.Top, "v", 5, new[] { 0 })] - [InlineData(Vertical.Top, "v\nv", 5, new[] { 0, 1 })] - [InlineData(Vertical.Top, "v\nv\nv", 5, new[] { 0, 1, 2 })] - [InlineData(Vertical.Center, "v", 1, new[] { 0 })] - [InlineData(Vertical.Center, "v", 4, new[] { 1 })] - [InlineData(Vertical.Center, "v", 5, new[] { 2 })] - [InlineData(Vertical.Center, "v", 6, new[] { 2 })] - [InlineData(Vertical.Center, "v\nv", 4, new[] { 1, 2 })] - [InlineData(Vertical.Center, "v\nv", 5, new[] { 1, 2 })] - [InlineData(Vertical.Center, "v\nv", 6, new[] { 2, 3 })] - [InlineData(Vertical.Bottom, "v", 5, new[] { 4 })] - [InlineData(Vertical.Bottom, "v\nv", 2, new[] { 0, 1 })] - [InlineData(Vertical.Bottom, "v\nv", 3, new[] { 1, 2 })] - [InlineData(Vertical.Bottom, "v\nv\nv\nv", 5, new[] { 1, 2, 3, 4 })] - public void DrawWithVerticalAlignment(Vertical alignment, string content, int canvasSize, int[] expectedPositions) - { - var canvas = Mock.Of(w => w.Size == new Size(canvasSize, canvasSize)); - _component.SetContent(content); - _component.SetAlignment(Horizontal.Left); - _component.SetAlignment(alignment); - - var componentCraftsman = new ComponentCraftsman(canvas); - componentCraftsman.Draw(_component, Position.Default, canvas.Size); - - foreach (var expectedPencilPosition in expectedPositions) - { - Mock.Get(canvas).VerifyPositionOnce(0, expectedPencilPosition); - } - } - - [Theory] - [InlineData(Horizontal.Left, Vertical.Top, 0, 0)] - [InlineData(Horizontal.Left, Vertical.Center, 0, 2)] - [InlineData(Horizontal.Left, Vertical.Bottom, 0, 4)] - [InlineData(Horizontal.Center, Vertical.Top, 2, 0)] - [InlineData(Horizontal.Center, Vertical.Center, 2, 2)] - [InlineData(Horizontal.Center, Vertical.Bottom, 2, 4)] - [InlineData(Horizontal.Right, Vertical.Top, 4, 0)] - [InlineData(Horizontal.Right, Vertical.Center, 4, 2)] - [InlineData(Horizontal.Right, Vertical.Bottom, 4, 4)] - public void DrawWithAlignment(Horizontal horizontal, Vertical vertical, int expectedLeft, - int expectedTop) - { - var canvas = Mock.Of(w => w.Size == new Size(6, 5)); - _component.SetContent("VV"); - _component.SetAlignment(horizontal); - _component.SetAlignment(vertical); - - var componentCraftsman = new ComponentCraftsman(canvas); - componentCraftsman.Draw(_component, Position.Default, canvas.Size); - - Mock.Get(canvas).VerifyPositionOnce(expectedLeft, expectedTop); - } - - [Theory] - [InlineData(Orientation.Horizontal, 9, 1)] - public void DrawWithOverloadHorizontal(Orientation orientation, int rootWidth, int rootHeight) - { - var canvas = Mock.Of(w => w.Size == new Size(rootWidth, rootHeight)); - var root = Prepare.Container(_component, _component); - root.SetOrientationHorizontal(); - - var componentCraftsman = new ComponentCraftsman(canvas); - var containerCraftsman = new ContainerCraftsman(componentCraftsman); - containerCraftsman.Draw(root, Position.Default, canvas.Size); - - Mock.Get(canvas).VerifyPositionOnce(Position.Default); - Mock.Get(canvas).VerifyPositionOnce(4, 0); - Mock.Get(canvas).Verify(w => w.Paint("Lore"), Times.Exactly(2)); - } - - - [Theory] - [InlineData(4, 4, new[] { 0, 1, 2, 3 })] - public void DrawWithOverloadVertical(int rootWidth, int rootHeight, int[] expectedTopPositions) - { - var canvas = Mock.Of(w => w.Size == new Size(rootWidth, rootHeight)); - _component.SetContent("Lorem\nLorem\nLorem"); - var root = Prepare.Container(_component, _component); - root.SetOrientationVertical(); - - var componentCraftsman = new ComponentCraftsman(canvas); - var containerCraftsman = new ContainerCraftsman(componentCraftsman); - containerCraftsman.Draw(root, Position.Default, canvas.Size); - - foreach (var expectedTopPosition in expectedTopPositions) - { - Mock.Get(canvas).VerifyPositionOnce(0, expectedTopPosition); - } - - Mock.Get(canvas).Verify(w => w.Paint("Lore"), Times.Exactly(rootHeight)); - } - - [Fact] - public void DrawVerticalWithDoubleComponent() - { - var canvas = Mock.Of(w => w.Size == new Size(10, 2)); - var root = Prepare.Container(_component, _component); - root.SetOrientationVertical(); - - var componentCraftsman = new ComponentCraftsman(canvas); - var containerCraftsman = new ContainerCraftsman(componentCraftsman); - new DrawCraftsman(componentCraftsman, containerCraftsman).Draw(root, Position.Default, canvas.Size); - - Mock.Get(canvas).VerifyPositionOnce(Position.Default); - Mock.Get(canvas).VerifyPositionOnce(0, 1); - Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(2)); - } - - [Fact] - public void DrawHorizontalWithDoubleComponent() - { - var canvas = Mock.Of(w => w.Size == new Size(10, 1)); - var nodes = new Nodes.Nodes { _component, _component }; - var container = Mock.Of(g => g.GetNodes() == nodes); - - var componentCraftsman = new ComponentCraftsman(canvas); - var containerCraftsman = new ContainerCraftsman(componentCraftsman); - new DrawCraftsman(componentCraftsman, containerCraftsman).Draw(container, Position.Default, canvas.Size); - - Mock.Get(canvas).VerifyPositionOnce(Position.Default); - Mock.Get(canvas).VerifyPositionOnce(5, 0); - Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(2)); - } - - [Fact] - public void DrawWithMultipleComponent() - { - var canvas = Mock.Of(w => w.Size == new Size(24, 1)); - var root = Prepare.Container(_component, _component, _component, _component); - - var componentCraftsman = new ComponentCraftsman(canvas); - var containerCraftsman = new ContainerCraftsman(componentCraftsman); - containerCraftsman.Draw(root, Position.Default, canvas.Size); - - Mock.Get(canvas).VerifyPositionOnce(Position.Default); - Mock.Get(canvas).VerifyPositionOnce(6, 0); - Mock.Get(canvas).VerifyPositionOnce(12, 0); - Mock.Get(canvas).VerifyPositionOnce(18, 0); - Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(4)); - } - - [Fact] - public void DrawWithContainerAndComponent() - { - var canvas = Mock.Of(w => w.Size == new Size(10, 2)); - var container = Prepare.Container(_component); - var root = Prepare.Container(container, _component); - root.SetAdaptive(Orientation.Vertical); - root.SetOrientationVertical(); - - var componentCraftsman = new ComponentCraftsman(canvas); - var containerCraftsman = new ContainerCraftsman(componentCraftsman); - containerCraftsman.Draw(root, Position.Default, canvas.Size); - - Mock.Get(canvas).VerifyPositionOnce(Position.Default); - Mock.Get(canvas).VerifyPositionOnce(0, 1); - Mock.Get(canvas).Verify(w => w.Paint("Lorem"), Times.Exactly(2)); - } -} \ No newline at end of file diff --git a/tests/TUI.Engine.Tests/DrawTests/IntegerTests.cs b/tests/TUI.Engine.Tests/Primitives/IntegerTests.cs similarity index 82% rename from tests/TUI.Engine.Tests/DrawTests/IntegerTests.cs rename to tests/TUI.Engine.Tests/Primitives/IntegerTests.cs index f2f7608..ed6d113 100644 --- a/tests/TUI.Engine.Tests/DrawTests/IntegerTests.cs +++ b/tests/TUI.Engine.Tests/Primitives/IntegerTests.cs @@ -1,10 +1,11 @@ using FluentAssertions; -namespace TUI.Engine.Tests.DrawTests; +namespace TUI.Engine.Tests.Draw; public class IntegerTests { [Theory] + [Trait("Category", "Primitives")] [InlineData(5, 10, 5)] [InlineData(5, 5, 5)] [InlineData(5, 3, 3)] @@ -15,6 +16,7 @@ public class IntegerTests } [Theory] + [Trait("Category", "Primitives")] [InlineData(5, 10, 10)] [InlineData(5, 5, 5)] [InlineData(5, 3, 5)] diff --git a/tests/TUI.Engine.Tests/Stubs/TestContainer.cs b/tests/TUI.Engine.Tests/Stubs/TestContainer.cs index f34d65b..07d8d20 100644 --- a/tests/TUI.Engine.Tests/Stubs/TestContainer.cs +++ b/tests/TUI.Engine.Tests/Stubs/TestContainer.cs @@ -5,7 +5,7 @@ namespace TUI.Engine.Tests.Stubs; public class TestContainer : ContainerBase { - private Nodes.Nodes _nodes = new(); + private readonly Nodes.Nodes _nodes = new(); public override Nodes.Nodes GetNodes() {