aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.SkuParser.Tests
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2024-07-21 16:25:59 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2024-07-21 16:25:59 +0300
commit6fe0a5e92b071411a0408d59d54d0de78e55d75c (patch)
tree3100d0991b67c17434d131e509eefc85f6a71ff8 /RhSolutions.SkuParser.Tests
parente0313b83a033040660f0669de6d9e77042e87026 (diff)
Squashed commit of the following:
commit 688c5426e8793b808b9c75c9a19733af0a402fcb Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sun Jul 21 16:25:14 2024 +0300 Switch to port 8080 commit c39249f6528ec76686a9382d1dc375c07d1d5044 Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sun Jul 21 16:24:59 2024 +0300 Switch to alpine image commit 5318d7ec3f4f3d205549cf6732fa5b066a1d0a36 Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sun Jul 21 15:40:14 2024 +0300 Add docker commit b6cd60a973da26bc92cf1fb45b4d2396b7ce56ea Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sun Jul 21 15:00:12 2024 +0300 Delete asynchrony commit 44a194e6d27312f3b8dd0b9c9c02d873e06e0b22 Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sun Jul 21 14:59:29 2024 +0300 Add Equals and GetHasCode methods overrides to ProductQuantity class commit a274eadd313e12f11cc84d32e5030bbc5b187f8c Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sun Jul 21 14:58:37 2024 +0300 Add parsers tests commit 4f969e70d9716d8ddb4f4efedd466846289d7e2b Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sun Jul 21 14:57:55 2024 +0300 Update product tests commit 2485e20d0e93bed562f929055b6867dc2574a95b Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sat Jul 20 19:34:19 2024 +0300 Implement Excel parser commit 30f2e28c87a4d961c1f1fc48fbd72334905bf4ed Author: Serghei Cebotari <serghei@cebotari.ru> Date: Sat Jul 20 16:58:35 2024 +0300 Implement csv parser commit 08e86b43c0829de341dc3d24fbe01aadbed2e173 Author: Serghei Cebotari <serghei@cebotari.ru> Date: Thu Jul 18 21:01:28 2024 +0300 Edit port number
Diffstat (limited to 'RhSolutions.SkuParser.Tests')
-rw-r--r--RhSolutions.SkuParser.Tests/ExcelParserTests.cs48
-rw-r--r--RhSolutions.SkuParser.Tests/FormFileUtil.cs17
-rw-r--r--RhSolutions.SkuParser.Tests/GlobalUsings.cs2
-rw-r--r--RhSolutions.SkuParser.Tests/ProductTests.cs75
-rw-r--r--RhSolutions.SkuParser.Tests/RhSolutions.SkuParser.Tests.csproj25
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/rhSolutionsBsTable.xlsxbin0 -> 858604 bytes
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/simple.csv10
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/simple.xlsxbin0 -> 10043 bytes
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/simpleWithFormulas.xlsxbin0 -> 10451 bytes
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/simpleWithNames.xlsxbin0 -> 10647 bytes
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/twoTables.xlsxbin0 -> 10924 bytes
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/withHeader.xlsxbin0 -> 10467 bytes
-rw-r--r--RhSolutions.SkuParser.Tests/Workbooks/withHeaderAndGarbage.xlsxbin0 -> 10687 bytes
13 files changed, 177 insertions, 0 deletions
diff --git a/RhSolutions.SkuParser.Tests/ExcelParserTests.cs b/RhSolutions.SkuParser.Tests/ExcelParserTests.cs
new file mode 100644
index 0000000..83e95c1
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/ExcelParserTests.cs
@@ -0,0 +1,48 @@
+using RhSolutions.SkuParser.Services;
+
+namespace RhSolutions.SkuParser.Tests;
+
+public class ExcelParserTests
+{
+ private static readonly List<ProductQuantity> _expected = new()
+ {
+ new ProductQuantity() {Product= new Product() {Sku = "11303703100"}, Quantity = 2129.5},
+ new ProductQuantity() {Product= new Product() {Sku = "11303803100"}, Quantity = 503},
+ new ProductQuantity() {Product= new Product() {Sku = "11303903050"}, Quantity = 52},
+ new ProductQuantity() {Product= new Product() {Sku = "11080011001"}, Quantity = 2154},
+ new ProductQuantity() {Product= new Product() {Sku = "11080021001"}, Quantity = 134},
+ new ProductQuantity() {Product= new Product() {Sku = "11080031001"}, Quantity = 6},
+ new ProductQuantity() {Product= new Product() {Sku = "11080311001"}, Quantity = 462},
+ new ProductQuantity() {Product= new Product() {Sku = "11080611001"}, Quantity = 38},
+ new ProductQuantity() {Product= new Product() {Sku = "11080811001"}, Quantity = 24},
+ new ProductQuantity() {Product= new Product() {Sku = "11080831001"}, Quantity = 2},
+ };
+
+ [TestCase("simple.xlsx")]
+ [TestCase("simpleWithNames.xlsx")]
+ [TestCase("withHeader.xlsx")]
+ [TestCase("withHeaderAndGarbage.xlsx")]
+ [TestCase("twoTables.xlsx")]
+ [TestCase("rhSolutionsBsTable.xlsx")]
+ [TestCase("simpleWithFormulas.xlsx")]
+ public void XlsxTests(string filename)
+ {
+ var mockFile = FormFileUtil.GetMockFormFile(filename);
+ var parser = new ExcelParser();
+ var actual = parser.ParseProducts(mockFile.Object);
+ Assert.That(actual.Count, Is.EqualTo(_expected.Count()));
+ CollectionAssert.AllItemsAreInstancesOfType(actual, typeof(ProductQuantity));
+ CollectionAssert.AreEqual(_expected, actual);
+ }
+
+ [TestCase("simple.csv")]
+ public void CsvTests(string filename)
+ {
+ var mockFile = FormFileUtil.GetMockFormFile(filename);
+ var parser = new CsvParser();
+ var actual = parser.ParseProducts(mockFile.Object);
+ Assert.That(actual.Count, Is.EqualTo(_expected.Count()));
+ CollectionAssert.AllItemsAreInstancesOfType(actual, typeof(ProductQuantity));
+ CollectionAssert.AreEqual(_expected, actual);
+ }
+}
diff --git a/RhSolutions.SkuParser.Tests/FormFileUtil.cs b/RhSolutions.SkuParser.Tests/FormFileUtil.cs
new file mode 100644
index 0000000..aaee7ca
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/FormFileUtil.cs
@@ -0,0 +1,17 @@
+using Microsoft.AspNetCore.Http;
+using Moq;
+
+namespace RhSolutions.SkuParser.Tests;
+
+public static class FormFileUtil
+{
+ public static Mock<IFormFile> GetMockFormFile(string workbookName)
+ {
+ string filepath = "./../../../Workbooks/" + workbookName;
+ var mockFile = new Mock<IFormFile>();
+ var memoryStream = new MemoryStream([.. File.ReadAllBytes(filepath)]);
+ mockFile.Setup(x => x.OpenReadStream())
+ .Returns(memoryStream);
+ return mockFile;
+ }
+} \ No newline at end of file
diff --git a/RhSolutions.SkuParser.Tests/GlobalUsings.cs b/RhSolutions.SkuParser.Tests/GlobalUsings.cs
new file mode 100644
index 0000000..139a90f
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/GlobalUsings.cs
@@ -0,0 +1,2 @@
+global using NUnit.Framework;
+global using RhSolutions.SkuParser.Models; \ No newline at end of file
diff --git a/RhSolutions.SkuParser.Tests/ProductTests.cs b/RhSolutions.SkuParser.Tests/ProductTests.cs
new file mode 100644
index 0000000..12f0944
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/ProductTests.cs
@@ -0,0 +1,75 @@
+namespace RhSolutions.SkuParser.Tests;
+
+public class ProductTests
+{
+ [TestCase("12222221001")]
+ [TestCase("12222223001")]
+ [TestCase("160001-001")]
+ public void SimpleParse(string value)
+ {
+ Assert.True(Product.TryParse(value, out _));
+ }
+
+ [TestCase("string 12222221001")]
+ [TestCase("12222223001 string")]
+ [TestCase("string 160001-001")]
+ [TestCase("160001-001 string ")]
+ [TestCase("11096641001 Трубка РЕХАУ из. нерж. стали для подкл. радиатора, Г-образная 16/250")]
+ public void AdvancedParse(string value)
+ {
+ Assert.True(Product.TryParse(value, out _));
+ }
+
+ [TestCase("11600011001")]
+ [TestCase("160001-001")]
+ public void ProductIsCorrect(string value)
+ {
+ if (Product.TryParse(value, out Product? product))
+ {
+ Assert.That(product!.Sku, Is.EqualTo("11600011001"));
+ }
+ else
+ {
+ Assert.Fail($"Parsing failed on {value}");
+ }
+ }
+
+ [TestCase("1222222001")]
+ [TestCase("12222225001")]
+ public void NotParses(string value)
+ {
+ Assert.False(Product.TryParse(value, out _));
+ }
+
+ [Test]
+ public void ProductEquality()
+ {
+ string value = "12222223001";
+ Product.TryParse(value, out Product? first);
+ Product.TryParse(value, out Product? second);
+ if (first == null || second == null)
+ {
+ Assert.Fail($"Parsing failed on {value}");
+ }
+ else
+ {
+ Assert.True(first.Equals(second));
+ }
+ }
+
+ [Test]
+ public void HashTest()
+ {
+ string value = "12222223001";
+ HashSet<Product> set = new();
+ if (Product.TryParse(value, out var product))
+ {
+ set.Add(product!);
+ }
+ else
+ {
+ Assert.Fail($"Parsing failed on {value}");
+ }
+ Assert.True(set.Contains(product!));
+ }
+} \ No newline at end of file
diff --git a/RhSolutions.SkuParser.Tests/RhSolutions.SkuParser.Tests.csproj b/RhSolutions.SkuParser.Tests/RhSolutions.SkuParser.Tests.csproj
new file mode 100644
index 0000000..069fa02
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/RhSolutions.SkuParser.Tests.csproj
@@ -0,0 +1,25 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>net8.0</TargetFramework>
+ <ImplicitUsings>enable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+
+ <IsPackable>false</IsPackable>
+ <IsTestProject>true</IsTestProject>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
+ <PackageReference Include="Moq" Version="4.20.70" />
+ <PackageReference Include="NUnit" Version="3.13.3" />
+ <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
+ <PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
+ <PackageReference Include="coverlet.collector" Version="6.0.0" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\RhSolutions.SkuParser.Api\RhSolutions.SkuParser.Api.csproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/rhSolutionsBsTable.xlsx b/RhSolutions.SkuParser.Tests/Workbooks/rhSolutionsBsTable.xlsx
new file mode 100644
index 0000000..dd05614
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/rhSolutionsBsTable.xlsx
Binary files differ
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/simple.csv b/RhSolutions.SkuParser.Tests/Workbooks/simple.csv
new file mode 100644
index 0000000..51d2c85
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/simple.csv
@@ -0,0 +1,10 @@
+11303703100;2129,5
+11303803100;503
+11303903050;52
+11080011001;2154
+11080021001;134
+11080031001;6
+11080311001;462
+11080611001;38
+11080811001;24
+11080831001;2
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/simple.xlsx b/RhSolutions.SkuParser.Tests/Workbooks/simple.xlsx
new file mode 100644
index 0000000..05ac907
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/simple.xlsx
Binary files differ
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/simpleWithFormulas.xlsx b/RhSolutions.SkuParser.Tests/Workbooks/simpleWithFormulas.xlsx
new file mode 100644
index 0000000..7013e8e
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/simpleWithFormulas.xlsx
Binary files differ
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/simpleWithNames.xlsx b/RhSolutions.SkuParser.Tests/Workbooks/simpleWithNames.xlsx
new file mode 100644
index 0000000..88a4f25
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/simpleWithNames.xlsx
Binary files differ
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/twoTables.xlsx b/RhSolutions.SkuParser.Tests/Workbooks/twoTables.xlsx
new file mode 100644
index 0000000..8532761
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/twoTables.xlsx
Binary files differ
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/withHeader.xlsx b/RhSolutions.SkuParser.Tests/Workbooks/withHeader.xlsx
new file mode 100644
index 0000000..cc75854
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/withHeader.xlsx
Binary files differ
diff --git a/RhSolutions.SkuParser.Tests/Workbooks/withHeaderAndGarbage.xlsx b/RhSolutions.SkuParser.Tests/Workbooks/withHeaderAndGarbage.xlsx
new file mode 100644
index 0000000..31cc27b
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/Workbooks/withHeaderAndGarbage.xlsx
Binary files differ