Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit f561a01

Browse files
committed
Add test to insert/select max values
1 parent acc118c commit f561a01

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using NUnit.Framework;
3+
using ServiceStack.Common.Tests.Models;
4+
using ServiceStack.Text;
5+
6+
namespace ServiceStack.OrmLite.Tests
7+
{
8+
public class MaxDataTypeTests : OrmLiteTestBase
9+
{
10+
[Test]
11+
public void Can_insert_and_select_max_values()
12+
{
13+
var model = new ModelWithFieldsOfDifferentTypes
14+
{
15+
Int = int.MaxValue,
16+
Long = long.MaxValue,
17+
Double = double.MaxValue,
18+
Decimal = Dialect != Dialect.SqlServer && Dialect != Dialect.SqlServer2012 && Dialect != Dialect.Sqlite
19+
? Decimal.MaxValue
20+
: long.MaxValue,
21+
DateTime = Dialect != Dialect.MySql
22+
? DateTime.MaxValue
23+
: DateTime.MaxValue.AddYears(-1),
24+
TimeSpan = TimeSpan.MaxValue,
25+
};
26+
27+
using (var db = OpenDbConnection())
28+
{
29+
db.DropAndCreateTable<ModelWithFieldsOfDifferentTypes>();
30+
31+
//db.GetLastSql().Print();
32+
33+
var id = db.Insert(model, selectIdentity: true);
34+
35+
var fromDb = db.SingleById<ModelWithFieldsOfDifferentTypes>(id);
36+
37+
Assert.That(fromDb.Int, Is.EqualTo(model.Int));
38+
Assert.That(fromDb.Long, Is.EqualTo(model.Long));
39+
Assert.That(fromDb.Double, Is.EqualTo(model.Double));
40+
Assert.That(fromDb.DateTime, Is.EqualTo(model.DateTime).Within(TimeSpan.FromSeconds(1)));
41+
Assert.That(fromDb.TimeSpan, Is.EqualTo(model.TimeSpan));
42+
43+
if (Dialect != Dialect.Sqlite)
44+
{
45+
Assert.That(fromDb.Decimal, Is.EqualTo(model.Decimal));
46+
}
47+
else
48+
{
49+
Assert.That(fromDb.Decimal / 10000, Is.EqualTo(model.Decimal / 10000).Within(1));
50+
}
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)