forked from praeclarum/sqlite-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestDb.cs
84 lines (77 loc) · 1.92 KB
/
TestDb.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
using System;
using System.IO;
#if NETFX_CORE
class DescriptionAttribute : Attribute
{
public DescriptionAttribute (string desc)
{
}
}
#endif
namespace SQLite.Tests
{
public class Product
{
[AutoIncrement, PrimaryKey]
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public uint TotalSales { get; set; }
}
public class Order
{
[AutoIncrement, PrimaryKey]
public int Id { get; set; }
public DateTime PlacedTime { get; set; }
}
public class OrderHistory {
[AutoIncrement, PrimaryKey]
public int Id { get; set; }
public int OrderId { get; set; }
public DateTime Time { get; set; }
public string Comment { get; set; }
}
public class OrderLine
{
[AutoIncrement, PrimaryKey]
public int Id { get; set; }
[Indexed("IX_OrderProduct", 1)]
public int OrderId { get; set; }
[Indexed("IX_OrderProduct", 2)]
public int ProductId { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public OrderLineStatus Status { get; set; }
}
public enum OrderLineStatus {
Placed = 1,
Shipped = 100
}
public class TestDb : SQLiteConnection
{
public TestDb (bool storeDateTimeAsTicks = true, object key = null, bool wal = true) : base (new SQLiteConnectionString (TestPath.GetTempFileName (), storeDateTimeAsTicks, key: key))
{
Trace = true;
if (wal)
EnableWriteAheadLogging ();
}
public TestDb (string path, bool storeDateTimeAsTicks = true, object key = null, bool wal = true) : base (new SQLiteConnectionString (path, storeDateTimeAsTicks, key: key))
{
Trace = true;
if (wal)
EnableWriteAheadLogging ();
}
}
public class TestPath
{
public static string GetTempFileName ()
{
#if NETFX_CORE
var name = Guid.NewGuid () + ".sqlite";
return Path.Combine (Windows.Storage.ApplicationData.Current.LocalFolder.Path, name);
#else
return Path.GetTempFileName ();
#endif
}
}
}