diff options
Diffstat (limited to 'RhSolutions.SkuParser.Tests')
-rw-r--r-- | RhSolutions.SkuParser.Tests/ExcelParserTests.cs | 96 | ||||
-rw-r--r-- | RhSolutions.SkuParser.Tests/FormFileUtil.cs | 32 | ||||
-rw-r--r-- | RhSolutions.SkuParser.Tests/GlobalUsings.cs | 2 | ||||
-rw-r--r-- | RhSolutions.SkuParser.Tests/ProductTests.cs | 148 | ||||
-rw-r--r-- | RhSolutions.SkuParser.Tests/RhSolutions.SkuParser.Tests.csproj | 50 | ||||
-rw-r--r-- | RhSolutions.SkuParser.Tests/Workbooks/simple.csv | 20 |
6 files changed, 174 insertions, 174 deletions
diff --git a/RhSolutions.SkuParser.Tests/ExcelParserTests.cs b/RhSolutions.SkuParser.Tests/ExcelParserTests.cs index 83e95c1..60e1e7b 100644 --- a/RhSolutions.SkuParser.Tests/ExcelParserTests.cs +++ b/RhSolutions.SkuParser.Tests/ExcelParserTests.cs @@ -1,48 +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); - } -} +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 index aaee7ca..f100989 100644 --- a/RhSolutions.SkuParser.Tests/FormFileUtil.cs +++ b/RhSolutions.SkuParser.Tests/FormFileUtil.cs @@ -1,17 +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; - } +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 index 139a90f..f1d70cc 100644 --- a/RhSolutions.SkuParser.Tests/GlobalUsings.cs +++ b/RhSolutions.SkuParser.Tests/GlobalUsings.cs @@ -1,2 +1,2 @@ -global using NUnit.Framework; +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 index 12f0944..ee7396d 100644 --- a/RhSolutions.SkuParser.Tests/ProductTests.cs +++ b/RhSolutions.SkuParser.Tests/ProductTests.cs @@ -1,75 +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!)); - } +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 index 069fa02..ba8a0cb 100644 --- a/RhSolutions.SkuParser.Tests/RhSolutions.SkuParser.Tests.csproj +++ b/RhSolutions.SkuParser.Tests/RhSolutions.SkuParser.Tests.csproj @@ -1,25 +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> +<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/simple.csv b/RhSolutions.SkuParser.Tests/Workbooks/simple.csv index 51d2c85..948bcf9 100644 --- a/RhSolutions.SkuParser.Tests/Workbooks/simple.csv +++ b/RhSolutions.SkuParser.Tests/Workbooks/simple.csv @@ -1,10 +1,10 @@ -11303703100;2129,5 -11303803100;503 -11303903050;52 -11080011001;2154 -11080021001;134 -11080031001;6 -11080311001;462 -11080611001;38 -11080811001;24 -11080831001;2 +11303703100;2129,5
+11303803100;503
+11303903050;52
+11080011001;2154
+11080021001;134
+11080031001;6
+11080311001;462
+11080611001;38
+11080811001;24
+11080831001;2
|