2023-04-06 21:38:11 +03:00
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using RhSolutions.AddIn;
|
|
|
|
|
|
|
|
|
|
namespace RhSolutions.Tests;
|
|
|
|
|
|
|
|
|
|
[ExcelTestSettings(OutOfProcess = true)]
|
|
|
|
|
public class CanReadProducts : IDisposable
|
|
|
|
|
{
|
|
|
|
|
private RhSolutionsAddIn _addIn;
|
2023-04-20 09:37:07 +03:00
|
|
|
|
private IReader _reader;
|
2023-04-06 21:38:11 +03:00
|
|
|
|
private Workbook _testWorkbook;
|
|
|
|
|
|
|
|
|
|
public CanReadProducts()
|
|
|
|
|
{
|
|
|
|
|
_addIn = new();
|
|
|
|
|
_testWorkbook = Util.Application.Workbooks.Add();
|
|
|
|
|
_addIn.AutoOpen();
|
2023-04-20 09:37:07 +03:00
|
|
|
|
_reader = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IReader>();
|
2023-04-06 21:38:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ExcelFact]
|
|
|
|
|
public void CanReadRange()
|
|
|
|
|
{
|
|
|
|
|
Worksheet worksheet = _testWorkbook.Sheets[1];
|
|
|
|
|
worksheet.Range["A1"].Value = "11600011001";
|
|
|
|
|
worksheet.Range["A2"].Value = "11600011001";
|
|
|
|
|
worksheet.Range["A3"].Value = "160002-001";
|
|
|
|
|
worksheet.Range["A4"].Value = "Fuzz";
|
|
|
|
|
worksheet.Range["B1"].Value = 10;
|
|
|
|
|
worksheet.Range["B2"].Value = 10;
|
|
|
|
|
worksheet.Range["B3"].Value = 5;
|
|
|
|
|
worksheet.Range["B5"].Value = 1000_000;
|
|
|
|
|
worksheet.Range["A6"].Value = "111111-111";
|
|
|
|
|
worksheet.Range["B6"].Value = 100;
|
|
|
|
|
|
|
|
|
|
Range testRange = worksheet.Range["A1:B6"];
|
|
|
|
|
|
|
|
|
|
var products = _reader.ReadProducts(testRange);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(products);
|
|
|
|
|
Assert.NotEmpty(products);
|
2023-05-05 08:21:26 +03:00
|
|
|
|
Assert.Equal("11600011001", products.First().Key.ProductSku?.ToString());
|
2023-04-06 21:38:11 +03:00
|
|
|
|
Assert.Equal(20.0, products.First().Value);
|
|
|
|
|
Assert.Equal(125.0, products.Sum(p => p.Value));
|
|
|
|
|
Assert.Equal(3, products.Count());
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-18 14:53:52 +03:00
|
|
|
|
[ExcelFact(Workbook = @"TestWorkbooks\TestSpecification.xlsx")]
|
2023-04-06 21:38:11 +03:00
|
|
|
|
public void CanReadWorkbook()
|
|
|
|
|
{
|
|
|
|
|
Worksheet worksheet = Util.Workbook.Worksheets[1];
|
2023-05-16 18:05:35 +03:00
|
|
|
|
var result = _reader.ReadProducts(new[] { worksheet });
|
|
|
|
|
Assert.NotNull(result);
|
|
|
|
|
Assert.NotEmpty(result);
|
2023-05-18 14:53:52 +03:00
|
|
|
|
Assert.Equal("TestSpecification", result.First().Item1);
|
2023-05-16 18:05:35 +03:00
|
|
|
|
var products = result.First().Item2;
|
|
|
|
|
Assert.Equal(46, products.Count());
|
|
|
|
|
Assert.Equal(29266, products.Sum(p => p.Value));
|
2023-04-06 21:38:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_addIn.AutoClose();
|
|
|
|
|
Util.Application.ActiveWindow.Close(SaveChanges: false);
|
|
|
|
|
}
|
|
|
|
|
}
|