mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add global usings (#668)
* Use global usings * Fix namespace declarations for test projects
This commit is contained in:
@ -1,131 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Spectre.Console.Testing;
|
||||
using Spectre.Verify.Extensions;
|
||||
using VerifyXunit;
|
||||
using Xunit;
|
||||
namespace Spectre.Console.Tests.Unit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
[UsesVerify]
|
||||
[ExpectationPath("Widgets/Table/Rows/Extensions")]
|
||||
public sealed class TableRowCollectionExtensionsTests
|
||||
{
|
||||
[UsesVerify]
|
||||
[ExpectationPath("Widgets/Table/Rows/Extensions")]
|
||||
public sealed class TableRowCollectionExtensionsTests
|
||||
public sealed class TheAddRowMethod
|
||||
{
|
||||
[UsesVerify]
|
||||
public sealed class TheAddRowMethod
|
||||
[Fact]
|
||||
[Expectation("Add", "Renderables")]
|
||||
public Task Should_Add_Renderables()
|
||||
{
|
||||
[Fact]
|
||||
[Expectation("Add", "Renderables")]
|
||||
public Task Should_Add_Renderables()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow(new[] { new Text("1"), new Text("1-2") });
|
||||
table.AddRow(new[] { new Text("2"), new Text("2-2") });
|
||||
table.AddRow(new[] { new Text("3"), new Text("3-2") });
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow(new[] { new Text("1"), new Text("1-2") });
|
||||
table.AddRow(new[] { new Text("2"), new Text("2-2") });
|
||||
table.AddRow(new[] { new Text("3"), new Text("3-2") });
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Add", "Strings")]
|
||||
public Task Should_Add_Strings()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow("1", "1-2");
|
||||
table.AddRow("2", "2-2");
|
||||
table.AddRow("3", "3-2");
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheInsertRowMethod
|
||||
[Fact]
|
||||
[Expectation("Add", "Strings")]
|
||||
public Task Should_Add_Strings()
|
||||
{
|
||||
[Fact]
|
||||
[Expectation("Insert", "Renderables")]
|
||||
public Task Should_Insert_Renderables()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow(new[] { new Text("1"), new Text("1-2") });
|
||||
table.AddRow(new[] { new Text("2"), new Text("2-2") });
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow("1", "1-2");
|
||||
table.AddRow("2", "2-2");
|
||||
table.AddRow("3", "3-2");
|
||||
|
||||
// When
|
||||
table.InsertRow(1, new[] { new Text("3"), new Text("3-2") });
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
console.Write(table);
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Insert", "Strings")]
|
||||
public Task Should_Insert_Strings()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow("1", "1-2");
|
||||
table.AddRow("2", "2-2");
|
||||
|
||||
// When
|
||||
table.InsertRow(1, "3", "3-2");
|
||||
|
||||
|
||||
// Then
|
||||
console.Write(table);
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheRemoveRowMethod
|
||||
{
|
||||
[Fact]
|
||||
[Expectation("Remove")]
|
||||
public Task Should_Remove_Row()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow(new[] { new Text("1"), new Text("1-2") });
|
||||
table.AddRow(new[] { new Text("2"), new Text("2-2") });
|
||||
table.AddRow(new[] { new Text("3"), new Text("3-2") });
|
||||
|
||||
// When
|
||||
table.RemoveRow(1);
|
||||
|
||||
// Then
|
||||
console.Write(table);
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheInsertRowMethod
|
||||
{
|
||||
[Fact]
|
||||
[Expectation("Insert", "Renderables")]
|
||||
public Task Should_Insert_Renderables()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow(new[] { new Text("1"), new Text("1-2") });
|
||||
table.AddRow(new[] { new Text("2"), new Text("2-2") });
|
||||
|
||||
// When
|
||||
table.InsertRow(1, new[] { new Text("3"), new Text("3-2") });
|
||||
|
||||
// Then
|
||||
console.Write(table);
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Insert", "Strings")]
|
||||
public Task Should_Insert_Strings()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow("1", "1-2");
|
||||
table.AddRow("2", "2-2");
|
||||
|
||||
// When
|
||||
table.InsertRow(1, "3", "3-2");
|
||||
|
||||
// Then
|
||||
console.Write(table);
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheRemoveRowMethod
|
||||
{
|
||||
[Fact]
|
||||
[Expectation("Remove")]
|
||||
public Task Should_Remove_Row()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddRow(new[] { new Text("1"), new Text("1-2") });
|
||||
table.AddRow(new[] { new Text("2"), new Text("2-2") });
|
||||
table.AddRow(new[] { new Text("3"), new Text("3-2") });
|
||||
|
||||
// When
|
||||
table.RemoveRow(1);
|
||||
|
||||
// Then
|
||||
console.Write(table);
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,366 +1,353 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Shouldly;
|
||||
using Spectre.Console.Testing;
|
||||
using Spectre.Verify.Extensions;
|
||||
using VerifyXunit;
|
||||
using Xunit;
|
||||
namespace Spectre.Console.Tests.Unit;
|
||||
|
||||
namespace Spectre.Console.Tests.Unit
|
||||
[ExpectationPath("Widgets/Table/Rows")]
|
||||
public sealed class TableRowCollectionTests
|
||||
{
|
||||
[ExpectationPath("Widgets/Table/Rows")]
|
||||
public sealed class TableRowCollectionTests
|
||||
[UsesVerify]
|
||||
public sealed class TheAddMethod
|
||||
{
|
||||
[UsesVerify]
|
||||
public sealed class TheAddMethod
|
||||
[Fact]
|
||||
public void Should_Throw_If_Columns_Are_Null()
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Throw_If_Columns_Are_Null()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
// Given
|
||||
var table = new Table();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.Add(null));
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.Add(null));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<ArgumentNullException>()
|
||||
.ParamName.ShouldBe("columns");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Add_Row_To_Collection()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
|
||||
// When
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// Then
|
||||
table.Rows.Count.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Return_Index_Of_Added_Row()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// When
|
||||
var result = table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Add")]
|
||||
public Task Should_Add_Item_At_Correct_Place()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
// Then
|
||||
result.ShouldBeOfType<ArgumentNullException>()
|
||||
.ParamName.ShouldBe("columns");
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheInsertMethod
|
||||
[Fact]
|
||||
public void Should_Add_Row_To_Collection()
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Throw_If_Columns_Are_Null()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.Insert(0, null));
|
||||
// When
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<ArgumentNullException>()
|
||||
.ParamName.ShouldBe("columns");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Insert_Row()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// When
|
||||
table.Rows.Insert(0, new[] { Text.Empty });
|
||||
|
||||
// Then
|
||||
table.Rows.Count.ShouldBe(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Return_Index_Of_Inserted_Row()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
|
||||
// When
|
||||
var result = table.Rows.Insert(1, new[] { new Text("3") });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Insert")]
|
||||
public Task Should_Insert_Item_At_Correct_Place()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Insert(1, new[] { new Text("3") });
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
// Then
|
||||
table.Rows.Count.ShouldBe(1);
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheRemoveMethod
|
||||
[Fact]
|
||||
public void Should_Return_Index_Of_Added_Row()
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Negative()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.RemoveAt(-1));
|
||||
// When
|
||||
var result = table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot be negative.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.RemoveAt(3));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot exceed the number of rows in the table.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Remove")]
|
||||
public Task Should_Remove_Row()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.RemoveAt(1);
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
// Then
|
||||
result.ShouldBe(1);
|
||||
}
|
||||
|
||||
public sealed class TheClearMethod
|
||||
[Fact]
|
||||
[Expectation("Add")]
|
||||
public Task Should_Add_Item_At_Correct_Place()
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Remove_All_Rows()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.Clear();
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
|
||||
// When
|
||||
var result = table.Rows.Count;
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
}
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheUpdateMethod
|
||||
{
|
||||
[Fact]
|
||||
public Task Should_Update_Row_With_String()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task Should_Update_Row_With_Renderable()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
|
||||
table.UpdateCell(2, 2, new Markup("5"));
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(5, 2, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot exceed the number of rows in the table.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Columns()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(2, 5, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table column index cannot exceed the number of rows in the table.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Row_Is_Negative()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(-1, 2, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot be negative.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Column_Is_Negative()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(2, -1, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table column index cannot be negative.");
|
||||
}
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheInsertMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Throw_If_Columns_Are_Null()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.Insert(0, null));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<ArgumentNullException>()
|
||||
.ParamName.ShouldBe("columns");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Insert_Row()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { Text.Empty });
|
||||
|
||||
// When
|
||||
table.Rows.Insert(0, new[] { Text.Empty });
|
||||
|
||||
// Then
|
||||
table.Rows.Count.ShouldBe(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Return_Index_Of_Inserted_Row()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
|
||||
// When
|
||||
var result = table.Rows.Insert(1, new[] { new Text("3") });
|
||||
|
||||
// Then
|
||||
result.ShouldBe(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Insert")]
|
||||
public Task Should_Insert_Item_At_Correct_Place()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Insert(1, new[] { new Text("3") });
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheRemoveMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Negative()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.RemoveAt(-1));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot be negative.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.Rows.RemoveAt(3));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot exceed the number of rows in the table.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Expectation("Remove")]
|
||||
public Task Should_Remove_Row()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.RemoveAt(1);
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TheClearMethod
|
||||
{
|
||||
[Fact]
|
||||
public void Should_Remove_All_Rows()
|
||||
{
|
||||
// Given
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3") });
|
||||
table.Rows.Clear();
|
||||
|
||||
// When
|
||||
var result = table.Rows.Count;
|
||||
|
||||
// Then
|
||||
result.ShouldBe(0);
|
||||
}
|
||||
}
|
||||
|
||||
[UsesVerify]
|
||||
public sealed class TheUpdateMethod
|
||||
{
|
||||
[Fact]
|
||||
public Task Should_Update_Row_With_String()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public Task Should_Update_Row_With_Renderable()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
|
||||
table.UpdateCell(2, 2, new Markup("5"));
|
||||
|
||||
// When
|
||||
console.Write(table);
|
||||
|
||||
// Then
|
||||
return Verifier.Verify(console.Output);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Rows()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(5, 2, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot exceed the number of rows in the table.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Is_Larger_Than_Number_Of_Columns()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(2, 5, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table column index cannot exceed the number of rows in the table.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Row_Is_Negative()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(-1, 2, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table row index cannot be negative.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Should_Throw_If_Index_Column_Is_Negative()
|
||||
{
|
||||
// Given
|
||||
var console = new TestConsole();
|
||||
var table = new Table();
|
||||
table.AddColumn("Column #1");
|
||||
table.AddColumn("Column #2");
|
||||
table.AddColumn("Column #3");
|
||||
table.Rows.Add(new[] { new Text("1") });
|
||||
table.Rows.Add(new[] { new Text("2") });
|
||||
table.Rows.Add(new[] { new Text("3"), new Text("4"), new Text("8") });
|
||||
table.UpdateCell(2, 2, "5");
|
||||
|
||||
// When
|
||||
var result = Record.Exception(() => table.UpdateCell(2, -1, "5"));
|
||||
|
||||
// Then
|
||||
result.ShouldBeOfType<IndexOutOfRangeException>()
|
||||
.Message.ShouldBe("Table column index cannot be negative.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user