From 6497738c2d7bf597b92fac2793a061a13e1b102d Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Thu, 23 Mar 2023 07:08:30 +0300 Subject: [PATCH] Add Test template --- RhSolutions.Tests/CalculationTests.cs | 30 +++++++++++++++++++ RhSolutions.Tests/Tests.cs | 38 ------------------------- RhSolutions.Tests/WorkbookCheckTests.cs | 16 +++++++++++ 3 files changed, 46 insertions(+), 38 deletions(-) create mode 100644 RhSolutions.Tests/CalculationTests.cs delete mode 100644 RhSolutions.Tests/Tests.cs create mode 100644 RhSolutions.Tests/WorkbookCheckTests.cs diff --git a/RhSolutions.Tests/CalculationTests.cs b/RhSolutions.Tests/CalculationTests.cs new file mode 100644 index 0000000..d6c54c2 --- /dev/null +++ b/RhSolutions.Tests/CalculationTests.cs @@ -0,0 +1,30 @@ +namespace RhSolutions.Tests; + +public class CalculationTests : IDisposable +{ + private Workbook workbook; + + public CalculationTests() + { + workbook = Util.Application.Workbooks.Add(); + } + + public void Dispose() + { + workbook.Close(SaveChanges: false); + } + + [ExcelFact] + public void NumbersAddCorrectly() + { + var ws = workbook.Sheets[1]; + + ws.Range["A1"].Value = 2.0; + ws.Range["A2"].Value = 3.0; + ws.Range["A3"].Formula = "= A1 + A2"; + + var result = ws.Range["A3"].Value; + + Assert.Equal(5.0, result); + } +} \ No newline at end of file diff --git a/RhSolutions.Tests/Tests.cs b/RhSolutions.Tests/Tests.cs deleted file mode 100644 index 3d1e988..0000000 --- a/RhSolutions.Tests/Tests.cs +++ /dev/null @@ -1,38 +0,0 @@ -namespace RhSolutions.Tests -{ - [ExcelTestSettings(AddIn = @"..\..\..\..\RhSolutions.AddIn\bin\Debug\net6.0-windows\RhSolutions-AddIn")] - public class CalculationTests : IDisposable - { - Workbook _testWorkbook; - - public CalculationTests() - { - // Get hold of the Excel Application object and create a workbook - _testWorkbook = Util.Application.Workbooks.Add(); - } - - public void Dispose() - { - // Clean up our workbook without saving changes - _testWorkbook.Close(SaveChanges: false); - } - - [ExcelFact] - public void NumbersAddCorrectly() - { - // We'll just do our test on the first sheet - var ws = _testWorkbook.Sheets[1]; - - // Write two numbers to the active sheet, and a formula that adds them, together - ws.Range["A1"].Value = 2.0; - ws.Range["A2"].Value = 3.0; - ws.Range["A3"].Formula = "= A1 + A2"; - - // Read back the value from the cell with the formula - var result = ws.Range["A3"].Value; - - // Check that we have the expected result - Assert.Equal(5.0, result); - } - } -} \ No newline at end of file diff --git a/RhSolutions.Tests/WorkbookCheckTests.cs b/RhSolutions.Tests/WorkbookCheckTests.cs new file mode 100644 index 0000000..f5fe66c --- /dev/null +++ b/RhSolutions.Tests/WorkbookCheckTests.cs @@ -0,0 +1,16 @@ +namespace RhSolutions.Tests; + +[ExcelTestSettings(AddIn = @"..\..\..\..\RhSolutions.AddIn\bin\Debug\net6.0-windows\RhSolutions-AddIn")] +public class WorkbookCheckTests : IDisposable +{ + [ExcelFact(Workbook = @".\Workbooks\EmptyTestTable.xlsx")] + public void WorksheetIsCorrect() + { + Assert.True(true); + } + + public void Dispose() + { + Util.Application.ActiveWorkbook.Close(SaveChanges: false); + } +} \ No newline at end of file