forked from praeclarum/sqlite-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringQueryTest.cs
66 lines (55 loc) · 1.61 KB
/
StringQueryTest.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
using System;
using System.Linq;
using System.Collections.Generic;
#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 StringQueryTest
{
TestDb db;
[SetUp]
public void SetUp ()
{
db = new TestDb ();
db.CreateTable<Product> ();
var prods = new[] {
new Product { Name = "Foo" },
new Product { Name = "Bar" },
new Product { Name = "Foobar" },
};
db.InsertAll (prods);
}
[Test]
public void StartsWith ()
{
var fs = db.Table<Product> ().Where (x => x.Name.StartsWith ("F")).ToList ();
Assert.AreEqual (2, fs.Count);
var bs = db.Table<Product> ().Where (x => x.Name.StartsWith ("B")).ToList ();
Assert.AreEqual (1, bs.Count);
}
[Test]
public void EndsWith ()
{
var fs = db.Table<Product> ().Where (x => x.Name.EndsWith ("ar")).ToList ();
Assert.AreEqual (2, fs.Count);
var bs = db.Table<Product> ().Where (x => x.Name.EndsWith ("o")).ToList ();
Assert.AreEqual (1, bs.Count);
}
[Test]
public void Contains ()
{
var fs = db.Table<Product> ().Where (x => x.Name.Contains ("o")).ToList ();
Assert.AreEqual (2, fs.Count);
var bs = db.Table<Product> ().Where (x => x.Name.Contains ("a")).ToList ();
Assert.AreEqual (2, bs.Count);
}
}
}