-
Notifications
You must be signed in to change notification settings - Fork 303
/
FindTests.cs
89 lines (78 loc) · 2.61 KB
/
FindTests.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.Reflection;
using System.Collections.Generic;
using NUnit.Framework;
using System.IO;
using Simple.Data.Ado;
using Simple.Data.SqlCe40;
using Simple.Data.SqlCeTest;
namespace Simple.Data.SqlCe40Test
{
/// <summary>
/// Summary description for FindTests
/// </summary>
[TestFixture]
public class FindTests
{
private static readonly string DatabasePath = Path.Combine(
Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Substring(8)),
"TestDatabase.sdf");
[TestFixtureSetUp]
public void DeleteAlice()
{
var db = Database.Opener.OpenFile(DatabasePath);
db.Users.DeleteByName("Alice");
}
[Test]
public void TestProviderWithFileName()
{
var provider = new ProviderHelper().GetProviderByFilename(DatabasePath);
Assert.IsInstanceOf(typeof (SqlCe40ConnectionProvider), provider);
}
[Test]
public void TestProviderWithConnectionString()
{
var provider = new ProviderHelper().GetProviderByConnectionString(string.Format("data source={0}", DatabasePath));
Assert.IsInstanceOf(typeof(SqlCe40ConnectionProvider), provider);
}
[Test]
public void TestFindById()
{
var db = Database.Opener.OpenFile(DatabasePath);
var user = db.Users.FindById(1);
Assert.AreEqual(1, user.Id);
}
[Test]
public void TestAll()
{
var db = Database.OpenFile(DatabasePath);
var all = new List<object>(db.Users.All().Cast<dynamic>());
Assert.IsNotEmpty(all);
}
[Test]
public void TestImplicitCast()
{
var db = Database.OpenFile(DatabasePath);
User user = db.Users.FindById(1);
Assert.AreEqual(1, user.Id);
}
[Test]
public void TestImplicitEnumerableCast()
{
var db = Database.OpenFile(DatabasePath);
foreach (User user in db.Users.All())
{
Assert.IsNotNull(user);
}
}
[Test]
public void TestInsert()
{
var db = Database.OpenFile(DatabasePath);
var user = db.Users.Insert(Name: "Alice", Password: "foo", Age: 29);
Assert.IsNotNull(user);
Assert.AreEqual("Alice", user.Name);
Assert.AreEqual("foo", user.Password);
Assert.AreEqual(29, user.Age);
}
}
}