Skip to content

Commit df202d1

Browse files
committed
TimeOnlys.ConstructorTest: Add hours overflow test
1 parent 7c30810 commit df202d1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Orm/Xtensive.Orm.Tests/Linq/DateTimeAndDateTimeOffset/TimeOnly/ConstructorTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,37 @@ public void TicksFromColumnsBasedExpressionMilliseconds()
188188
Assert.That(result.Count, Is.EqualTo(1));
189189
});
190190
}
191+
192+
[Test]
193+
public void HourOverflowTest()
194+
{
195+
Require.ProviderIsNot(StorageProvider.MySql | StorageProvider.Sqlite,
196+
"These providers don't throw exceptions on hour value overflow but return NULL or Max possible value, so no support for time constructor");
197+
198+
var ticksPerHour = new TimeOnly(1, 0).Ticks;
199+
var testTicks = FirstMillisecondTimeOnly.Hour + ticksPerHour * 25;
200+
201+
_ = Assert.Throws<ArgumentOutOfRangeException>(() => new TimeOnly(testTicks));
202+
203+
ExecuteInsideSession((s) => {
204+
_ = Assert.Throws(GetExceptionType(),
205+
() => s.Query.All<AllPossiblePartsEntity>()
206+
.Select(e => new {
207+
Entity = e,
208+
ConstructedTime = new TimeOnly(e.Hour + ticksPerHour * 25)
209+
})
210+
.Where(a => a.ConstructedTime == FirstMillisecondTimeOnly)
211+
.OrderBy(a => a.Entity.Id).Run());
212+
});
213+
214+
static Type GetExceptionType()
215+
{
216+
return StorageProviderInfo.Instance.Provider switch {
217+
StorageProvider.SqlServer => typeof(SyntaxErrorException),
218+
_ => typeof(StorageException)
219+
};
220+
}
221+
}
191222
}
192223
}
193224
#endif

0 commit comments

Comments
 (0)