11using System . ComponentModel ;
22using System . Text . RegularExpressions ;
3+ using MiniExcelLib . Core . Enums ;
34using MiniExcelLib . Core . Exceptions ;
45using MiniExcelLib . Core . OpenXml . Picture ;
56using MiniExcelLib . Core . OpenXml . Utils ;
@@ -16,44 +17,7 @@ public class MiniExcelIssueTests(ITestOutputHelper output)
1617 private readonly OpenXmlExporter _excelExporter = MiniExcel . Exporters . GetOpenXmlExporter ( ) ;
1718 private readonly OpenXmlTemplater _excelTemplater = MiniExcel . Templaters . GetOpenXmlTemplater ( ) ;
1819
19- // private readonly OpenXmlImporter _csvImporter = MiniExcel.Importer.GetCsvImporter();
20- // private readonly OpenXmlExporter _csvExporter = MiniExcel.Exporter.GetCsvExporter();
21-
22- [ Theory ]
23- [ InlineData ( "DateTimeMidnight" , DateOnlyConversionMode . None , true ) ]
24- [ InlineData ( "DateTimeNotMidnight" , DateOnlyConversionMode . None , true ) ]
25- [ InlineData ( "DateTimeMidnight" , DateOnlyConversionMode . EnforceMidnight , false ) ]
26- [ InlineData ( "DateTimeNotMidnight" , DateOnlyConversionMode . EnforceMidnight , true ) ]
27- [ InlineData ( "DateTimeMidnight" , DateOnlyConversionMode . IgnoreTimePart , false ) ]
28- [ InlineData ( "DateTimeNotMidnight" , DateOnlyConversionMode . IgnoreTimePart , false ) ]
29- public void TestIssue869 ( string fileName , DateOnlyConversionMode mode , bool throwsException )
30- {
31- var path = PathHelper . GetFile ( $ "xlsx/TestIssue869/{ fileName } .xlsx") ;
32- var config = new OpenXmlConfiguration { DateOnlyConversionMode = mode } ;
33- var testFn = ( ) => _excelImporter . Query < DateTimeSheet > ( path , configuration : config ) . ToList ( ) ;
34- if ( throwsException )
35- {
36- Assert . Throws < MiniExcelInvalidCastException > ( testFn ) ;
37- }
38- else
39- {
40- try
41- {
42- _ = testFn ( ) ;
43- }
44- catch ( Exception ex )
45- {
46- Assert . Fail ( $ "No exception should be thrown, but still one was thrown: { ex . Message } .") ;
47- }
48- }
49- }
5020
51- private class DateTimeSheet
52- {
53- public string ? Name { get ; set ; }
54- public DateOnly ? Date { get ; set ; }
55- }
56-
5721 /// <summary>
5822 /// https://github.com/mini-software/MiniExcel/issues/549
5923 /// </summary>
@@ -3688,4 +3652,41 @@ public void TestIssue809()
36883652 Assert . Equal ( null , rows [ 0 ] . A ) ;
36893653 Assert . Equal ( 2 , rows [ 2 ] . B ) ;
36903654 }
3655+
3656+
3657+ private class Issue869
3658+ {
3659+ public string ? Name { get ; set ; }
3660+ public DateOnly ? Date { get ; set ; }
3661+ }
3662+
3663+ [ Theory ]
3664+ [ InlineData ( "DateTimeMidnight" , DateOnlyConversionMode . None , true ) ]
3665+ [ InlineData ( "DateTimeNotMidnight" , DateOnlyConversionMode . None , true ) ]
3666+ [ InlineData ( "DateTimeMidnight" , DateOnlyConversionMode . RequireMidnight , false ) ]
3667+ [ InlineData ( "DateTimeNotMidnight" , DateOnlyConversionMode . RequireMidnight , true ) ]
3668+ [ InlineData ( "DateTimeMidnight" , DateOnlyConversionMode . IgnoreTimePart , false ) ]
3669+ [ InlineData ( "DateTimeNotMidnight" , DateOnlyConversionMode . IgnoreTimePart , false ) ]
3670+ public void TestIssue869 ( string fileName , DateOnlyConversionMode mode , bool throwsException )
3671+ {
3672+ var path = PathHelper . GetFile ( $ "xlsx/TestIssue869/{ fileName } .xlsx") ;
3673+ var config = new OpenXmlConfiguration { DateOnlyConversionMode = mode } ;
3674+
3675+ var testFn = ( ) => _excelImporter . Query < Issue869 > ( path , configuration : config ) . ToList ( ) ;
3676+ if ( throwsException )
3677+ {
3678+ Assert . Throws < MiniExcelInvalidCastException > ( testFn ) ;
3679+ }
3680+ else
3681+ {
3682+ try
3683+ {
3684+ _ = testFn ( ) ;
3685+ }
3686+ catch ( Exception ex )
3687+ {
3688+ Assert . Fail ( $ "No exception should be thrown, but one was still thrown: { ex } .") ;
3689+ }
3690+ }
3691+ }
36913692}
0 commit comments