aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.Tests/RealPricelistTest.cs
blob: 284c328bae1beab6172a40f734b1064af0df8766 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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()
    {
        Environment.SetEnvironmentVariable("ISTESTING", "true");
        _addIn = new();
        _addIn.AutoOpen();
        _reader = new ExcelReader(Util.Application, RhSolutionsAddIn.Configuration);
    }

    [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 NewPriceWriter(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);
    }
}