-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTodoTests.cs
126 lines (107 loc) · 3.88 KB
/
TodoTests.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System.IO;
using System.Threading.Tasks;
using Friflo.Json.Fliox.Hub.Host;
using NUnit.Framework;
using static NUnit.Framework.Assert;
namespace TodoTest;
public static class TodoTests
{
private static readonly string DbPath = GetBasePath() + "Todo/Test/DB/main_db";
private static readonly DatabaseSchema Schema = DatabaseSchema.Create<TodoClient>();
/// <summary>create a <see cref="MemoryDatabase"/> clone for every client to avoid side effects by DB mutations</summary>
private static FlioxHub CreateTodoHub()
{
var cloneDB = CreateMemoryDatabaseClone("main_db", DbPath);
return new FlioxHub(cloneDB);
}
private static string GetBasePath()
{
string baseDir = Directory.GetCurrentDirectory() + "/../../../../../";
return Path.GetFullPath(baseDir);
}
private static MemoryDatabase CreateMemoryDatabaseClone(string dbName, string srcDatabasePath)
{
var referenceDB = new FileDatabase("source_db", srcDatabasePath);
var cloneDB = new MemoryDatabase(dbName, Schema);
cloneDB.SeedDatabase(referenceDB).Wait();
return cloneDB;
}
[Test]
public static async Task QueryAllJobs()
{
var hub = CreateTodoHub();
var client = new TodoClient(hub);
var jobs = client.Jobs.QueryAll();
await client.SyncTasks();
AreEqual(2, jobs.Result.Count);
AreEqual(2, client.Jobs.Local.Count);
}
[Test]
public static async Task QueryFilterJobs()
{
var hub = CreateTodoHub();
var client = new TodoClient(hub);
var jobs = client.Jobs.Query(o => o.completed == true);
await client.SyncTasks();
AreEqual(1, jobs.Result.Count);
AreEqual(1, client.Jobs.Local.Count);
}
[Test]
public static async Task QueryCursorJobs()
{
var hub = CreateTodoHub();
var client = new TodoClient(hub);
var query = client.Jobs.QueryAll();
query.maxCount = 1; // query with cursor
var count = 0;
while (true) {
await client.SyncTasks();
count += query.Result.Count;
if (query.IsFinished)
break;
query = query.QueryNext();
}
AreEqual(2, count);
}
[Test]
public static async Task CountAllJobs()
{
var hub = CreateTodoHub();
var client = new TodoClient(hub);
var jobs = client.Jobs.CountAll();
await client.SyncTasks();
AreEqual(2, jobs.Result);
}
[Test]
public static async Task CountFilterJobs()
{
var hub = CreateTodoHub();
var client = new TodoClient(hub);
var jobs = client.Jobs.Count(o => o.completed == true);
await client.SyncTasks();
AreEqual(1, jobs.Result);
}
[Test]
public static async Task FindJob()
{
var hub = CreateTodoHub();
var client = new TodoClient(hub);
var readJob = client.Jobs.Read().Find(1);
await client.SyncTasks();
AreEqual("buy milk", readJob.Result.title);
AreEqual(1, client.Jobs.Local.Count);
}
[Test]
public static async Task FindRangeJob()
{
var hub = CreateTodoHub();
var client = new TodoClient(hub);
var readJob = client.Jobs.Read().FindRange(new long [] { 1, 2, 3 });
await client.SyncTasks();
AreEqual(3, readJob.Result.Count);
NotNull(readJob.Result[1]);
NotNull(readJob.Result[2]);
IsNull (readJob.Result[3]);
AreEqual(3, client.Jobs.Local.Count);
}
}