forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCRUDTests.cs
More file actions
111 lines (88 loc) · 5.03 KB
/
CRUDTests.cs
File metadata and controls
111 lines (88 loc) · 5.03 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
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Xunit;
using NetCoreForce.Client;
using NetCoreForce.Client.Models;
using NetCoreForce.Models;
using Newtonsoft.Json;
namespace NetCoreForce.FunctionalTests
{
public class CRUDTests : IClassFixture<ForceClientFixture>
{
ForceClientFixture forceClientFixture;
public CRUDTests(ForceClientFixture fixture)
{
this.forceClientFixture = fixture;
}
[Fact]
public async Task CrudChain()
{
ForceClient client = await forceClientFixture.GetForceClient();
//create new object
SfAccount newAccount = new SfAccount();
string accountName = string.Format("Test Object {0}", Guid.NewGuid().ToString());
newAccount.Name = accountName;
CreateResponse createResp = await client.CreateRecord<SfAccount>(SfAccount.SObjectTypeName, newAccount);
Assert.True(!string.IsNullOrEmpty(createResp.Id), "Failed to create new object");
//get newly created
string newAccountId = createResp.Id;
SfAccount account = await client.GetObjectById<SfAccount>(SfAccount.SObjectTypeName, newAccountId);
Assert.True(account != null, "Failed to retrieve new object");
//update object
string description = string.Format("Test Description {0}", Guid.NewGuid().ToString());
account.Description = description;
await client.UpdateRecord<SfAccount>(SfAccount.SObjectTypeName, account.Id, account);
//get newly updated
SfAccount udpatedAccount = await client.GetObjectById<SfAccount>(SfAccount.SObjectTypeName, newAccountId);
Assert.True(udpatedAccount != null, "Failed to retrieve udpated object");
Assert.Equal(description, udpatedAccount.Description);
//delete
await client.DeleteRecord(SfAccount.SObjectTypeName, newAccountId);
//use queryall to find deleted record
}
[Fact]
public async Task CreateAnUpdateMultiple()
{
ForceClient client = await forceClientFixture.GetForceClient();
//create new object
SfAccount firstAccount = new SfAccount() { };
string firstAccountName = string.Format("Test Object {0}", Guid.NewGuid().ToString());
firstAccount.Name = firstAccountName;
CreateResponse createResp = await client.CreateRecord<SfAccount>(SfAccount.SObjectTypeName, firstAccount);
string firstAccountId = createResp.Id;
Assert.True(!string.IsNullOrEmpty(createResp.Id), "Failed to create new object");
//get new object
firstAccount = await client.GetObjectById<SfAccount>(SfAccount.SObjectTypeName, firstAccountId);
//create second new object for testing update multiple
SfAccount secondAccount = new SfAccount();
string secondAccountName = string.Format("Test Object {0}", Guid.NewGuid().ToString());
secondAccount.Name = secondAccountName;
CreateResponse secondCreateResp = await client.CreateRecord<SfAccount>(SfAccount.SObjectTypeName, secondAccount);
string secondAccountId = secondCreateResp.Id;
Assert.True(!string.IsNullOrEmpty(secondCreateResp.Id), "Failed to create second new object");
//get new object
secondAccount = await client.GetObjectById<SfAccount>(SfAccount.SObjectTypeName, secondAccountId);
//test update multiple
string firstUpdatedDescription = string.Format("Test Description {0}", Guid.NewGuid().ToString());
string secondUpdatedDescription = string.Format("Test Description {0}", Guid.NewGuid().ToString());
firstAccount.Description = firstUpdatedDescription;
secondAccount.Description = secondUpdatedDescription;
List<UpdateMultipleResponse> responses = await client.UpdateRecords(new List<SObject>() { firstAccount, secondAccount }, true);
Assert.True(responses.All(r => r.Success), "Failed to update multiple objects");
//get newly updated objects
string secondNewAccountId = secondCreateResp.Id;
SfAccount firstUpdatedAccount = await client.GetObjectById<SfAccount>(SfAccount.SObjectTypeName, firstAccountId);
SfAccount secondUpdatedAccount = await client.GetObjectById<SfAccount>(SfAccount.SObjectTypeName, secondAccountId);
Assert.True(firstUpdatedAccount != null && secondUpdatedAccount != null, "Failed to retrieve multiple updated objects");
Assert.Equal(firstUpdatedDescription, firstUpdatedAccount.Description);
Assert.Equal(secondUpdatedDescription, secondUpdatedAccount.Description);
//delete
await client.DeleteRecord(SfAccount.SObjectTypeName, firstAccountId);
await client.DeleteRecord(SfAccount.SObjectTypeName, secondNewAccountId);
//use queryall to find deleted record
}
}
}