Browse Source

test(exporter): Add unit tests

- Add LibreOffice unit tests
- Add Spire.XLS unit tests
pull/1249/head
colin 8 months ago
parent
commit
d18588c2bb
  1. 20
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests.csproj
  2. 24
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests.sln
  3. 6
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeTestBase.cs
  4. 20
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeTestsModule.cs
  5. 5
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOffice_Tests.cs
  6. 20
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests.csproj
  7. 6
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN/Abp/Exporter/Pdf/SpireLib/AbpExporterPdfSpireLibTestBase.cs
  8. 12
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN/Abp/Exporter/Pdf/SpireLib/AbpExporterPdfSpireLibTestsModule.cs
  9. 5
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN/Abp/Exporter/Pdf/SpireLib/AbpExporterSpireLibOffice_Tests.cs
  10. 25
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN.Abp.Exporter.Pdf.Tests.csproj
  11. 8
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/AbpExporterPdfTestBase.cs
  12. 20
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/AbpExporterPdfTestsModule.cs
  13. 34
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/ExcelToPdfProvider_Tests.cs
  14. BIN
      aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/Resources/test.xlsx

20
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests.csproj

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace />
<IsPackable>false</IsPackable>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\exporter\LINGYUN.Abp.Exporter.Pdf.LibreOffice\LINGYUN.Abp.Exporter.Pdf.LibreOffice.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Exporter.Pdf.Tests\LINGYUN.Abp.Exporter.Pdf.Tests.csproj" />
</ItemGroup>
</Project>

24
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests.sln

@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests", "LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests.csproj", "{F760B606-3243-2655-8219-F8799FFAE4AF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F760B606-3243-2655-8219-F8799FFAE4AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F760B606-3243-2655-8219-F8799FFAE4AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F760B606-3243-2655-8219-F8799FFAE4AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F760B606-3243-2655-8219-F8799FFAE4AF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E1CB4316-1F23-4B1A-B67C-322A416FD6F5}
EndGlobalSection
EndGlobal

6
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeTestBase.cs

@ -0,0 +1,6 @@
using LINGYUN.Abp.Tests;
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice;
public abstract class AbpExporterPdfLibreOfficeTestBase : AbpTestsBase<AbpExporterPdfLibreOfficeTestsModule>
{
}

20
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeTestsModule.cs

@ -0,0 +1,20 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice;
[DependsOn(
typeof(AbpExporterPdfLibreOfficeModule),
typeof(AbpExporterPdfTestsModule),
typeof(AbpAutofacModule))]
public class AbpExporterPdfLibreOfficeTestsModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
if (!LibreOfficeCommands.IsLibreOffliceInstalled())
{
context.Services.AddSingleton<LibreOfficeTestEnvironment>();
}
}
}

5
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.LibreOffice.Tests/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOffice_Tests.cs

@ -0,0 +1,5 @@
namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice;
public class AbpExporterPdfLibreOffice_Tests : ExcelToPdfProvider_Tests<AbpExporterPdfLibreOfficeTestsModule>
{
}

20
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests.csproj

@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace />
<IsPackable>false</IsPackable>
<Configurations>Debug;Release</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\exporter\LINGYUN.Abp.Exporter.Pdf.SpireLib\LINGYUN.Abp.Exporter.Pdf.SpireLib.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.Exporter.Pdf.Tests\LINGYUN.Abp.Exporter.Pdf.Tests.csproj" />
</ItemGroup>
</Project>

6
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN/Abp/Exporter/Pdf/SpireLib/AbpExporterPdfSpireLibTestBase.cs

@ -0,0 +1,6 @@
using LINGYUN.Abp.Tests;
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib;
public abstract class AbpExporterPdfSpireLibTestBase : AbpTestsBase<AbpExporterPdfSpireLibTestsModule>
{
}

12
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN/Abp/Exporter/Pdf/SpireLib/AbpExporterPdfSpireLibTestsModule.cs

@ -0,0 +1,12 @@
using Volo.Abp.Autofac;
using Volo.Abp.Modularity;
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib;
[DependsOn(
typeof(AbpExporterPdfSpireLibModule),
typeof(AbpExporterPdfTestsModule),
typeof(AbpAutofacModule))]
public class AbpExporterPdfSpireLibTestsModule : AbpModule
{
}

5
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.SpireLib.Tests/LINGYUN/Abp/Exporter/Pdf/SpireLib/AbpExporterSpireLibOffice_Tests.cs

@ -0,0 +1,5 @@
namespace LINGYUN.Abp.Exporter.Pdf.SpireLib;
public class AbpExporterSpireLibOffice_Tests : ExcelToPdfProvider_Tests<AbpExporterPdfSpireLibTestsModule>
{
}

25
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN.Abp.Exporter.Pdf.Tests.csproj

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
<IsPackable>false</IsPackable>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<None Remove="LINGYUN\Abp\Exporter\Pdf\Resources\test.xlsx" />
<EmbeddedResource Include="LINGYUN\Abp\Exporter\Pdf\Resources\test.xlsx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\framework\exporter\LINGYUN.Abp.Exporter.Pdf\LINGYUN.Abp.Exporter.Pdf.csproj" />
<ProjectReference Include="..\LINGYUN.Abp.TestBase\LINGYUN.Abp.TestsBase.csproj" />
</ItemGroup>
</Project>

8
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/AbpExporterPdfTestBase.cs

@ -0,0 +1,8 @@
using Volo.Abp.Modularity;
using Volo.Abp.Testing;
namespace LINGYUN.Abp.Exporter.Pdf;
public abstract class AbpExporterPdfTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
}

20
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/AbpExporterPdfTestsModule.cs

@ -0,0 +1,20 @@
using LINGYUN.Abp.Tests;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
namespace LINGYUN.Abp.Exporter.Pdf;
[DependsOn(
typeof(AbpVirtualFileSystemModule),
typeof(AbpExporterPdfModule),
typeof(AbpTestsBaseModule))]
public class AbpExporterPdfTestsModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpExporterPdfTestsModule>();
});
}
}

34
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/ExcelToPdfProvider_Tests.cs

@ -0,0 +1,34 @@
using Shouldly;
using System.IO;
using System.Threading.Tasks;
using Volo.Abp.IO;
using Volo.Abp.Modularity;
using Volo.Abp.VirtualFileSystem;
using Xunit;
namespace LINGYUN.Abp.Exporter.Pdf;
public abstract class ExcelToPdfProvider_Tests<TStartupModule> : AbpExporterPdfTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly IExcelToPdfProvider _excelToPdfProvider;
private readonly IVirtualFileProvider _virtualFileProvider;
public ExcelToPdfProvider_Tests()
{
_excelToPdfProvider = GetRequiredService<IExcelToPdfProvider>();
_virtualFileProvider = GetRequiredService<IVirtualFileProvider>();
}
[Fact]
public async virtual Task Should_Parsed()
{
var excelFileInfo = _virtualFileProvider.GetFileInfo("/LINGYUN/Abp/Exporter/Pdf/Resources/test.xlsx");
using (var excelStream = excelFileInfo.CreateReadStream())
{
using (var pdfStream = await _excelToPdfProvider.ParseAsync(excelStream))
{
pdfStream.Seek(0, System.IO.SeekOrigin.Begin);
pdfStream.Length.ShouldBePositive();
}
}
}
}

BIN
aspnet-core/tests/LINGYUN.Abp.Exporter.Pdf.Tests/LINGYUN/Abp/Exporter/Pdf/Resources/test.xlsx

Binary file not shown.
Loading…
Cancel
Save