Add Workbook check tests

This commit is contained in:
Sergey Chebotar 2023-03-23 17:13:48 +03:00
parent 2cef4d1d9f
commit 3c93c978d4
8 changed files with 72 additions and 100 deletions

View File

@ -1,24 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net472;net6.0-windows</TargetFrameworks> <TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
<OutputType>Library</OutputType> <LangVersion>10</LangVersion>
<RootNamespace>RhSolutions.AddIn</RootNamespace> <OutputType>Library</OutputType>
<AssemblyName>RhSolutions.AddIn</AssemblyName> <RootNamespace>RhSolutions.AddIn</RootNamespace>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> <AssemblyName>RhSolutions.AddIn</AssemblyName>
<UseWindowsForms>true</UseWindowsForms> <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets> <UseWindowsForms>true</UseWindowsForms>
</PropertyGroup> <ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
<PropertyGroup> </PropertyGroup>
<StartupObject /> <PropertyGroup>
</PropertyGroup> <StartupObject />
<ItemGroup> </PropertyGroup>
<PackageReference Include="ExcelDna.AddIn" Version="1.6.0" /> <ItemGroup>
<PackageReference Include="ExcelDna.Integration" Version="1.6.0" /> <PackageReference Include="ExcelDna.AddIn" Version="1.6.0" />
<PackageReference Include="ExcelDna.IntelliSense" Version="1.6.0" /> <PackageReference Include="ExcelDna.Integration" Version="1.6.0" />
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" /> <PackageReference Include="ExcelDna.IntelliSense" Version="1.6.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> <PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="RhSolutions.Sku" Version="0.1.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" /> <PackageReference Include="RhSolutions.Sku" Version="0.1.1" />
</ItemGroup> <PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project> </Project>

View File

@ -1,30 +0,0 @@
namespace RhSolutions.Tests;
public class CalculationTests : IDisposable
{
private Workbook workbook;
public CalculationTests()
{
workbook = Util.Application.Workbooks.Add();
}
public void Dispose()
{
workbook.Close(SaveChanges: false);
}
[ExcelFact]
public void NumbersAddCorrectly()
{
var ws = workbook.Sheets[1];
ws.Range["A1"].Value = 2.0;
ws.Range["A2"].Value = 3.0;
ws.Range["A3"].Formula = "= A1 + A2";
var result = ws.Range["A3"].Value;
Assert.Equal(5.0, result);
}
}

View File

@ -1,14 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net472</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <LangVersion>10</LangVersion>
<Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings>
<OutputType>Library</OutputType> <Nullable>enable</Nullable>
</PropertyGroup> <OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ExcelDna.Testing" Version="1.6.0" /> <PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
</ItemGroup> <PackageReference Include="ExcelDna.Testing" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RhSolutions.AddIn\RhSolutions.AddIn.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="TestWorkbooks\EmptyTestTable.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestWorkbooks\EmptyWorkbook.xlsx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project> </Project>

View File

@ -1,30 +1,30 @@
namespace RhSolutions.Tests; namespace RhSolutions.Tests
[ExcelTestSettings(AddIn = @"..\..\..\..\RhSolutions.AddIn\bin\Debug\net6.0-windows\RhSolutions-AddIn")]
public class RhSolutionsCheckTest : IDisposable
{ {
private Workbook workbook; [ExcelTestSettings(AddIn = @"..\..\..\..\RhSolutions.AddIn\bin\Debug\net472\RhSolutions-AddIn", OutOfProcess = true)]
public class WorkbookCheck : IDisposable
public RhSolutionsCheckTest()
{ {
workbook = Util.Application.Workbooks.Add(); public WorkbookCheck()
} {
Util.Application.Workbooks.Add();
}
[ExcelFact] [ExcelFact(Workbook = @"TestWorkbooks\EmptyTestTable.xlsx")]
public void RhSolutionsFunctionWorks() public void WorksheetIsCorrect()
{ {
var ws = workbook.Sheets[1]; Worksheet worksheet= Util.Workbook.Sheets[1];
Assert.True(worksheet.IsRehauSource());
}
ws.Range["A1"].Formula = "=RHSOLUTIONS(\"гильза 16\")"; [ExcelFact(Workbook = @"TestWorkbooks\EmptyWorkbook.xlsx")]
Util.Application.CalculateFull(); public void EmptyWorkbookIsNotCorrect()
{
Worksheet worksheet = Util.Workbook.Sheets[1];
Assert.False(worksheet.IsRehauSource());
}
var result = ws.Range["A1"].Value; public void Dispose()
{
Assert.Equal("Загрузка...", result); Util.Application.ActiveWorkbook.Close(SaveChanges: false);
} }
public void Dispose()
{
Util.Application.ActiveWorkbook.Close(SaveChanges: false);
} }
} }

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,5 @@
global using Xunit; global using Xunit;
global using Microsoft.Office.Interop.Excel; global using Microsoft.Office.Interop.Excel;
global using ExcelDna.Testing; global using ExcelDna.Testing;
global using RhSolutions.Models;
global using RhSolutions.Services;

View File

@ -1,16 +0,0 @@
//namespace RhSolutions.Tests;
//[ExcelTestSettings(AddIn = @"..\..\..\..\RhSolutions.AddIn\bin\Debug\net6.0-windows\RhSolutions-AddIn")]
//public class WorkbookCheckTests : IDisposable
//{
// [ExcelFact(Workbook = @".\Workbooks\EmptyTestTable.xlsx")]
// public void WorksheetIsCorrect()
// {
// Assert.True(true);
// }
// public void Dispose()
// {
// Util.Application.ActiveWorkbook.Close(SaveChanges: false);
// }
//}