diff --git a/azure-pipelines.yml b/azure-pipelines.yml index cbf06b79..1950ddfe 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -47,6 +47,11 @@ steps: inputs: packageType: 'sdk' version: '7.x' + +- task: UseDotNet@2 + inputs: + packageType: 'sdk' + version: '8.x' # 不再进行多框架全面测试 #- task: UseDotNet@2 diff --git a/common.props b/common.props index 1c646287..0195c11f 100644 --- a/common.props +++ b/common.props @@ -1,6 +1,6 @@ - 2.7.5.0 + 2.7.5.1 true snupkg 1591 diff --git a/src/Magicodes.ExporterAndImporter.Core/Models/ImportResult.cs b/src/Magicodes.ExporterAndImporter.Core/Models/ImportResult.cs index 488b2d67..ad077fd3 100644 --- a/src/Magicodes.ExporterAndImporter.Core/Models/ImportResult.cs +++ b/src/Magicodes.ExporterAndImporter.Core/Models/ImportResult.cs @@ -23,6 +23,7 @@ public class ImportResultEnumer where T : class /// public ImportResultEnumer() { + Data = new List(); RowErrors = new List(); } @@ -70,6 +71,7 @@ public class ImportResult where T : class /// public ImportResult() { + Data = new List(); RowErrors = new List(); } diff --git a/src/Magicodes.ExporterAndImporter.Tests/ExcelImporter_Tests.cs b/src/Magicodes.ExporterAndImporter.Tests/ExcelImporter_Tests.cs index dc7110e7..146201bf 100644 --- a/src/Magicodes.ExporterAndImporter.Tests/ExcelImporter_Tests.cs +++ b/src/Magicodes.ExporterAndImporter.Tests/ExcelImporter_Tests.cs @@ -1210,5 +1210,15 @@ public async Task Issue377_Test() import.HasError.ShouldBeFalse(); import.Data.Count.ShouldBe(3); } + + [Fact(DisplayName = "#549-Excel中缺少列时,应返回空和错误,不应该空指针异常")] + public async Task MissingField_Test() + { + var filePath = Path.Combine(Directory.GetCurrentDirectory(), "TestFiles", "Import", "Issue549.xlsx"); + var import = await Importer.Import(filePath); + + import.HasError.ShouldBeTrue(); + import.Data.Count.ShouldBe(0); + } } } \ No newline at end of file diff --git a/src/Magicodes.ExporterAndImporter.Tests/Models/Import/Issue549.cs b/src/Magicodes.ExporterAndImporter.Tests/Models/Import/Issue549.cs new file mode 100644 index 00000000..4567c48a --- /dev/null +++ b/src/Magicodes.ExporterAndImporter.Tests/Models/Import/Issue549.cs @@ -0,0 +1,15 @@ +using Magicodes.ExporterAndImporter.Core; + +namespace Magicodes.IE.Tests.Models.Import; + +public class Issue549 +{ + [ImporterHeader(Name = "姓名", AutoTrim = true)] + public string Name { get; set; } + + [ImporterHeader(Name = "年龄", AutoTrim = true)] + public decimal Age { get; set; } + + [ImporterHeader(Name = "身高", AutoTrim = true)] + public decimal Height { get; set; } +} diff --git a/src/Magicodes.ExporterAndImporter.Tests/TestFiles/Import/Issue549.xlsx b/src/Magicodes.ExporterAndImporter.Tests/TestFiles/Import/Issue549.xlsx new file mode 100644 index 00000000..5580afdd Binary files /dev/null and b/src/Magicodes.ExporterAndImporter.Tests/TestFiles/Import/Issue549.xlsx differ