forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryAsyncTests.cs
215 lines (177 loc) · 7.09 KB
/
QueryAsyncTests.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
using NetCoreForce.Client;
using NetCoreForce.Client.Attributes;
using NetCoreForce.Client.Models;
using NetCoreForce.Models;
using Newtonsoft.Json;
namespace NetCoreForce.FunctionalTests
{
public class QueryAsyncTests : IClassFixture<ForceClientFixture>
{
ForceClientFixture forceClientFixture;
public QueryAsyncTests(ForceClientFixture fixture)
{
this.forceClientFixture = fixture;
}
[Fact]
public async Task QueryAsync()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 3000");
int count = 0;
SfContact contact = null;
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
while (await contactsEnumerator.MoveNextAsync())
{
contact = contactsEnumerator.Current;
count++;
}
}
// recordcount needs be greater than 2000 to ensure that more than one batch was retrieved
// and that the async retrieval occurred.
Assert.True(count > 2000);
Assert.NotNull(contact.Id);
}
[Fact]
public async Task QueryAsync_small_batchSize()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1000", batchSize: 200);
int count = 0;
SfContact contact = null;
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
// Assert.NotNull(contactsEnumerator);
while (await contactsEnumerator.MoveNextAsync())
{
contact = contactsEnumerator.Current;
count++;
#if DEBUG
if (count % 200 == 0)
{
Console.WriteLine("QueryAsync_small_batchSize: processed {0} records", count.ToString());
}
#endif
}
}
// recordcount needs be greater than 200 to ensure that more than one batch was retrieved
// and that the async retrieval occurred.
Assert.True(count > 200);
Assert.NotNull(contact.Id);
}
[Fact]
public async Task QueryAsync_single_result()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1");
int count = 0;
SfContact contact = null;
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
while (await contactsEnumerator.MoveNextAsync())
{
contact = contactsEnumerator.Current;
count++;
}
}
Assert.Equal(1, count);
Assert.NotNull(contact.Id);
}
[Fact]
public async Task QueryAsync_large_resultset()
{
ForceClient client = await forceClientFixture.GetForceClient();
var enumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact");
int count = 0;
await using (var enumerator = enumerable.GetAsyncEnumerator())
{
while (await enumerator.MoveNextAsync())
{
var currentItem = enumerator.Current;
count++;
#if DEBUG
if (count % 1000 == 0)
{
Console.WriteLine("QueryAsync_large_resultset: processed {0} records", count.ToString());
}
#endif
}
}
Assert.True(count > 0);
}
[Fact]
public async Task QueryAsync_valid_result_collection()
{
ForceClient client = await forceClientFixture.GetForceClient();
var enumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact limit 450", batchSize: 200);
List<SfContact> results = new List<SfContact>();
await using (var enumerator = enumerable.GetAsyncEnumerator())
{
while (await enumerator.MoveNextAsync())
{
results.Add(enumerator.Current);
}
}
Assert.NotEmpty(results);
Assert.Equal(450, results.Count);
}
[Fact]
public async Task QueryAsync_custom_batchSize()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 3000", batchSize: 200);
int count = 0;
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
while (await contactsEnumerator.MoveNextAsync())
{
SfContact contact = contactsEnumerator.Current;
count++;
}
}
Assert.True(count > 0);
}
[Fact]
public async Task QueryAsync_invalid_batchsize()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1000", batchSize: 100);
await Assert.ThrowsAsync<ArgumentException>(async () =>
{
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
await contactsEnumerator.MoveNextAsync();
}
});
}
[Fact]
public async Task QueryAsync_no_results()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact WHERE Name='xyz123foobar'");
SfContact contact = null;
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
while (await contactsEnumerator.MoveNextAsync())
{
contact = contactsEnumerator.Current;
}
}
Assert.Null(contact);
}
[Fact]
public async Task QueryAsync_ToList()
{
ForceClient client = await forceClientFixture.GetForceClient();
List<SfContact> contacts = await client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1000", batchSize: 200).ToListAsync();
Assert.NotNull(contacts);
Assert.NotEmpty(contacts);
}
}
}