public void TestMethod4() { string testMethodName = MethodBase.GetCurrentMethod().Name; string testingFolderName = GetAppPath(); Encoding enc = Encoding.GetEncoding("utf-8"); string inputCsvPath; { string inputCsvFileName = testMethodName + ".CSV"; inputCsvPath = Path.Combine(testingFolderName, inputCsvFileName); string[] lines = new string[] { "1a,\"1,b\",1c", "2a,,2c,2d", "3a, " }; File.WriteAllLines(inputCsvPath, lines, enc); } string outputXlsxPath; { string outputXlsxFileName = testMethodName + ".xlsx"; outputXlsxPath = Path.Combine(testingFolderName, outputXlsxFileName); } ConvertCsvToXlsx.Program.Request request = new ConvertCsvToXlsx.Program.Request(); { request.InputCsvFileNameByArgs = inputCsvPath; request.InputCsvEncoding = enc.WebName; request.InputCsvSkipFirstRow = true; request.OutputXlsxFileNameByArgs = outputXlsxPath; } { var target = new PrivateType(typeof(ConvertCsvToXlsx.Program)); target.InvokeStatic("MainProcess", request); } using (var workbook = new XLWorkbook(outputXlsxPath)) { string sheetName = Path.GetFileName(outputXlsxPath); var worksheet = workbook.Worksheet(sheetName); var outputXlsxTable = worksheet.RangeUsed().AsTable(); Assert.AreEqual(2, outputXlsxTable.RowCount()); Assert.AreEqual("2a", worksheet.Cell(1, 1).Value); Assert.AreEqual("", worksheet.Cell(1, 2).Value); Assert.AreEqual("2c", worksheet.Cell(1, 3).Value); Assert.AreEqual("3a", worksheet.Cell(2, 1).Value); Assert.AreEqual(" ", worksheet.Cell(2, 2).Value); Assert.AreEqual("", worksheet.Cell(2, 3).Value); } File.Delete(inputCsvPath); File.Delete(outputXlsxPath); }
public void TestMethod5() { string testMethodName = MethodBase.GetCurrentMethod().Name; string testingFolderName = GetAppPath(); Encoding enc = Encoding.GetEncoding("Shift_JIS"); string inputCsvPath; { string inputCsvFileName = testMethodName + ".CSV"; inputCsvPath = Path.Combine(testingFolderName, inputCsvFileName); string[] lines = new string[] { "12:34:56 , 0:0 , 23:59:59 , -00:00, 24:00", "2000/02/29 , 1900/1/1 , 2999/12/31 , 2000-01-01, 1999/02/29", "2000/02/29 12:34:56, 1900/1/1 0:0, 2999/12/31 23:59:59, 2000/01/01 00:00:60", "True , false , TRUE , falsE, TRUE/FALSE", "-1.2345678901234567, -0 , 123456789012345678 , 12345678" }; File.WriteAllLines(inputCsvPath, lines, enc); } string outputXlsxPath; { string outputXlsxFileName = testMethodName + ".xlsx"; outputXlsxPath = Path.Combine(testingFolderName, outputXlsxFileName); } ConvertCsvToXlsx.Program.Request request = new ConvertCsvToXlsx.Program.Request(); { request.InputCsvFileNameByArgs = inputCsvPath; request.InputCsvEncoding = enc.WebName; request.OutputXlsxFileNameByArgs = outputXlsxPath; } { var target = new PrivateType(typeof(ConvertCsvToXlsx.Program)); target.InvokeStatic("MainProcess", request); } using (var workbook = new XLWorkbook(outputXlsxPath)) { string sheetName = Path.GetFileName(outputXlsxPath); var worksheet = workbook.Worksheet(sheetName); var outputXlsxTable = worksheet.RangeUsed().AsTable(); Assert.AreEqual(new TimeSpan(12, 34, 56), TimeSpan.FromDays(worksheet.Cell(1, 1).GetValue <double>())); Assert.AreEqual(new TimeSpan(00, 00, 00), TimeSpan.FromDays(worksheet.Cell(1, 2).GetValue <double>())); Assert.AreEqual(new TimeSpan(23, 59, 59), TimeSpan.FromDays(worksheet.Cell(1, 3).GetValue <double>())); Assert.AreEqual(" -00:00", worksheet.Cell(1, 4).GetValue <string>()); Assert.AreEqual(" 24:00", worksheet.Cell(1, 5).GetValue <string>()); Assert.AreEqual(new DateTime(2000, 02, 29), worksheet.Cell(2, 1).GetValue <DateTime>()); Assert.AreEqual(new DateTime(1900, 01, 01), worksheet.Cell(2, 2).GetValue <DateTime>()); Assert.AreEqual(new DateTime(2999, 12, 31), worksheet.Cell(2, 3).GetValue <DateTime>()); Assert.AreEqual(new DateTime(2000, 01, 01), worksheet.Cell(2, 4).GetValue <DateTime>()); Assert.AreEqual(" 1999/02/29", worksheet.Cell(2, 5).GetValue <string>()); Assert.AreEqual(new DateTime(2000, 02, 29, 12, 34, 56), worksheet.Cell(3, 1).GetValue <DateTime>()); Assert.AreEqual(new DateTime(1900, 01, 01, 00, 00, 00), worksheet.Cell(3, 2).GetValue <DateTime>()); Assert.AreEqual(new DateTime(2999, 12, 31, 23, 59, 59), worksheet.Cell(3, 3).GetValue <DateTime>()); Assert.AreEqual(" 2000/01/01 00:00:60", worksheet.Cell(3, 4).GetValue <string>()); Assert.AreEqual(true, worksheet.Cell(4, 1).GetValue <bool>()); Assert.AreEqual(false, worksheet.Cell(4, 2).GetValue <bool>()); Assert.AreEqual(true, worksheet.Cell(4, 3).GetValue <bool>()); Assert.AreEqual(false, worksheet.Cell(4, 4).GetValue <bool>()); Assert.AreEqual(" TRUE/FALSE", worksheet.Cell(4, 5).GetValue <string>()); Assert.AreEqual(-1.2345678901234600m, worksheet.Cell(5, 1).GetValue <decimal>()); // Excelの仕様で15桁目以降に誤差が生じる Assert.AreEqual(0m, worksheet.Cell(5, 2).GetValue <decimal>()); Assert.AreEqual(123456789012346000m, worksheet.Cell(5, 3).GetValue <decimal>()); // Excelの仕様で15桁目以降に誤差が生じる Assert.AreEqual(" 12345678", worksheet.Cell(5, 4).GetValue <string>()); } File.Delete(inputCsvPath); File.Delete(outputXlsxPath); }