Skip to content

Commit

Permalink
Merge pull request #143 from donnytian/develop
Browse files Browse the repository at this point in the history
upgrade npoi, nunit and actions
  • Loading branch information
donnytian authored Nov 16, 2024
2 parents 1de5f33 + 337b5b6 commit 2c9215a
Show file tree
Hide file tree
Showing 13 changed files with 281 additions and 278 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Restore dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
runs-on: ubuntu-latest
environment: nuget-publish # Configured in Settings > Environments
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v2
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.x
- name: Restore dependencies
Expand Down
6 changes: 3 additions & 3 deletions Npoi.Mapper/src/Npoi.Mapper/Npoi.Mapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageTags>Excel;XLS;XLSX;NPOI;object mapping;dynamic object mapping</PackageTags>
<PackageProjectUrl>https://donnytian.github.io/Npoi.Mapper/</PackageProjectUrl>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>6.2.1</Version>
<Version>6.2.2</Version>
<PackageReleaseNotes>Support net472 and net6.0</PackageReleaseNotes>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>npoi.mapper.snk</AssemblyOriginatorKeyFile>
Expand All @@ -31,11 +31,11 @@

<ItemGroup>
<PackageReference Include="LogicExtensions" Version="0.0.3" />
<PackageReference Include="NPOI" Version="2.6.2" />
<PackageReference Include="NPOI" Version="2.7.1" />
</ItemGroup>

<ItemGroup Label="SourceLink">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
38 changes: 18 additions & 20 deletions Npoi.Mapper/test/AttributeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public void ColumnAttributeIndexTest()
var objs = importer.Take<SampleClass>(1).ToList();

// Assert
Assert.IsNotNull(objs);
Assert.AreEqual(1, objs.Count);
Assert.That(objs, Is.Not.Null);
Assert.That(objs, Has.Count.EqualTo(1));

var obj = objs[0];
Assert.AreEqual(str, obj.Value.ColumnIndexAttributeProperty);
Assert.That(obj.Value.ColumnIndexAttributeProperty, Is.EqualTo(str));
}

[Test]
Expand All @@ -46,11 +46,11 @@ public void ColumnAttributeNameTest()
var objs = importer.Take<SampleClass>(1).ToList();

// Assert
Assert.IsNotNull(objs);
Assert.AreEqual(1, objs.Count);
Assert.That(objs, Is.Not.Null);
Assert.That(objs.Count, Is.EqualTo(1));

var obj = objs[0];
Assert.AreEqual(str, obj.Value.ColumnNameAttributeProperty);
Assert.That(obj.Value.ColumnNameAttributeProperty, Is.EqualTo(str));
}

[Test]
Expand All @@ -68,25 +68,24 @@ public void DisplayNameTest()
var objs = importer.Take<SampleClass>(1).ToList();

// Assert
Assert.IsNotNull(objs);
Assert.AreEqual(1, objs.Count);
Assert.That(objs, Is.Not.Null);
Assert.That(objs, Has.Count.EqualTo(1));

var obj = objs[0];
Assert.AreEqual(str, obj.Value.DisplayNameProperty);
Assert.That(obj.Value.DisplayNameProperty, Is.EqualTo(str));
}

[Test]
public void UseLastNonBlankValueAttributeTest()
{
// Prepare
var sample = new SampleClass();
var date = DateTime.Now;
const string str1 = "aBC";
const string str2 = "BCD";
var workbook = GetSimpleWorkbook(date, str1);

var header = workbook.GetSheetAt(1).GetRow(0).CreateCell(41);
header.SetCellValue(nameof(sample.UseLastNonBlankValueAttributeProperty));
header.SetCellValue(nameof(SampleClass.UseLastNonBlankValueAttributeProperty));

// Create 4 rows, row 22 and 23 have empty values.
workbook.GetSheetAt(1).CreateRow(21).CreateCell(41).SetCellValue(str1);
Expand All @@ -100,32 +99,31 @@ public void UseLastNonBlankValueAttributeTest()
var objs = importer.Take<SampleClass>(1).ToList();

// Assert
Assert.IsNotNull(objs);
Assert.AreEqual(5, objs.Count);
Assert.That(objs, Is.Not.Null);
Assert.That(objs.Count, Is.EqualTo(5));

var obj = objs[1];
Assert.AreEqual(str1, obj.Value.UseLastNonBlankValueAttributeProperty);
Assert.That(obj.Value.UseLastNonBlankValueAttributeProperty, Is.EqualTo(str1));

obj = objs[2];
Assert.AreEqual(str1, obj.Value.UseLastNonBlankValueAttributeProperty);
Assert.That(obj.Value.UseLastNonBlankValueAttributeProperty, Is.EqualTo(str1));

obj = objs[3];
Assert.AreEqual(str1, obj.Value.UseLastNonBlankValueAttributeProperty);
Assert.That(obj.Value.UseLastNonBlankValueAttributeProperty, Is.EqualTo(str1));

obj = objs[4];
Assert.AreEqual(str2, obj.Value.UseLastNonBlankValueAttributeProperty);
Assert.That(obj.Value.UseLastNonBlankValueAttributeProperty, Is.EqualTo(str2));
}

[Test]
public void IgnoreAttributeTest()
{
// Prepare
var sample = new SampleClass();
var date = DateTime.Now;
const string str1 = "aBC";
var workbook = GetSimpleWorkbook(date, str1);

workbook.GetSheetAt(1).GetRow(0).CreateCell(41).SetCellValue(nameof(sample.IgnoredAttributeProperty));
workbook.GetSheetAt(1).GetRow(0).CreateCell(41).SetCellValue(nameof(SampleClass.IgnoredAttributeProperty));
workbook.GetSheetAt(1).CreateRow(21).CreateCell(41).SetCellValue(str1);

var importer = new Mapper(workbook);
Expand All @@ -134,7 +132,7 @@ public void IgnoreAttributeTest()
var objs = importer.Take<SampleClass>(1).ToList();

// Assert
Assert.IsNull(objs[0].Value.IgnoredAttributeProperty);
Assert.That(objs[0].Value.IgnoredAttributeProperty, Is.Null);
}
}
}
30 changes: 15 additions & 15 deletions Npoi.Mapper/test/CustomResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public void SingleColumnResolverTest()
var objs = mapper.Take<SampleClass>().ToList();

// Assert "Take"
Assert.IsNotNull(objs);
Assert.AreEqual(date1.ToLongDateString() + str1, objs[0].Value.SingleColumnResolverProperty);
Assert.That(objs, Is.Not.Null);
Assert.That(objs[0].Value.SingleColumnResolverProperty, Is.EqualTo(date1.ToLongDateString() + str1));

// Act "Put"
objs[0].Value.SingleColumnResolverProperty = date1.ToLongDateString() + str2;
mapper.Put(new[] { objs[0].Value });

// Assert "Put"
Assert.AreEqual(str2, sheet.GetRow(1).GetCell(51).StringCellValue);
Assert.That(sheet.GetRow(1).GetCell(51).StringCellValue, Is.EqualTo(str2));
}

[Test]
Expand Down Expand Up @@ -148,18 +148,18 @@ public void MultiColumnContainerTest()
var objs = mapper.Take<SampleClass>(1).ToList();

// Assert
Assert.IsNotNull(objs);
Assert.AreEqual(1, objs.Count);
Assert.That(objs, Is.Not.Null);
Assert.That(objs.Count, Is.EqualTo(1));

var obj = objs[0];

Assert.AreEqual(2, obj.Value.CollectionGenericProperty.Count);
Assert.That(obj.Value.CollectionGenericProperty.Count, Is.EqualTo(2));

var list = obj.Value.CollectionGenericProperty.ToList();

// Assert Take
Assert.AreEqual(date1.ToLongDateString() + str1, list[0]);
Assert.AreEqual(date2.ToLongDateString() + str2, list[1]);
Assert.That(list[0], Is.EqualTo(date1.ToLongDateString() + str1));
Assert.That(list[1], Is.EqualTo(date2.ToLongDateString() + str2));

// Act Put
obj.Value.CollectionGenericProperty.Clear();
Expand All @@ -169,8 +169,8 @@ public void MultiColumnContainerTest()

// Assert "Put"
var sheet = workbook.GetSheetAt(1);
Assert.AreEqual(str3, sheet.GetRow(1).GetCell(31).StringCellValue);
Assert.AreEqual(str3, sheet.GetRow(1).GetCell(33).StringCellValue);
Assert.That(sheet.GetRow(1).GetCell(31).StringCellValue, Is.EqualTo(str3));
Assert.That(sheet.GetRow(1).GetCell(33).StringCellValue, Is.EqualTo(str3));
}

//https://github.com/donnytian/Npoi.Mapper/issues/23
Expand Down Expand Up @@ -200,7 +200,7 @@ public void WithInvalidEnum_TryTake_ShouldBeCalled()
var items = mapper.Take<SampleClass>().ToList();

// Assert
Assert.AreEqual(SampleEnum.Value3, items[0].Value.EnumProperty);
Assert.That(items[0].Value.EnumProperty, Is.EqualTo(SampleEnum.Value3));
}

//https://github.com/donnytian/Npoi.Mapper/issues/64
Expand Down Expand Up @@ -229,7 +229,7 @@ public void Map_TryTakeDateTimeFromDouble_ShouldGetDateTime()
var items = mapper.Take<SampleClass>().ToList();

// Assert
Assert.AreEqual(value.ToString(format), items[0].Value.DateProperty.ToString(format));
Assert.That(items[0].Value.DateProperty.ToString(format), Is.EqualTo(value.ToString(format)));
}

[Test]
Expand All @@ -252,9 +252,9 @@ public void RowTagForTryTakeTest()
var items = mapper.Take<SampleClass>(1).ToList();

// Assert
Assert.AreEqual(2, items.Count);
Assert.AreEqual("foo", items[0].RowTag);
Assert.AreEqual("bar", items[1].RowTag);
Assert.That(items.Count, Is.EqualTo(2));
Assert.That(items[0].RowTag, Is.EqualTo("foo"));
Assert.That(items[1].RowTag, Is.EqualTo("bar"));
}
}
}
4 changes: 2 additions & 2 deletions Npoi.Mapper/test/ExportCustomResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void ForHeader_ChangeHeaderStyle_ShouldChanged()

// Assert
var row2 = workbook.GetSheetAt(0).GetRow(1);
Assert.AreEqual(120, row1.GetCell(11).CellStyle.LeftBorderColor);
Assert.AreEqual(str1, row2.GetCell(11).StringCellValue);
Assert.That(row1.GetCell(11).CellStyle.LeftBorderColor, Is.EqualTo(120));
Assert.That(row2.GetCell(11).StringCellValue, Is.EqualTo(str1));

}
}
Expand Down
Loading

0 comments on commit 2c9215a

Please sign in to comment.