forked from koush/sqlite-net
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBooleanTest.cs
78 lines (67 loc) · 2.33 KB
/
BooleanTest.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
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SQLite;
using System.Diagnostics;
#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 BooleanTest
{
public class VO
{
[AutoIncrement, PrimaryKey]
public int ID { get; set; }
public bool Flag { get; set; }
public String Text { get; set; }
public override string ToString()
{
return string.Format("VO:: ID:{0} Flag:{1} Text:{2}", ID, Flag, Text);
}
}
public class DbAcs : SQLiteConnection
{
public DbAcs(String path)
: base(path)
{
}
public void buildTable()
{
CreateTable<VO>();
}
public int CountWithFlag(Boolean flag)
{
var cmd = CreateCommand("SELECT COUNT(*) FROM VO Where Flag = ?", flag);
return cmd.ExecuteScalar<int>();
}
}
[Test]
public void TestBoolean()
{
var tmpFile = TestPath.GetTempFileName();
var db = new DbAcs(tmpFile);
db.buildTable();
for (int i = 0; i < 10; i++)
db.Insert(new VO() { Flag = (i % 3 == 0), Text = String.Format("VO{0}", i) });
// count vo which flag is true
Assert.AreEqual(4, db.CountWithFlag(true));
Assert.AreEqual(6, db.CountWithFlag(false));
Debug.WriteLine("VO with true flag:");
foreach (var vo in db.Query<VO>("SELECT * FROM VO Where Flag = ?", true))
Debug.WriteLine (vo.ToString ());
Debug.WriteLine ("VO with false flag:");
foreach (var vo in db.Query<VO>("SELECT * FROM VO Where Flag = ?", false))
Debug.WriteLine (vo.ToString ());
}
}
}