RhSolutions-AddIn/RhSolutions.Tests/CanWriteProducts.cs

43 lines
1.5 KiB
C#
Raw Normal View History

2023-05-18 07:15:52 +03:00
using Microsoft.Extensions.DependencyInjection;
using RhSolutions.AddIn;
using System.IO;
namespace RhSolutions.Tests;
[ExcelTestSettings(OutOfProcess = true)]
public class CanWriteProducts : IDisposable
{
private RhSolutionsAddIn _addIn;
private IReader _reader;
public CanWriteProducts()
{
_addIn = new();
_addIn.AutoOpen();
_reader = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IReader>();
}
2023-05-18 07:23:59 +03:00
[ExcelFact(Workbook = @"TestWorkbooks\TestSpecification.xlsx")]
public void CanWriteSingle()
2023-05-18 07:15:52 +03:00
{
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
2023-05-18 07:23:59 +03:00
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecification.xlsx"));
2023-05-18 07:15:52 +03:00
var products = _reader.ReadProducts(new[] { sourceSheet });
var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration);
_writer.WriteProducts(products);
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
2023-05-18 07:23:59 +03:00
Assert.Equal("TestSpecification", products.First().Item1);
Assert.Equal("TargetSpecification", targetProducts.First().Item1);
2023-05-18 07:15:52 +03:00
Assert.Equal(products.First().Item2.Count(), targetProducts.First().Item2.Count());
2023-05-18 07:23:59 +03:00
Assert.Equal(products.First().Item2.Values.Sum(), targetProducts.First().Item2.Values.Sum());
2023-05-18 07:15:52 +03:00
}
public void Dispose()
{
_addIn.AutoClose();
Util.Application.ActiveWindow.Close(SaveChanges: false);
}
}