aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.Tests
diff options
context:
space:
mode:
authorSergey Chebotar <s.chebotar@gmail.com>2023-04-06 21:38:11 +0300
committerSergey Chebotar <s.chebotar@gmail.com>2023-04-06 21:38:11 +0300
commit93195a9cc90b6ebf3e1ecdbd618a5e6a800956b7 (patch)
tree96b2c7d55cb1a13d48234be4d6abff5fee343ee4 /RhSolutions.Tests
parent99f46e089cc4548966159bca47b18c9fc257d0a4 (diff)
Add Tests
Diffstat (limited to 'RhSolutions.Tests')
-rw-r--r--RhSolutions.Tests/CanReadProducts.cs63
-rw-r--r--RhSolutions.Tests/RhSolutions.Tests.csproj3
-rw-r--r--RhSolutions.Tests/TestWorkbooks/Specifications/HeatingFloor.xlsxbin0 -> 10005 bytes
-rw-r--r--RhSolutions.Tests/WorkbookValidationTests.cs16
4 files changed, 78 insertions, 4 deletions
diff --git a/RhSolutions.Tests/CanReadProducts.cs b/RhSolutions.Tests/CanReadProducts.cs
new file mode 100644
index 0000000..e9be68c
--- /dev/null
+++ b/RhSolutions.Tests/CanReadProducts.cs
@@ -0,0 +1,63 @@
+using Microsoft.Extensions.DependencyInjection;
+using RhSolutions.AddIn;
+
+namespace RhSolutions.Tests;
+
+[ExcelTestSettings(OutOfProcess = true)]
+public class CanReadProducts : IDisposable
+{
+ private RhSolutionsAddIn _addIn;
+ private IExcelReader _reader;
+ private Workbook _testWorkbook;
+
+ public CanReadProducts()
+ {
+ _addIn = new();
+ _testWorkbook = Util.Application.Workbooks.Add();
+ _addIn.AutoOpen();
+ _reader = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IExcelReader>();
+ }
+
+ [ExcelFact]
+ public void CanReadRange()
+ {
+ Worksheet worksheet = _testWorkbook.Sheets[1];
+ worksheet.Range["A1"].Value = "11600011001";
+ worksheet.Range["A2"].Value = "11600011001";
+ worksheet.Range["A3"].Value = "160002-001";
+ worksheet.Range["A4"].Value = "Fuzz";
+ worksheet.Range["B1"].Value = 10;
+ worksheet.Range["B2"].Value = 10;
+ worksheet.Range["B3"].Value = 5;
+ worksheet.Range["B5"].Value = 1000_000;
+ worksheet.Range["A6"].Value = "111111-111";
+ worksheet.Range["B6"].Value = 100;
+
+ Range testRange = worksheet.Range["A1:B6"];
+
+ var products = _reader.ReadProducts(testRange);
+
+ Assert.NotNull(products);
+ Assert.NotEmpty(products);
+ Assert.Equal("11600011001", products.First().Key.ProductSku);
+ Assert.Equal(20.0, products.First().Value);
+ Assert.Equal(125.0, products.Sum(p => p.Value));
+ Assert.Equal(3, products.Count());
+ }
+
+ [ExcelFact(Workbook = @"TestWorkbooks\Specifications\HeatingFloor.xlsx")]
+ public void CanReadWorkbook()
+ {
+ Worksheet worksheet = Util.Workbook.Worksheets[1];
+ var products = _reader.ReadProducts(new[] { worksheet });
+
+ Assert.NotNull(products);
+ Assert.NotEmpty(products);
+ }
+
+ public void Dispose()
+ {
+ _addIn.AutoClose();
+ Util.Application.ActiveWindow.Close(SaveChanges: false);
+ }
+} \ No newline at end of file
diff --git a/RhSolutions.Tests/RhSolutions.Tests.csproj b/RhSolutions.Tests/RhSolutions.Tests.csproj
index 9410802..63b9ae5 100644
--- a/RhSolutions.Tests/RhSolutions.Tests.csproj
+++ b/RhSolutions.Tests/RhSolutions.Tests.csproj
@@ -27,6 +27,9 @@
<None Update="TestWorkbooks\ExcelTableTest.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+ <None Update="TestWorkbooks\Specifications\HeatingFloor.xlsx">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
</ItemGroup>
</Project>
diff --git a/RhSolutions.Tests/TestWorkbooks/Specifications/HeatingFloor.xlsx b/RhSolutions.Tests/TestWorkbooks/Specifications/HeatingFloor.xlsx
new file mode 100644
index 0000000..f0b76f3
--- /dev/null
+++ b/RhSolutions.Tests/TestWorkbooks/Specifications/HeatingFloor.xlsx
Binary files differ
diff --git a/RhSolutions.Tests/WorkbookValidationTests.cs b/RhSolutions.Tests/WorkbookValidationTests.cs
index aec7139..ca00a18 100644
--- a/RhSolutions.Tests/WorkbookValidationTests.cs
+++ b/RhSolutions.Tests/WorkbookValidationTests.cs
@@ -1,10 +1,17 @@
-namespace RhSolutions.Tests;
+using RhSolutions.AddIn;
+using RhSolutions.Tools;
+
+namespace RhSolutions.Tests;
[ExcelTestSettings(OutOfProcess = true)]
public class WorkbookValidationTests : IDisposable
{
+ private readonly RhSolutionsAddIn _addIn;
+
public WorkbookValidationTests()
{
+ _addIn = new RhSolutionsAddIn();
+ _addIn.AutoOpen();
Util.Application.Workbooks.Add();
}
@@ -12,18 +19,19 @@ public class WorkbookValidationTests : IDisposable
public void WorksheetIsCorrect()
{
Worksheet worksheet = Util.Workbook.Sheets[1];
- Assert.True(worksheet.IsRehauSource());
+ Assert.True(worksheet.IsValidSource());
}
[ExcelFact(Workbook = @"TestWorkbooks\EmptyWorkbook.xlsx")]
public void EmptyWorkbookIsNotCorrect()
{
Worksheet worksheet = Util.Workbook.Sheets[1];
- Assert.False(worksheet.IsRehauSource());
+ Assert.False(worksheet.IsValidSource());
}
public void Dispose()
{
+ _addIn.AutoClose();
Util.Application.ActiveWindow.Close(SaveChanges: false);
}
-} \ No newline at end of file
+}