diff options
Diffstat (limited to 'RhSolutions.SkuParser.Tests/ExcelParserTests.cs')
-rw-r--r-- | RhSolutions.SkuParser.Tests/ExcelParserTests.cs | 48 |
1 files changed, 48 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); + } +} |