-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathCreateTableTest.cs
99 lines (82 loc) · 2.38 KB
/
CreateTableTest.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
90
91
92
93
94
95
96
97
98
99
using System;
using System.Linq;
#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 CreateTableTest
{
[Test]
public void CreateThem ()
{
var db = new TestDb ();
db.CreateTable<Product> ();
db.CreateTable<Order> ();
db.CreateTable<OrderLine> ();
db.CreateTable<OrderHistory> ();
VerifyCreations(db);
}
[Test]
public void CreateAsPassedInTypes ()
{
var db = new TestDb();
db.CreateTable(typeof(Product));
db.CreateTable(typeof(Order));
db.CreateTable(typeof(OrderLine));
db.CreateTable(typeof(OrderHistory));
VerifyCreations(db);
}
[Test]
public void CreateTwice ()
{
var db = new TestDb ();
db.CreateTable<Product> ();
db.CreateTable<OrderLine> ();
db.CreateTable<Order> ();
db.CreateTable<OrderLine> ();
db.CreateTable<OrderHistory> ();
VerifyCreations(db);
}
private static void VerifyCreations(TestDb db)
{
var orderLine = db.GetMapping(typeof(OrderLine));
Assert.AreEqual(6, orderLine.Columns.Length);
var l = new OrderLine()
{
Status = OrderLineStatus.Shipped
};
db.Insert(l);
var lo = db.Table<OrderLine>().First(x => x.Status == OrderLineStatus.Shipped);
Assert.AreEqual(lo.Id, l.Id);
}
class Issue115_MyObject
{
[PrimaryKey]
public string UniqueId { get; set; }
public byte OtherValue { get; set; }
}
[Test]
public void Issue115_MissingPrimaryKey ()
{
using (var conn = new TestDb ()) {
conn.CreateTable<Issue115_MyObject> ();
conn.InsertAll (from i in Enumerable.Range (0, 10) select new Issue115_MyObject {
UniqueId = i.ToString (),
OtherValue = (byte)(i * 10),
});
var query = conn.Table<Issue115_MyObject> ();
foreach (var itm in query) {
itm.OtherValue++;
Assert.AreEqual (1, conn.Update (itm, typeof(Issue115_MyObject)));
}
}
}
}
}