forked from anthonyreilly/NetCoreForce
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForceClientFixture.cs
More file actions
63 lines (53 loc) · 1.97 KB
/
ForceClientFixture.cs
File metadata and controls
63 lines (53 loc) · 1.97 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
using System;
using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using NetCoreForce.Client;
using NetCoreForce.Client.Models;
using Newtonsoft.Json;
namespace NetCoreForce.FunctionalTests
{
public class ForceClientFixture : IDisposable
{
public AuthInfo AuthInfo { get; private set; }
public ForceClientFixture()
{
string filePath = null;
try
{
if (string.IsNullOrEmpty(filePath))
{
string executabledirectory = System.IO.Directory.GetCurrentDirectory();
string fileName = "credentials_dev.json";
filePath = Path.Combine(executabledirectory, fileName);
}
Console.WriteLine("Reading credentials file {0}", filePath);
string contents = File.ReadAllText(filePath);
AuthInfo info = JsonConvert.DeserializeObject<AuthInfo>(contents);
this.AuthInfo = info;
}
catch (Exception ex)
{
Console.WriteLine("Error reading credentials file: " + ex.Message);
throw;
}
}
public async Task<ForceClient> GetForceClient(string proxyUrl = null)
{
System.Net.Http.HttpClient proxyClient = null;
if(!string.IsNullOrEmpty(proxyUrl))
{
proxyClient = HttpClientFactory.CreateHttpClient(true, proxyUrl);
}
AuthenticationClient auth = new AuthenticationClient();
await auth.UsernamePasswordAsync(AuthInfo.ClientId, AuthInfo.ClientSecret,
AuthInfo.Username, AuthInfo.Password, AuthInfo.TokenRequestEndpoint);
ForceClient client = new ForceClient(auth.AccessInfo.InstanceUrl, auth.ApiVersion, auth.AccessInfo.AccessToken, proxyClient);
return client;
}
public void Dispose()
{
}
}
}