forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MockHttpAsyncTests.cs
79 lines (64 loc) · 3.39 KB
/
MockHttpAsyncTests.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
using System;
using System.Net;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using NetCoreForce.Client;
using Xunit;
using NetCoreForce.Models;
namespace NetCoreForce.Client.Tests
{
public class MockHttpAsyncTests
{
[Fact]
public async Task QueryAsyncInvalidBatchSize()
{
HttpClient httpClient = new HttpClient(new MockHttpClientHandler());
ForceClient client = new ForceClient("https://na15.salesforce.com", "v57.0", "dummyToken", httpClient);
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 1000", batchSize: 100);
ArgumentException ex = await Assert.ThrowsAsync<ArgumentException>(async () =>
{
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
while (await contactsEnumerator.MoveNextAsync())
{
var result = contactsEnumerator.Current;
}
}
});
// Check that the error message mentions 200 as the minimum value
Assert.Contains("200", ex.Message);
}
[Fact]
public async void QueryAsync()
{
var mockHandler = new MockHttpClientHandler();
HttpResponseMessage respMsg = MockResponse.GetResponse("querybatch/batch-1.json", HttpStatusCode.OK);
Uri requestUri = new Uri(@"https://na15.salesforce.com/services/data/v57.0/query?q=SELECT%20Id%20FROM%20Contact%20LIMIT%20800");
mockHandler.AddMockResponse(requestUri, respMsg);
HttpResponseMessage respMsg2 = MockResponse.GetResponse("querybatch/batch-2.json", HttpStatusCode.OK);
Uri requestUri2 = new Uri(@"https://na15.salesforce.com/services/data/v57.0/query/01gC000006QJJ7fIAH-200");
mockHandler.AddMockResponse(requestUri2, respMsg2);
HttpResponseMessage respMsg3 = MockResponse.GetResponse("querybatch/batch-3.json", HttpStatusCode.OK);
Uri requestUri3 = new Uri(@"https://na15.salesforce.com/services/data/v57.0/query/01gC000006QJJ7fIAH-400");
mockHandler.AddMockResponse(requestUri3, respMsg3);
HttpResponseMessage respMsg4 = MockResponse.GetResponse("querybatch/batch-4.json", HttpStatusCode.OK);
Uri requestUri4 = new Uri(@"https://na15.salesforce.com/services/data/v57.0/query/01gC000006QJJ7fIAH-600");
mockHandler.AddMockResponse(requestUri4, respMsg4);
HttpClient httpClient = new HttpClient(mockHandler);
ForceClient client = new ForceClient("https://na15.salesforce.com", "v57.0", "dummyToken", httpClient);
var contactsEnumerable = client.QueryAsync<SfContact>("SELECT Id FROM Contact LIMIT 800", batchSize: 200);
List<SfContact> contacts = new List<SfContact>(800);
await using (IAsyncEnumerator<SfContact> contactsEnumerator = contactsEnumerable.GetAsyncEnumerator())
{
while (await contactsEnumerator.MoveNextAsync())
{
contacts.Add(contactsEnumerator.Current);
}
}
Assert.Equal(800, contacts.Count);
Assert.Equal("003XXXXXXXXXXXXXXX", contacts[0].Id);
Assert.Equal("003XXXXXXXXXXXXXXX", contacts[799].Id);
}
}
}