Skip to content

Commit

Permalink
新增 ClosedXML 依賴版本測試
Browse files Browse the repository at this point in the history
  • Loading branch information
max committed Jan 15, 2024
1 parent 063a72f commit 8ac5f59
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Excely.ClosedXML.UnitTests/Excely.ClosedXML.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ClosedXML" Version="0.102.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Excely.ClosedXML\Excely.ClosedXML.csproj" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions Excely.ClosedXML.UnitTests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
9 changes: 9 additions & 0 deletions Excely.ClosedXML.UnitTests/Models/SampleEnum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Excely.ClosedXML.UnitTests.Models
{
internal enum SampleEnum
{
Enum1,
Enum2,
Enum3,
}
}
10 changes: 10 additions & 0 deletions Excely.ClosedXML.UnitTests/Models/SimpleClass.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Excely.ClosedXML.UnitTests.Models
{
internal class SimpleClass
{
public int IntValue { get; set; }
public string StrigValue { get; set; } = "";
public DateTime DateTimeValue { get; set; }
public SampleEnum EnumValue { get; set; }
}
}
33 changes: 33 additions & 0 deletions Excely.ClosedXML.UnitTests/XlsxTableConverterTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using ClosedXML.Excel;
using Excely.ClosedXML.TableConverters;

namespace Excely.ClosedXML.UnitTests
{
[TestClass]
public class XlsxTableConverterTests
{
/// <summary>
/// 確保 ClosedXML 在處理字串時不會自動轉型為數字
/// </summary>
[TestMethod]
public void ConvertPaddingStartWith0Data_ShouldReturnExcelWithCurrectData()
{
// Arrange
using var workbook = new XLWorkbook();
var worksheet = workbook.AddWorksheet("sheet1");

var converter = new XlsxTableConverter(worksheet);
var table = new ExcelyTable(new List<IList<object?>>
{
new List<object?> { "Name", "No" },
new List<object?> { "John", "01" },
});

// Act
converter.ConvertFrom(table);

// Assert
Assert.AreEqual("01", worksheet.Cell(2,2).Value.ToString());
}
}
}
6 changes: 6 additions & 0 deletions Excely.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excely.UnitTests", "Excely.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Excely.ClosedXML", "Excely.ClosedXML\Excely.ClosedXML.csproj", "{C3137C4B-EBA0-4720-8B29-7C0B0202A55F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Excely.ClosedXML.UnitTests", "Excely.ClosedXML.UnitTests\Excely.ClosedXML.UnitTests.csproj", "{075DACAA-3E1D-46E6-B094-0E119B56673B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -33,6 +35,10 @@ Global
{C3137C4B-EBA0-4720-8B29-7C0B0202A55F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3137C4B-EBA0-4720-8B29-7C0B0202A55F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3137C4B-EBA0-4720-8B29-7C0B0202A55F}.Release|Any CPU.Build.0 = Release|Any CPU
{075DACAA-3E1D-46E6-B094-0E119B56673B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{075DACAA-3E1D-46E6-B094-0E119B56673B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{075DACAA-3E1D-46E6-B094-0E119B56673B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{075DACAA-3E1D-46E6-B094-0E119B56673B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 8ac5f59

Please sign in to comment.