@@ -22,7 +22,8 @@ public void CtorHMSM()
2222 . Select ( e => new {
2323 Entity = e ,
2424 ConstructedTime = new TimeOnly ( e . Hour , e . Minute , e . Second , e . Millisecond ) } )
25- . Where ( a => a . ConstructedTime == FirstMillisecondTimeOnly ) . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
25+ . Where ( a => a . ConstructedTime == FirstMillisecondTimeOnly )
26+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
2627 Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
2728 } ) ;
2829 }
@@ -36,7 +37,8 @@ public void CtorHMS()
3637 Entity = e ,
3738 ConstructedTime = new TimeOnly ( e . Hour , e . Minute , e . Second )
3839 } )
39- . Where ( a => a . ConstructedTime == FirstTimeOnly ) . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
40+ . Where ( a => a . ConstructedTime == FirstTimeOnly )
41+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
4042 Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
4143 } ) ;
4244 }
@@ -52,6 +54,140 @@ public void CtorHM()
5254 Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
5355 } ) ;
5456 }
57+
58+ [ Test ]
59+ public void CtorTicksLiteralValue ( )
60+ {
61+ var ticksPerHour = new TimeOnly ( 1 , 0 ) . Ticks ;
62+ var ticksPerMinute = new TimeOnly ( 0 , 1 ) . Ticks ;
63+ var ticksPerSecond = new TimeOnly ( 0 , 0 , 1 ) . Ticks ;
64+ var testTicks = ticksPerHour * FirstTimeOnly . Hour +
65+ ticksPerMinute * FirstTimeOnly . Minute +
66+ ticksPerSecond * FirstTimeOnly . Second ;
67+
68+ ExecuteInsideSession ( ( s ) => {
69+ var result = s . Query . All < AllPossiblePartsEntity > ( )
70+ . Select ( e => new { Entity = e , ConstructedTime = new TimeOnly ( testTicks ) } )
71+ . Where ( a => a . ConstructedTime == FirstTimeOnly )
72+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
73+ Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
74+ } ) ;
75+ }
76+
77+ [ Test ]
78+ public void CtorTicksLiteralExpressions ( )
79+ {
80+ var ticksPerHour = new TimeOnly ( 1 , 0 ) . Ticks ;
81+ var ticksPerMinute = new TimeOnly ( 0 , 1 ) . Ticks ;
82+ var ticksPerSecond = new TimeOnly ( 0 , 0 , 1 ) . Ticks ;
83+ var testTicks = ticksPerHour * FirstTimeOnly . Hour +
84+ ticksPerMinute * FirstTimeOnly . Minute +
85+ ticksPerSecond * FirstTimeOnly . Second ;
86+
87+ ExecuteInsideSession ( ( s ) => {
88+ var result = s . Query . All < AllPossiblePartsEntity > ( )
89+ . Select ( e => new { Entity = e , ConstructedTime = new TimeOnly ( testTicks + 1000 - 1000 ) } )
90+ . Where ( a => a . ConstructedTime == FirstTimeOnly )
91+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
92+ Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
93+ } ) ;
94+ }
95+
96+ [ Test ]
97+ public void CtorTicksFromIntervalTicks ( )
98+ {
99+ Require . ProviderIsNot ( StorageProvider . MySql ) ;
100+
101+ ExecuteInsideSession ( ( s ) => {
102+ var result = s . Query . All < AllPossiblePartsEntity > ( )
103+ . Select ( e => new { Entity = e , ConstructedTime = new TimeOnly ( e . TimeSpan . Ticks ) } )
104+ . Where ( a => a . ConstructedTime == FirstMillisecondTimeOnly )
105+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
106+ Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
107+ } ) ;
108+ }
109+
110+ [ Test ]
111+ public void MysqlCtorTicksFromIntervalTicks ( )
112+ {
113+ Require . ProviderIs ( StorageProvider . MySql ) ;
114+
115+ if ( StorageProviderInfo . Instance . Info . StorageVersion <= StorageProviderVersion . MySql55 ) {
116+ ExecuteInsideSession ( ( s ) => {
117+ var result = s . Query . All < AllPossiblePartsEntity > ( )
118+ . Select ( e => new { Entity = e , ConstructedTime = new TimeOnly ( e . TimeSpan . Ticks ) } )
119+ . Where ( a => a . ConstructedTime == FirstTimeOnly )
120+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
121+ Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
122+ } ) ;
123+ }
124+ else {
125+ ExecuteInsideSession ( ( s ) => {
126+ var result = s . Query . All < AllPossiblePartsEntity > ( )
127+ . Select ( e => new { Entity = e , ConstructedTime = new TimeOnly ( e . TimeSpan . Ticks ) } )
128+ . Where ( a => a . ConstructedTime == FirstMillisecondTimeOnly )
129+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
130+ Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
131+ } ) ;
132+ }
133+ }
134+
135+ [ Test ]
136+ public void TicksFromColumnsBasedExpression ( )
137+ {
138+ var ticksPerHour = new TimeOnly ( 1 , 0 ) . Ticks ;
139+ var ticksPerMinute = new TimeOnly ( 0 , 1 ) . Ticks ;
140+ var ticksPerSecond = new TimeOnly ( 0 , 0 , 1 ) . Ticks ;
141+ var testTicks = ticksPerHour * FirstTimeOnly . Hour +
142+ ticksPerMinute * FirstTimeOnly . Minute +
143+ ticksPerSecond * FirstTimeOnly . Second ;
144+
145+ Assert . That ( new TimeOnly ( testTicks ) . Ticks , Is . EqualTo ( testTicks ) ) ;
146+ Assert . That ( new TimeOnly ( testTicks ) , Is . EqualTo ( FirstTimeOnly ) ) ;
147+
148+ ExecuteInsideSession ( ( s ) => {
149+ var result = s . Query . All < AllPossiblePartsEntity > ( )
150+ . Select ( e => new {
151+ Entity = e ,
152+ ConstructedTime = new TimeOnly ( e . Hour * ticksPerHour + e . Minute * ticksPerMinute + e . Second * ticksPerSecond )
153+ } )
154+ . Where ( a => a . ConstructedTime == FirstTimeOnly )
155+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
156+ Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
157+ } ) ;
158+ }
159+
160+ [ Test ]
161+ public void TicksFromColumnsBasedExpressionMilliseconds ( )
162+ {
163+ if ( StorageProviderInfo . Instance . CheckProviderIs ( StorageProvider . MySql ) ) {
164+ Require . ProviderVersionAtLeast ( StorageProviderVersion . MySql56 ) ;
165+ }
166+
167+ var ticksPerHour = new TimeOnly ( 1 , 0 ) . Ticks ;
168+ var ticksPerMinute = new TimeOnly ( 0 , 1 ) . Ticks ;
169+ var ticksPerSecond = new TimeOnly ( 0 , 0 , 1 ) . Ticks ;
170+ var ticksPerMillisecond = new TimeOnly ( 0 , 0 , 0 , 1 ) . Ticks ;
171+ var testTicks = ticksPerHour * FirstMillisecondTimeOnly . Hour +
172+ ticksPerMinute * FirstMillisecondTimeOnly . Minute +
173+ ticksPerSecond * FirstMillisecondTimeOnly . Second +
174+ ticksPerMillisecond * FirstMillisecondTimeOnly . Millisecond ;
175+
176+ Assert . That ( new TimeOnly ( testTicks ) . Ticks , Is . EqualTo ( testTicks ) ) ;
177+ Assert . That ( new TimeOnly ( testTicks ) , Is . EqualTo ( FirstMillisecondTimeOnly ) ) ;
178+
179+ ExecuteInsideSession ( ( s ) => {
180+ var result = s . Query . All < AllPossiblePartsEntity > ( )
181+ . Select ( e => new {
182+ Entity = e ,
183+ ConstructedTime = new TimeOnly (
184+ e . Hour * ticksPerHour + e . Minute * ticksPerMinute + e . Second * ticksPerSecond + e . Millisecond * ticksPerMillisecond )
185+ } )
186+ . Where ( a => a . ConstructedTime == FirstMillisecondTimeOnly )
187+ . OrderBy ( a => a . Entity . Id ) . ToList ( 3 ) ;
188+ Assert . That ( result . Count , Is . EqualTo ( 1 ) ) ;
189+ } ) ;
190+ }
55191 }
56192}
57193#endif
0 commit comments