From 0fcc6320249a2bacc821c31d2d8fddb90798d14d Mon Sep 17 00:00:00 2001 From: Sergey Chebotar Date: Sun, 21 May 2023 15:47:09 +0300 Subject: Add real pricelist test --- RhSolutions.Tests/RealPricelistTest.cs | 41 +++++++++++++++++++++ .../TestWorkbooks/RealTargetSpecification.xlsx | Bin 0 -> 739068 bytes .../TestWorkbooks/RealTestSpecification.xlsm | Bin 0 -> 1904085 bytes 3 files changed, 41 insertions(+) create mode 100644 RhSolutions.Tests/RealPricelistTest.cs create mode 100644 RhSolutions.Tests/TestWorkbooks/RealTargetSpecification.xlsx create mode 100644 RhSolutions.Tests/TestWorkbooks/RealTestSpecification.xlsm (limited to 'RhSolutions.Tests') diff --git a/RhSolutions.Tests/RealPricelistTest.cs b/RhSolutions.Tests/RealPricelistTest.cs new file mode 100644 index 0000000..37a9bc4 --- /dev/null +++ b/RhSolutions.Tests/RealPricelistTest.cs @@ -0,0 +1,41 @@ +using Microsoft.Extensions.DependencyInjection; +using RhSolutions.AddIn; +using System.IO; + +namespace RhSolutions.Tests; + +[ExcelTestSettings(OutOfProcess = true)] +public class RealPricelistTest : IDisposable +{ + private RhSolutionsAddIn _addIn; + private IReader _reader; + + public RealPricelistTest() + { + _addIn = new(); + _addIn.AutoOpen(); + _reader = RhSolutionsAddIn.ServiceProvider.GetRequiredService(); + } + + [ExcelFact(Workbook = @"..\..\..\TestWorkbooks\RealTestSpecification.xlsm")] + public void CanWrite() + { + Worksheet sourceSheet = Util.Workbook.Worksheets[1]; + RhSolutionsAddIn.Configuration.SetPriceListPath(Path.GetFullPath(@"..\..\..\TestWorkbooks\RealTargetSpecification.xlsx")); + var products = _reader.ReadProducts(new[] { sourceSheet }); + var _writer = new ExcelWriter(Util.Application, RhSolutionsAddIn.Configuration); + _writer.WriteProducts(products); + Worksheet targetSheet = Util.Application.ActiveWindow.ActiveSheet; + targetSheet.Range["A1"].Formula = "=SUM(H:H)"; + + Assert.Equal("RealTestSpecification", products.First().Item1); + Assert.Equal("RealTargetSpecification.xlsx", Util.Application.ActiveWorkbook.Name); + Assert.Equal(1188.0, targetSheet.Range["A1"].Value); + } + + public void Dispose() + { + _addIn.AutoClose(); + Util.Application.ActiveWindow.Close(SaveChanges: false); + } +} diff --git a/RhSolutions.Tests/TestWorkbooks/RealTargetSpecification.xlsx b/RhSolutions.Tests/TestWorkbooks/RealTargetSpecification.xlsx new file mode 100644 index 0000000..ed3d370 Binary files /dev/null and b/RhSolutions.Tests/TestWorkbooks/RealTargetSpecification.xlsx differ diff --git a/RhSolutions.Tests/TestWorkbooks/RealTestSpecification.xlsm b/RhSolutions.Tests/TestWorkbooks/RealTestSpecification.xlsm new file mode 100644 index 0000000..b8fcf4a Binary files /dev/null and b/RhSolutions.Tests/TestWorkbooks/RealTestSpecification.xlsm differ -- cgit v1.2.3