@@ -6,50 +6,66 @@ namespace Belin.Sql;
66[ TestClass ]
77public sealed class MapperTests {
88
9- [ DataRow ( null , typeof ( bool ) , false , false ) ]
10- [ DataRow ( null , typeof ( bool ? ) , true , null ) ]
11- [ DataRow ( 0 , typeof ( bool ) , false , false ) ]
12- [ DataRow ( 0 , typeof ( bool ? ) , true , false ) ]
13- [ DataRow ( 1 , typeof ( bool ) , false , true ) ]
14- [ DataRow ( 1 , typeof ( bool ? ) , true , true ) ]
15- [ DataRow ( "false" , typeof ( bool ) , false , false ) ]
16- [ DataRow ( "true" , typeof ( bool ) , false , true ) ]
17-
18- [ DataRow ( null , typeof ( char ) , false , char . MinValue ) ]
19- [ DataRow ( null , typeof ( char ? ) , true , null ) ]
20- [ DataRow ( 0 , typeof ( char ) , false , char . MinValue ) ]
21- [ DataRow ( 0 , typeof ( char ? ) , true , char . MinValue ) ]
22- [ DataRow ( 97 , typeof ( char ) , false , 'a' ) ]
23- [ DataRow ( "a" , typeof ( char ) , false , 'a' ) ]
24-
25- [ DataRow ( null , typeof ( double ) , false , 0.0 ) ]
26- [ DataRow ( null , typeof ( double ? ) , true , null ) ]
27- [ DataRow ( 0 , typeof ( double ) , false , 0.0 ) ]
28- [ DataRow ( 0 , typeof ( double ? ) , true , 0.0 ) ]
29- [ DataRow ( 123 , typeof ( double ) , false , 123.0 ) ]
30- [ DataRow ( - 123.456 , typeof ( double ? ) , true , - 123.456 ) ]
31- [ DataRow ( "123" , typeof ( double ) , false , 123.0 ) ]
32- [ DataRow ( "-123.456" , typeof ( double ) , false , - 123.456 ) ]
33-
34- [ DataRow ( null , typeof ( int ) , false , 0 ) ]
35- [ DataRow ( null , typeof ( int ? ) , true , null ) ]
36- [ DataRow ( 0 , typeof ( int ) , false , 0 ) ]
37- [ DataRow ( 0 , typeof ( int ? ) , true , 0 ) ]
38- [ DataRow ( 123 , typeof ( int ) , false , 123 ) ]
39- [ DataRow ( - 123.456 , typeof ( int ? ) , true , - 123 ) ]
40- [ DataRow ( "123" , typeof ( int ) , false , 123 ) ]
41- [ DataRow ( "-123" , typeof ( int ) , false , - 123 ) ]
42-
43- [ DataRow ( null , typeof ( DayOfWeek ) , false , DayOfWeek . Sunday ) ]
44- [ DataRow ( null , typeof ( DayOfWeek ? ) , true , null ) ]
45- [ DataRow ( 0 , typeof ( DayOfWeek ) , false , DayOfWeek . Sunday ) ]
46- [ DataRow ( 0 , typeof ( DayOfWeek ? ) , true , DayOfWeek . Sunday ) ]
47- [ DataRow ( 5 , typeof ( DayOfWeek ) , false , DayOfWeek . Friday ) ]
48- [ DataRow ( 5 , typeof ( DayOfWeek ? ) , true , DayOfWeek . Friday ) ]
49- [ DataRow ( "sunday" , typeof ( DayOfWeek ) , false , DayOfWeek . Sunday ) ]
50- [ DataRow ( "friday" , typeof ( DayOfWeek ) , false , DayOfWeek . Friday ) ]
51-
52- [ TestMethod ]
9+ /// <summary>
10+ /// The test data used by the <see cref="ChangeType"/> method.
11+ /// </summary>
12+ private static IEnumerable < object ? [ ] > TestData => [
13+ [ null , typeof ( bool ) , false , false ] ,
14+ [ null , typeof ( bool ? ) , true , null ] ,
15+ [ 0 , typeof ( bool ) , false , false ] ,
16+ [ 0 , typeof ( bool ? ) , true , false ] ,
17+ [ 1 , typeof ( bool ) , false , true ] ,
18+ [ 1 , typeof ( bool ? ) , true , true ] ,
19+ [ "false" , typeof ( bool ) , false , false ] ,
20+ [ "true" , typeof ( bool ) , false , true ] ,
21+
22+ [ null , typeof ( char ) , false , char . MinValue ] ,
23+ [ null , typeof ( char ? ) , true , null ] ,
24+ [ 0 , typeof ( char ) , false , char . MinValue ] ,
25+ [ 0 , typeof ( char ? ) , true , char . MinValue ] ,
26+ [ 97 , typeof ( char ) , false , 'a' ] ,
27+ [ 98 , typeof ( char ? ) , true , 'b' ] ,
28+ [ "a" , typeof ( char ) , false , 'a' ] ,
29+ [ "b" , typeof ( char ? ) , true , 'b' ] ,
30+
31+ [ null , typeof ( double ) , false , 0.0 ] ,
32+ [ null , typeof ( double ? ) , true , null ] ,
33+ [ 0 , typeof ( double ) , false , 0.0 ] ,
34+ [ 0 , typeof ( double ? ) , true , 0.0 ] ,
35+ [ 123 , typeof ( double ) , false , 123.0 ] ,
36+ [ - 123.456 , typeof ( double ? ) , true , - 123.456 ] ,
37+ [ "123" , typeof ( double ) , false , 123.0 ] ,
38+ [ "-123.456" , typeof ( double ? ) , true , - 123.456 ] ,
39+
40+ [ null , typeof ( DateTime ) , false , DateTime . MinValue ] ,
41+ [ null , typeof ( DateTime ? ) , true , null ] ,
42+ [ DateTime . MinValue , typeof ( DateTime ) , false , DateTime . MinValue ] ,
43+ [ DateTime . MaxValue , typeof ( DateTime ? ) , true , DateTime . MaxValue ] ,
44+ [ new DateTime ( 2025 , 6 , 7 , 10 , 45 , 1 ) , typeof ( DateTime ) , false , new DateTime ( 2025 , 6 , 7 , 10 , 45 , 1 ) ] ,
45+ [ new DateTime ( 2025 , 6 , 7 , 10 , 45 , 1 ) , typeof ( DateTime ? ) , true , new DateTime ( 2025 , 6 , 7 , 10 , 45 , 1 ) ] ,
46+ [ "2025-06-07 10:45:01" , typeof ( DateTime ) , false , new DateTime ( 2025 , 6 , 7 , 10 , 45 , 1 ) ] ,
47+ [ "2025-06-07T10:45:01" , typeof ( DateTime ? ) , true , new DateTime ( 2025 , 6 , 7 , 10 , 45 , 1 ) ] ,
48+
49+ [ null , typeof ( int ) , false , 0 ] ,
50+ [ null , typeof ( int ? ) , true , null ] ,
51+ [ 0 , typeof ( int ) , false , 0 ] ,
52+ [ 0 , typeof ( int ? ) , true , 0 ] ,
53+ [ 123 , typeof ( int ) , false , 123 ] ,
54+ [ - 123.456 , typeof ( int ? ) , true , - 123 ] ,
55+ [ "123" , typeof ( int ) , false , 123 ] ,
56+ [ "-123" , typeof ( int ? ) , true , - 123 ] ,
57+
58+ [ null , typeof ( DayOfWeek ) , false , DayOfWeek . Sunday ] ,
59+ [ null , typeof ( DayOfWeek ? ) , true , null ] ,
60+ [ 0 , typeof ( DayOfWeek ) , false , DayOfWeek . Sunday ] ,
61+ [ 1 , typeof ( DayOfWeek ? ) , true , DayOfWeek . Monday ] ,
62+ [ 5 , typeof ( DayOfWeek ) , false , DayOfWeek . Friday ] ,
63+ [ 6 , typeof ( DayOfWeek ? ) , true , DayOfWeek . Saturday ] ,
64+ [ "sunday" , typeof ( DayOfWeek ) , false , DayOfWeek . Sunday ] ,
65+ [ "friday" , typeof ( DayOfWeek ? ) , true , DayOfWeek . Friday ]
66+ ] ;
67+
68+ [ TestMethod , DynamicData ( nameof ( TestData ) ) ]
5369 public void ChangeType ( object ? value , Type conversionType , bool isNullable , object ? expected ) =>
5470 AreEqual ( expected , new Mapper ( ) . ChangeType ( value , conversionType , isNullable ) ) ;
5571}
0 commit comments