aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.Tests/ExcelTablesTests.cs
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-03-31 15:27:31 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-03-31 15:27:31 +0300
commitf01228d94554669146137dea9614d87df22c01f3 (patch)
treed507329f02195f52dc16ec72934d2627833756b3 /RhSolutions.Tests/ExcelTablesTests.cs
parentcdb153c988f0eaa1355bf53d27280e3d6eed92a4 (diff)
Add Excel Table classes
Diffstat (limited to 'RhSolutions.Tests/ExcelTablesTests.cs')
-rw-r--r--RhSolutions.Tests/ExcelTablesTests.cs65
1 files changed, 65 insertions, 0 deletions
diff --git a/RhSolutions.Tests/ExcelTablesTests.cs b/RhSolutions.Tests/ExcelTablesTests.cs
new file mode 100644
index 0000000..3ce71bc
--- /dev/null
+++ b/RhSolutions.Tests/ExcelTablesTests.cs
@@ -0,0 +1,65 @@
+namespace RhSolutions.Tests;
+
+[ExcelTestSettings(OutOfProcess = true, Workbook = @"TestWorkbooks\ExcelTableTest.xlsx")]
+public class ExcelTablesTests : IDisposable
+{
+ ExcelTable.ExcelTable table;
+
+ public ExcelTablesTests()
+ {
+ Util.Application.Workbooks.Add();
+
+ Worksheet worksheet = Util.Workbook.Sheets[1];
+ Range range = worksheet.Range["E7:G9"];
+ table = new(range);
+ }
+
+ [ExcelFact]
+ public void CanReadExcelTable()
+ {
+ Assert.Equal(3, table.Columns.Where(c => c.Header.StartsWith("Столбец")).Count());
+ Assert.Equal("Столбец 1", table.Rows.First()[0].Value);
+ Assert.Equal("Столбец 2", table[0, 1].Value);
+ Assert.Equal(123d, table[1, 1].Value);
+ Assert.Null(table[1, 2].Value);
+ }
+
+ [ExcelFact]
+ public void CanModifyTableCells()
+ {
+ table[2, 1].Value = 1;
+ table[1, 1].Value = (double)table[1, 1].Value + 123;
+ Assert.Equal(1d, table[2, 1].Value);
+ Assert.Equal(246d, table[1, 1].Value);
+ }
+
+ [ExcelFact]
+ public void CanFindInTable()
+ {
+ table[2, 0].Value = "Find!";
+ table[2, 1].Value = "Find this!";
+ table[2, 2].Value = "Find that!";
+
+
+ var cells = table.Find("Find");
+ Assert.Collection(cells, item => Assert.Equal("Find!", item.Value),
+ item => Assert.Equal("Find this!", item.Value),
+ item => Assert.Equal("Find that!", item.Value));
+ Assert.Equal(0, table.Find("Значение").First().ParentColumn.Index);
+ Assert.Equal(3, table.Rows[2].Find("Find").Count());
+ Assert.Empty(table.Columns[1].Find("Пусто"));
+ }
+
+ [ExcelFact]
+ public void CanAddColumns()
+ {
+ int originalCount = table.Columns.Count();
+ table.Columns[1].AddLeft();
+ Assert.Equal(originalCount + 1, table.Columns.Count());
+ }
+
+ public void Dispose()
+ {
+ Util.Application.ActiveWindow.Close(SaveChanges: false);
+ }
+}