66 lines
2.8 KiB
C#
66 lines
2.8 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using RhSolutions.AddIn;
|
|
using System.IO;
|
|
|
|
namespace RhSolutions.Tests;
|
|
|
|
[ExcelTestSettings(OutOfProcess = true)]
|
|
public class CanDoGuess : IDisposable
|
|
{
|
|
private RhSolutionsAddIn _addIn;
|
|
private IReader _guessReader;
|
|
private IReader _reader;
|
|
|
|
public CanDoGuess()
|
|
{
|
|
_addIn = new();
|
|
_addIn.AutoOpen();
|
|
_guessReader = new GuessReader(Util.Application);
|
|
_reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration);
|
|
}
|
|
|
|
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationGuess.xlsx")]
|
|
public void CanWriteMultiplyRows()
|
|
{
|
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
|
sourceSheet.Validate();
|
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
|
|
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
|
_writer.WriteProducts(products);
|
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
|
targetSheet.Validate();
|
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
|
|
|
Assert.Equal("TestSpecificationGuess", products.First().Item1);
|
|
Assert.Equal("TargetSpecificationGuess", 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\TestSpecificationGuessOneRow.xlsx")]
|
|
public void CanWriteOneRow()
|
|
{
|
|
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
|
|
sourceSheet.Validate();
|
|
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
|
|
var products = _guessReader.ReadProducts(new[] { sourceSheet });
|
|
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
|
|
_writer.WriteProducts(products);
|
|
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
|
|
targetSheet.Validate();
|
|
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
|
|
|
|
Assert.Equal("TestSpecificationGuessOneRow", products.First().Item1);
|
|
Assert.Equal("TargetSpecificationGuessOneRow", 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);
|
|
}
|
|
}
|