1
0

47 lines
1.5 KiB
C#

using RhSolutions.SkuParser.Services;
namespace RhSolutions.SkuParser.Tests;
public class ExcelParserTests
{
private static readonly Dictionary<Product, double> _expected = new()
{
[new Product() {Sku = "11303703100"}] = 2129.5,
[new Product() {Sku = "11303803100"}] = 503,
[new Product() {Sku = "11303903050"}] = 52,
[new Product() {Sku = "11080011001"}] = 2154,
[new Product() {Sku = "11080021001"}] = 134,
[new Product() {Sku = "11080031001"}] = 6,
[new Product() {Sku = "11080311001"}] = 462,
[new Product() {Sku = "11080611001"}] = 38,
[new Product() {Sku = "11080811001"}] = 24,
[new Product() {Sku = "11080831001"}] = 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 CommonExcelParser();
var actual = parser.ParseProducts(mockFile.Object);
Assert.That(actual.Count, Is.EqualTo(_expected.Count()));
CollectionAssert.AreEqual(_expected, actual);
}
[TestCase("simple.csv")]
public void CsvTests(string filename)
{
var mockFile = FormFileUtil.GetMockFormFile(filename);
var parser = new CommonCsvParser();
var actual = parser.ParseProducts(mockFile.Object);
Assert.That(actual.Count, Is.EqualTo(_expected.Count()));
CollectionAssert.AreEqual(_expected, actual);
}
}