forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueryTests.cs
101 lines (78 loc) · 3.56 KB
/
QueryTests.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
using System;
using System.IO;
using System.Collections.Generic;
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 QueryTests : IClassFixture<ForceClientFixture>
{
ForceClientFixture forceClientFixture;
public QueryTests(ForceClientFixture fixture)
{
this.forceClientFixture = fixture;
}
[Fact]
public async Task QuerySingle()
{
ForceClient client = await forceClientFixture.GetForceClient();
SfCase singleCase = await client.QuerySingle<SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case LIMIT 1");
Assert.False(singleCase == null);
Assert.NotNull(singleCase.CaseNumber);
}
[Fact]
public async Task QuerySingleNoResults()
{
ForceClient client = await forceClientFixture.GetForceClient();
SfCase singleCase = await client.QuerySingle<SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case WHERE CaseNumber = '999999'");
Assert.True(singleCase == null);
}
[Fact]
public async Task Query()
{
ForceClient client = await forceClientFixture.GetForceClient();
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.True(cases.Count > 1);
Assert.NotNull(firstCase.CaseNumber);
}
[Fact]
public async Task QueryNoResults()
{
ForceClient client = await forceClientFixture.GetForceClient();
List<SfCase> cases = await client.Query<SfCase>("SELECT Id,CaseNumber,SystemModstamp,Account.Name,Account.SystemModstamp,Contact.Name,Contact.SystemModstamp FROM Case WHERE CaseNumber = '999999'");
Assert.False(cases == null);
Assert.True(cases.Count == 0);
}
public class AccountWithContactsSub : SfAccount
{
[JsonProperty(PropertyName = "contacts")]
[Updateable(false), Createable(false)]
public QueryResult<SfContact> Contacts { get; set; }
}
[Fact]
public async Task QueryRelationship()
{
//This isn't fully supported yet - this wont query all if there are NextRecordsUrl values in the subqueries
ForceClient client = await forceClientFixture.GetForceClient();
List<AccountWithContactsSub> accounts = await client.Query<AccountWithContactsSub>("SELECT Account.Name, (Select Contact.Name from Contacts) FROM Account");
Assert.NotNull(accounts);
//these assertions could fail on accounts without any contacts. Not necessarily an error
// Assert.True(accounts[0].Contacts.Done);
// Assert.NotNull(accounts[0].Contacts.Records[0].Name);
}
[Fact]
public async Task CountQuery()
{
ForceClient client = await forceClientFixture.GetForceClient();
int count = await client.CountQuery("SELECT COUNT() FROM Case");
Assert.True(count > 1);
}
}
}