Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#549-Excel中缺少列时,应返回空和错误,不应该空指针异常 #551

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ steps:
inputs:
packageType: 'sdk'
version: '7.x'

- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.x'

# 不再进行多框架全面测试
#- task: UseDotNet@2
Expand Down
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.7.5.0</Version>
<Version>2.7.5.1</Version>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<NoWarn>1591</NoWarn>
Expand Down
2 changes: 2 additions & 0 deletions src/Magicodes.ExporterAndImporter.Core/Models/ImportResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ImportResultEnumer<T> where T : class
/// </summary>
public ImportResultEnumer()
{
Data = new List<T>();
RowErrors = new List<DataRowErrorInfo>();
}

Expand Down Expand Up @@ -70,6 +71,7 @@ public class ImportResult<T> where T : class
/// </summary>
public ImportResult()
{
Data = new List<T>();
RowErrors = new List<DataRowErrorInfo>();
}

Expand Down
10 changes: 10 additions & 0 deletions src/Magicodes.ExporterAndImporter.Tests/ExcelImporter_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Issue549>(filePath);

import.HasError.ShouldBeTrue();
import.Data.Count.ShouldBe(0);
}
}
}
15 changes: 15 additions & 0 deletions src/Magicodes.ExporterAndImporter.Tests/Models/Import/Issue549.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
Binary file not shown.
Loading