1
0

47 lines
1.5 KiB
C#
Raw Normal View History

2025-01-14 05:59:55 +00:00
using RhSolutions.SkuParser.Services;
namespace RhSolutions.SkuParser.Tests;
public class ExcelParserTests
{
2025-01-14 14:01:01 +00:00
private static readonly Dictionary<Product, double> _expected = new()
2025-01-14 05:59:55 +00:00
{
2025-01-14 14:01:01 +00:00
[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,
2025-01-14 05:59:55 +00:00
};
[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);
2025-01-14 14:01:01 +00:00
var parser = new CommonExcelParser();
2025-01-14 05:59:55 +00:00
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);
2025-01-14 14:01:01 +00:00
var parser = new CommonCsvParser();
2025-01-14 05:59:55 +00:00
var actual = parser.ParseProducts(mockFile.Object);
Assert.That(actual.Count, Is.EqualTo(_expected.Count()));
CollectionAssert.AreEqual(_expected, actual);
}
}