using RhSolutions.SkuParser.Services; namespace RhSolutions.SkuParser.Tests; public class ExcelParserTests { private static readonly List _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); } }