forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryAsyncTests.cs
More file actions
160 lines (131 loc) · 5.08 KB
/
QueryAsyncTests.cs
File metadata and controls
160 lines (131 loc) · 5.08 KB
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
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 QueryAsyncEnumerator()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 3000");
SfContact contact = null;
using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetEnumerator())
{
while (await contactsEnumerator.MoveNext())
{
contact = contactsEnumerator.Current;
}
}
Assert.NotNull(contact.Id);
}
[Fact]
public async Task QueryAsyncEnumeratorSingle()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1");
int count = 0;
SfContact contact = null;
using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetEnumerator())
{
while (await contactsEnumerator.MoveNext())
{
contact = contactsEnumerator.Current;
count++;
}
}
Assert.Equal(1, count);
Assert.NotNull(contact.Id);
}
[Fact]
public async Task QueryAsyncEnumeratorLarge()
{
ForceClient client = await forceClientFixture.GetForceClient();
var enumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact");
int count = 0;
using (var enumerator = enumerable.GetEnumerator())
{
while (await enumerator.MoveNext())
{
var currentItem = enumerator.Current;
count++;
#if DEBUG
if (count % 1000 == 0)
{
Console.WriteLine("processed {0} records", count.ToString());
}
#endif
}
}
Assert.True(count > 0);
}
[Fact]
public async Task QueryAsyncEnumeratorCustombBatchSize()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 3000", batchSize: 200);
int count = 0;
using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetEnumerator())
{
while (await contactsEnumerator.MoveNext())
{
SfContact contact = contactsEnumerator.Current;
count++;
}
}
Assert.True(count > 0);
}
[Fact]
public async Task QueryAsyncInvalidBatchSize()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1000", batchSize: 100);
Assert.Throws<ArgumentException>(() => {
IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetEnumerator();
});
await Assert.ThrowsAsync<ArgumentException>(async () =>
{
using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetEnumerator())
{
await contactsEnumerator.MoveNext();
}
});
}
[Fact]
public async Task QueryAsyncEnumeratorNoResults()
{
ForceClient client = await forceClientFixture.GetForceClient();
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact WHERE Name='xyz123foobar'");
SfContact contact = null;
using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetEnumerator())
{
while (await contactsEnumerator.MoveNext())
{
contact = contactsEnumerator.Current;
}
}
Assert.Null(contact);
}
public async Task QueryAsyncToList()
{
ForceClient client = await forceClientFixture.GetForceClient();
List<SfContact> contacts = await client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1000", batchSize: 200).ToList();
Assert.NotNull(contacts);
Assert.NotEmpty(contacts);
}
}
}