Add Magic reader test

This commit is contained in:
Sergey Chebotar 2023-05-22 08:05:44 +03:00
parent 5720d2ede0
commit 7a7cdaab58
3 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
using Microsoft.Extensions.DependencyInjection;
using RhSolutions.AddIn;
using System.IO;
namespace RhSolutions.Tests;
[ExcelTestSettings(OutOfProcess = true)]
public class CanDoMagic : IDisposable
{
private RhSolutionsAddIn _addIn;
private ReaderFactory _readerFactory;
private IReader _reader;
public CanDoMagic()
{
_addIn = new();
_addIn.AutoOpen();
_readerFactory = RhSolutionsAddIn.ServiceProvider.GetRequiredService<ReaderFactory>();
_reader = _readerFactory.GetReader("Magic");
}
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationMagic.xlsx")]
public void CanWrite()
{
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationMagic.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("TestSpecificationMagic", products.First().Item1);
Assert.Equal("TargetSpecificationMagic", 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());
}
public void Dispose()
{
_addIn.AutoClose();
Util.Application.ActiveWindow.Close(SaveChanges: false);
}
}