forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExternalIdTests.cs
63 lines (52 loc) · 2.47 KB
/
ExternalIdTests.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
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 ExternalIdTests : IClassFixture<ForceClientFixture>
{
ForceClientFixture forceClientFixture;
public ExternalIdTests(ForceClientFixture fixture)
{
this.forceClientFixture = fixture;
}
[Fact]
public async Task ExternalIdInsertAndUpdate()
{
ForceClient client = await forceClientFixture.GetForceClient();
//create new object
SfAccount newAccount = new SfAccount();
string accountName = string.Format("Test Object {0}", Guid.NewGuid().ToString());
string externalId = Guid.NewGuid().ToString();
newAccount.Name = accountName;
UpsertResponse insertResponse = await client.InsertOrUpdateRecord<SfAccount>(SfAccount.SObjectTypeName, "AccountExtId__c", externalId, newAccount);
Assert.True(insertResponse.Created);
Assert.NotNull(insertResponse.Id);
//get newly created
string newAccountId = insertResponse.Id;
SfAccount account = await client.GetObjectById<SfAccount>(SfAccount.SObjectTypeName, newAccountId);
Assert.True(account != null, "Failed to retrieve new object");
Assert.Equal(newAccountId, account.Id);
//update object description
SfAccount accountUpdate = new SfAccount();
string description = string.Format("Test Description {0}", Guid.NewGuid().ToString());
accountUpdate.Description = description;
UpsertResponse updateResponse = await client.InsertOrUpdateRecord<SfAccount>(SfAccount.SObjectTypeName, "AccountExtId__c", externalId, accountUpdate);
Assert.Equal(newAccountId, updateResponse.Id);
Assert.False(updateResponse.Created);
//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);
}
}
}