60 lines
2.6 KiB
C#
60 lines
2.6 KiB
C#
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>();
|
|
}
|
|
|
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecification.xlsx")]
|
|
public void CanWriteSingle()
|
|
{
|
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecification.xlsx"));
|
|
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 });
|
|
|
|
Assert.Equal("TestSpecification", products.First().Item1);
|
|
Assert.Equal("TargetSpecification", targetProducts.First().Item1);
|
|
Assert.Equal(products.First().Item2.Count(), targetProducts.First().Item2.Count());
|
|
Assert.Equal(products.First().Item2.Values.Sum(), targetProducts.First().Item2.Values.Sum());
|
|
}
|
|
|
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationMultipleProductLines.xlsx")]
|
|
public void CanWriteMultipleProductLines()
|
|
{
|
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMultipleProductLines.xlsx"));
|
|
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 });
|
|
|
|
Assert.Equal("TestSpecificationMultipleProductLines", products.First().Item1);
|
|
Assert.Equal("TargetSpecificationMultipleProductLines", targetProducts.First().Item1);
|
|
Assert.Equal(2, targetProducts.First().Item2.Count());
|
|
Assert.True(Enumerable.SequenceEqual(products.First().Item2, targetProducts.First().Item2));
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_addIn.AutoClose();
|
|
Util.Application.ActiveWindow.Close(SaveChanges: false);
|
|
}
|
|
}
|