forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRavenAsyncTest.cs
107 lines (100 loc) · 3.66 KB
/
RavenAsyncTest.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
using System.Linq;
using System.Threading.Tasks;
using Raven.Client;
using Raven.Client.Document;
using Raven.Client.Linq;
using Raven.Tests.Common;
using Xunit;
namespace Raven.Tests.MailingList
{
public class AsyncTest : RavenTest
{
public class Dummy
{
public string Id { get; set; }
public string Name { get; set; }
}
[Fact]
public void SyncQuery()
{
using (GetNewServer())
using (var store = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
using (var session = store.OpenSession())
{
var results = session.Query<Dummy>().ToList();
Assert.Equal(0, results.Count);
results = session.Query<Dummy>().ToList();
Assert.Equal(0, results.Count);
}
}
[Fact]
public async Task AsyncQuery()
{
using (GetNewServer())
using (var store = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
using (var session = store.OpenAsyncSession())
{
var results = await session.Query<Dummy>().ToListAsync();
Assert.Equal(0, results.Count);
var results2 = await session.Query<Dummy>().ToListAsync();
Assert.Equal(0, results2.Count);
}
}
[Fact]
public async Task AsyncQuery_WithWhereClause()
{
using (GetNewServer())
using (var store = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
{
using (var session = store.OpenAsyncSession())
{
await session.StoreAsync(new Dummy {Name = "oren"});
await session.SaveChangesAsync();
}
using (var session = store.OpenAsyncSession())
{
var results = await session.Query<Dummy>()
.Customize(x => x.WaitForNonStaleResults())
.Where(x => x.Name == "oren")
.ToListAsync();
Assert.Equal(1, results.Count);
}
}
}
[Fact]
public async Task AsyncLoadNonExistant()
{
// load a non-existant entity
using (GetNewServer())
using (var store = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
using (var session = store.OpenAsyncSession())
{
var loaded = await session.LoadAsync<Dummy>("dummies/-1337");
Assert.Null(loaded);
}
}
[Fact]
public async Task AsyncLoad()
{
using (GetNewServer())
using (var store = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
{
using (var session = store.OpenAsyncSession())
{
await session.StoreAsync(new Dummy());
await session.SaveChangesAsync();
}
using (var session = store.OpenAsyncSession())
{
await session.LoadAsync<Dummy>("dummies/1");
Assert.Equal(0, store.JsonRequestFactory.NumberOfCachedRequests);
}
using (var session = store.OpenAsyncSession())
{
await session.LoadAsync<Dummy>("dummies/1");
Assert.Equal(1, store.JsonRequestFactory.NumberOfCachedRequests);
}
}
}
}
}