forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockHttpTests.cs
More file actions
113 lines (76 loc) · 4.71 KB
/
MockHttpTests.cs
File metadata and controls
113 lines (76 loc) · 4.71 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
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 MockHttpTests
{
//test with empty response content
[Fact]
public async void ObjectById()
{
var mockHandler = new MockHttpClientHandler();
HttpResponseMessage respMsg = MockResponse.GetResponse("account.json", HttpStatusCode.OK);
const string objectId = "001i000002C8QTIAA3";
Uri requestUri = new Uri("https://na15.salesforce.com/services/data/v41.0/sobjects/Account/001i000002C8QTIAA3");
mockHandler.AddMockResponse(requestUri, respMsg);
HttpClient httpClient = new HttpClient(mockHandler);
ForceClient client = new ForceClient("https://na15.salesforce.com", "v41.0", "dummyToken", httpClient);
SfAccount acct = await client.GetObjectById<SfAccount>("Account", objectId);
Assert.False(acct == null);
Assert.Equal(objectId, acct.Id);
Assert.Equal("NY", acct.BillingAddress.State);
}
[Fact]
public async void QueryNestedObjects()
{
var mockHandler = new MockHttpClientHandler();
HttpResponseMessage respMsg = MockResponse.GetResponse("query_case_result.json", HttpStatusCode.OK);
Uri requestUri = new Uri(@"https://na15.salesforce.com/services/data/v41.0/query?q=SELECT%20Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp%20FROM%20Case");
mockHandler.AddMockResponse(requestUri, respMsg);
HttpClient httpClient = new HttpClient(mockHandler);
ForceClient client = new ForceClient("https://na15.salesforce.com", "v41.0", "dummyToken", httpClient);
List<SfCase> cases = await client.Query<SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case");
SfCase firstCase = cases[0];
Assert.False(cases == null);
Assert.Equal("00001000", cases[0].CaseNumber);
Assert.Equal("Edge Communications", cases[0].Account.Name);
Assert.Equal("Rose Gonzalez", cases[0].Contact.Name);
Assert.Equal(26, cases.Count);
}
[Fact]
public async void QuerySingleObject()
{
var mockHandler = new MockHttpClientHandler();
HttpResponseMessage respMsg = MockResponse.GetResponse("query_case_single_result.json", HttpStatusCode.OK);
Uri requestUri = new Uri(@"https://na15.salesforce.com/services/data/v41.0/query?q=SELECT%20Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp%20FROM%20Case%20WHERE%20CaseNumber%20%3D%20%2700001000%27");
mockHandler.AddMockResponse(requestUri, respMsg);
HttpClient httpClient = new HttpClient(mockHandler);
ForceClient client = new ForceClient("https://na15.salesforce.com", "v41.0", "dummyToken", httpClient);
SfCase singleCase = await client.QuerySingle<SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case WHERE CaseNumber = '00001000'");
Assert.False(singleCase == null);
Assert.Equal("00001000", singleCase.CaseNumber);
Assert.Equal("Edge Communications", singleCase.Account.Name);
Assert.Equal("Rose Gonzalez", singleCase.Contact.Name);
}
[Fact]
public async void QuerySingleObjectFail()
{
var mockHandler = new MockHttpClientHandler();
HttpResponseMessage respMsg = MockResponse.GetResponse("query_case_result.json", HttpStatusCode.OK);
Uri requestUri = new Uri(@"https://na15.salesforce.com/services/data/v41.0/query?q=SELECT%20Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp%20FROM%20Case%20WHERE%20CaseNumber%20LIKE%20%270000%25%27");
mockHandler.AddMockResponse(requestUri, respMsg);
HttpClient httpClient = new HttpClient(mockHandler);
ForceClient client = new ForceClient("https://na15.salesforce.com", "v41.0", "dummyToken", httpClient);
Exception ex = await Assert.ThrowsAsync<Exception>(
async () => await client.QuerySingle<SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case WHERE CaseNumber LIKE '0000%'")
);
Assert.NotNull(ex);
}
}
}