RhSolutions-AddIn/RhSolutions.Tests/CanDoGuess.cs

62 lines
2.7 KiB
C#
Raw Permalink Normal View History

2023-05-22 08:05:44 +03:00
using Microsoft.Extensions.DependencyInjection;
using RhSolutions.AddIn;
using System.IO;
namespace RhSolutions.Tests;
[ExcelTestSettings(OutOfProcess = true)]
2023-05-23 07:07:16 +03:00
public class CanDoGuess : IDisposable
2023-05-22 08:05:44 +03:00
{
private RhSolutionsAddIn _addIn;
2023-05-30 08:47:16 +03:00
private IReader _guessReader;
2023-05-22 08:05:44 +03:00
private IReader _reader;
2023-05-23 07:07:16 +03:00
public CanDoGuess()
2023-05-22 08:05:44 +03:00
{
_addIn = new();
_addIn.AutoOpen();
2023-05-30 08:47:16 +03:00
_guessReader = new GuessReader(Util.Application);
_reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration);
2023-05-22 08:05:44 +03:00
}
2023-05-23 07:07:16 +03:00
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationGuess.xlsx")]
2023-05-23 14:39:49 +03:00
public void CanWriteMultiplyRows()
2023-05-22 08:05:44 +03:00
{
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
2023-05-23 07:07:16 +03:00
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuess.xlsx"));
2023-05-30 08:47:16 +03:00
var products = _guessReader.ReadProducts(new[] { sourceSheet });
2023-06-20 07:25:44 +03:00
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
2023-05-22 08:05:44 +03:00
_writer.WriteProducts(products);
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
var targetProducts = _reader.ReadProducts(new[] { targetSheet });
2023-05-23 07:07:16 +03:00
Assert.Equal("TestSpecificationGuess", products.First().Item1);
Assert.Equal("TargetSpecificationGuess", targetProducts.First().Item1);
2023-05-22 08:05:44 +03:00
Assert.Equal(products.First().Item2.Count(), targetProducts.First().Item2.Count());
Assert.Equal(products.First().Item2.Values.Sum(), targetProducts.First().Item2.Values.Sum());
}
2023-05-23 14:39:49 +03:00
[ExcelFact(Workbook = @"..\..\..\TestWorkbooks\TestSpecificationGuessOneRow.xlsx")]
public void CanWriteOneRow()
{
Worksheet sourceSheet = Util.Workbook.Worksheets[1];
RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\TargetSpecificationGuessOneRow.xlsx"));
2023-05-30 08:47:16 +03:00
var products = _guessReader.ReadProducts(new[] { sourceSheet });
2023-06-20 07:25:44 +03:00
var _writer = new NewPriceWriter(Util.Application, RhSolutionsAddIn.Configuration);
2023-05-23 14:39:49 +03:00
_writer.WriteProducts(products);
Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet;
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());
}
2023-05-22 08:05:44 +03:00
public void Dispose()
{
_addIn.AutoClose();
Util.Application.ActiveWindow.Close(SaveChanges: false);
}
}