From e817431fe7e30b035bead5c124b9df539753d57f Mon Sep 17 00:00:00 2001 From: colin Date: Sat, 21 Jun 2025 18:56:09 +0800 Subject: [PATCH] fix(exporter): fix unit tests --- .../Pdf/LibreOffice/AbpExporterPdfLibreOfficeModule.cs | 5 +++++ .../Exporter/Pdf/LibreOffice/LibreOfficeTestEnvironment.cs | 4 ++++ ...llExcelToPdfProvider.cs => OriginalExcelToPdfProvider.cs} | 5 ++--- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/LibreOfficeTestEnvironment.cs rename aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf/LINGYUN/Abp/Exporter/Pdf/{NullExcelToPdfProvider.cs => OriginalExcelToPdfProvider.cs} (60%) diff --git a/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeModule.cs b/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeModule.cs index d686cbc12..48dd21670 100644 --- a/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeModule.cs +++ b/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/AbpExporterPdfLibreOfficeModule.cs @@ -8,6 +8,11 @@ public class AbpExporterPdfLibreOfficeModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) { + // 解决单元测试问题 + if (context.Services.IsAdded()) + { + return; + } if (!LibreOfficeCommands.IsLibreOffliceInstalled()) { throw new Volo.Abp.AbpInitializationException("Libreoffice not installed in the current operation environment of the host, please refer to the document after installation using ` AbpExporterPdfLibreOfficeModule ` module."); diff --git a/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/LibreOfficeTestEnvironment.cs b/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/LibreOfficeTestEnvironment.cs new file mode 100644 index 000000000..09323204d --- /dev/null +++ b/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf.LibreOffice/LINGYUN/Abp/Exporter/Pdf/LibreOffice/LibreOfficeTestEnvironment.cs @@ -0,0 +1,4 @@ +namespace LINGYUN.Abp.Exporter.Pdf.LibreOffice; +public class LibreOfficeTestEnvironment +{ +} diff --git a/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf/LINGYUN/Abp/Exporter/Pdf/NullExcelToPdfProvider.cs b/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf/LINGYUN/Abp/Exporter/Pdf/OriginalExcelToPdfProvider.cs similarity index 60% rename from aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf/LINGYUN/Abp/Exporter/Pdf/NullExcelToPdfProvider.cs rename to aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf/LINGYUN/Abp/Exporter/Pdf/OriginalExcelToPdfProvider.cs index 293adf18e..8cccfcf34 100644 --- a/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf/LINGYUN/Abp/Exporter/Pdf/NullExcelToPdfProvider.cs +++ b/aspnet-core/framework/exporter/LINGYUN.Abp.Exporter.Pdf/LINGYUN/Abp/Exporter/Pdf/OriginalExcelToPdfProvider.cs @@ -6,11 +6,10 @@ using Volo.Abp.DependencyInjection; namespace LINGYUN.Abp.Exporter.Pdf; [Dependency(TryRegister = true)] -public class NullExcelToPdfProvider : IExcelToPdfProvider, ISingletonDependency +public class OriginalExcelToPdfProvider : IExcelToPdfProvider, ISingletonDependency { - private readonly static Stream _nullStreamCache = Stream.Null; public virtual Task ParseAsync(Stream excelStream, CancellationToken cancellationToken = default) { - return Task.FromResult(_nullStreamCache); + return Task.FromResult(excelStream); } }