forked from praeclarum/sqlite-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTimeTest.cs
90 lines (75 loc) · 1.82 KB
/
DateTimeTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
#if NETFX_CORE
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using SetUp = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestInitializeAttribute;
using TestFixture = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestClassAttribute;
using Test = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.TestMethodAttribute;
#else
using NUnit.Framework;
#endif
namespace SQLite.Tests
{
[TestFixture]
public class DateTimeTest
{
class TestObj
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public DateTime ModifiedTime { get; set; }
}
[Test]
public void AsTicks ()
{
var db = new TestDb (storeDateTimeAsTicks: true);
TestDateTime (db);
}
[Test]
public void AsStrings ()
{
var db = new TestDb (storeDateTimeAsTicks: false);
TestDateTime (db);
}
[Test]
public void AsyncAsTicks ()
{
var db = new SQLiteAsyncConnection (TestPath.GetTempFileName (), true);
TestAsyncDateTime (db);
}
[Test]
public void AsyncAsString ()
{
var db = new SQLiteAsyncConnection (TestPath.GetTempFileName (), false);
TestAsyncDateTime (db);
}
void TestAsyncDateTime (SQLiteAsyncConnection db)
{
db.CreateTableAsync<TestObj> ().Wait ();
TestObj o, o2;
//
// Ticks
//
o = new TestObj {
ModifiedTime = new DateTime (2012, 1, 14, 3, 2, 1, 234),
};
db.InsertAsync (o).Wait ();
o2 = db.GetAsync<TestObj> (o.Id).Result;
Assert.AreEqual (o.ModifiedTime, o2.ModifiedTime);
}
void TestDateTime (TestDb db)
{
db.CreateTable<TestObj> ();
TestObj o, o2;
//
// Ticks
//
o = new TestObj {
ModifiedTime = new DateTime (2012, 1, 14, 3, 2, 1, 234),
};
db.Insert (o);
o2 = db.Get<TestObj> (o.Id);
Assert.AreEqual (o.ModifiedTime, o2.ModifiedTime);
}
}
}