diff --git a/Excely.ClosedXML.UnitTests/Excely.ClosedXML.UnitTests.csproj b/Excely.ClosedXML.UnitTests/Excely.ClosedXML.UnitTests.csproj new file mode 100644 index 0000000..f29ff26 --- /dev/null +++ b/Excely.ClosedXML.UnitTests/Excely.ClosedXML.UnitTests.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + false + true + + + + + + + + + + + + + + + diff --git a/Excely.ClosedXML.UnitTests/GlobalUsings.cs b/Excely.ClosedXML.UnitTests/GlobalUsings.cs new file mode 100644 index 0000000..ab67c7e --- /dev/null +++ b/Excely.ClosedXML.UnitTests/GlobalUsings.cs @@ -0,0 +1 @@ +global using Microsoft.VisualStudio.TestTools.UnitTesting; \ No newline at end of file diff --git a/Excely.ClosedXML.UnitTests/Models/SampleEnum.cs b/Excely.ClosedXML.UnitTests/Models/SampleEnum.cs new file mode 100644 index 0000000..9cf6465 --- /dev/null +++ b/Excely.ClosedXML.UnitTests/Models/SampleEnum.cs @@ -0,0 +1,9 @@ +嚜積amespace Excely.ClosedXML.UnitTests.Models +{ + internal enum SampleEnum + { + Enum1, + Enum2, + Enum3, + } +} diff --git a/Excely.ClosedXML.UnitTests/Models/SimpleClass.cs b/Excely.ClosedXML.UnitTests/Models/SimpleClass.cs new file mode 100644 index 0000000..c90b0ef --- /dev/null +++ b/Excely.ClosedXML.UnitTests/Models/SimpleClass.cs @@ -0,0 +1,10 @@ +嚜積amespace 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; } + } +} diff --git a/Excely.ClosedXML.UnitTests/XlsxTableConverterTests.cs b/Excely.ClosedXML.UnitTests/XlsxTableConverterTests.cs new file mode 100644 index 0000000..ed4dc39 --- /dev/null +++ b/Excely.ClosedXML.UnitTests/XlsxTableConverterTests.cs @@ -0,0 +1,33 @@ +using ClosedXML.Excel; +using Excely.ClosedXML.TableConverters; + +namespace Excely.ClosedXML.UnitTests +{ + [TestClass] + public class XlsxTableConverterTests + { + /// + /// 確保 ClosedXML 在處理字串時不會自動轉型為數字 + /// + [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> + { + new List { "Name", "No" }, + new List { "John", "01" }, + }); + + // Act + converter.ConvertFrom(table); + + // Assert + Assert.AreEqual("01", worksheet.Cell(2,2).Value.ToString()); + } + } +} \ No newline at end of file diff --git a/Excely.sln b/Excely.sln index a0bb6ff..5582e27 100644 --- a/Excely.sln +++ b/Excely.sln @@ -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 @@ -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