diff --git a/src/ChatterToolkitForNET.FunctionalTests/ChatterClientTests.cs b/src/ChatterToolkitForNET.FunctionalTests/ChatterClientTests.cs index 3f1ce063..917c6da4 100644 --- a/src/ChatterToolkitForNET.FunctionalTests/ChatterClientTests.cs +++ b/src/ChatterToolkitForNET.FunctionalTests/ChatterClientTests.cs @@ -178,7 +178,6 @@ public async void Chatter_Get_Groups_IsNotNull() Assert.IsNotNull(groups); } - //TODO: Create a test that creates a chatter group and adds to the feed so that it never fails [Test] public async void Chatter_Get_Group_News_Feed_IsNotNull() { diff --git a/src/CommonLibrariesForNET.UnitTests/AuthenticationClientRouteHandler.cs b/src/CommonLibrariesForNET.UnitTests/AuthenticationClientRouteHandler.cs index 506be897..b84c19d0 100644 --- a/src/CommonLibrariesForNET.UnitTests/AuthenticationClientRouteHandler.cs +++ b/src/CommonLibrariesForNET.UnitTests/AuthenticationClientRouteHandler.cs @@ -1,5 +1,3 @@ -//TODO: add license header - using System; using System.Net; using System.Net.Http; @@ -11,7 +9,7 @@ namespace Salesforce.Common.UnitTests { internal class AuthenticationClientRouteHandler : DelegatingHandler { - Action _testingAction; + readonly Action _testingAction; public AuthenticationClientRouteHandler(Action testingAction) { diff --git a/src/CommonLibrariesForNET.UnitTests/CommonTests.cs b/src/CommonLibrariesForNET.UnitTests/CommonTests.cs index 425489bc..b66ce0b8 100644 --- a/src/CommonLibrariesForNET.UnitTests/CommonTests.cs +++ b/src/CommonLibrariesForNET.UnitTests/CommonTests.cs @@ -7,6 +7,8 @@ namespace Salesforce.Common.UnitTests [TestFixture] public class CommonTests { + private const string UserAgent = "forcedotcom-toolkit-dotnet"; + [Test] public void Auth_HasApiVersion() { @@ -49,7 +51,7 @@ public async void Requests_CheckHttpRequestMessage_HttpGet() Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/v32/wade"); Assert.IsNotNull(r.Headers.UserAgent); - Assert.AreEqual(r.Headers.UserAgent.ToString(), "forcedotcom-toolkit-dotnet/v32"); + Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32"); Assert.IsNotNull(r.Headers.Authorization); Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken"); @@ -69,7 +71,7 @@ public async void Requests_CheckHttpRequestMessage_HttpGet_WithNode() Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/v32/wade"); Assert.IsNotNull(r.Headers.UserAgent); - Assert.AreEqual(r.Headers.UserAgent.ToString(), "forcedotcom-toolkit-dotnet/v32"); + Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32"); Assert.IsNotNull(r.Headers.Authorization); Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken"); @@ -89,7 +91,7 @@ public async void Requests_CheckHttpRequestMessage_HttpPost() Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/v32/wade"); Assert.IsNotNull(r.Headers.UserAgent); - Assert.AreEqual(r.Headers.UserAgent.ToString(), "forcedotcom-toolkit-dotnet/v32"); + Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32"); Assert.IsNotNull(r.Headers.Authorization); Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken"); @@ -109,7 +111,7 @@ public async void Requests_CheckHttpRequestMessage_HttpPatch() Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/v32/wade"); Assert.IsNotNull(r.Headers.UserAgent); - Assert.AreEqual(r.Headers.UserAgent.ToString(), "forcedotcom-toolkit-dotnet/v32"); + Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32"); Assert.IsNotNull(r.Headers.Authorization); Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken"); @@ -129,7 +131,7 @@ public async void Requests_CheckHttpRequestMessage_HttpDelete() Assert.AreEqual(r.RequestUri.ToString(), "http://localhost:1899/services/data/v32/wade"); Assert.IsNotNull(r.Headers.UserAgent); - Assert.AreEqual(r.Headers.UserAgent.ToString(), "forcedotcom-toolkit-dotnet/v32"); + Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32"); Assert.IsNotNull(r.Headers.Authorization); Assert.AreEqual(r.Headers.Authorization.ToString(), "Bearer accessToken"); diff --git a/src/CommonLibrariesForNET.UnitTests/JsonContent.cs b/src/CommonLibrariesForNET.UnitTests/JsonContent.cs index e320b921..e05a3a72 100644 --- a/src/CommonLibrariesForNET.UnitTests/JsonContent.cs +++ b/src/CommonLibrariesForNET.UnitTests/JsonContent.cs @@ -1,5 +1,3 @@ -//TODO: add license header - using System.IO; using System.Net; using System.Net.Http; diff --git a/src/CommonLibrariesForNET.UnitTests/ServiceClientRouteHandler.cs b/src/CommonLibrariesForNET.UnitTests/ServiceClientRouteHandler.cs index c972be45..052ee88c 100644 --- a/src/CommonLibrariesForNET.UnitTests/ServiceClientRouteHandler.cs +++ b/src/CommonLibrariesForNET.UnitTests/ServiceClientRouteHandler.cs @@ -1,5 +1,3 @@ -//TODO: add license header - using System; using System.Net; using System.Net.Http; @@ -10,7 +8,7 @@ namespace Salesforce.Common.UnitTests { internal class ServiceClientRouteHandler : DelegatingHandler { - Action _testingAction; + readonly Action _testingAction; public ServiceClientRouteHandler(Action testingAction) { diff --git a/src/CommonLibrariesForNET/AuthenticationClient.cs b/src/CommonLibrariesForNET/AuthenticationClient.cs index e3681996..a0a0d127 100644 --- a/src/CommonLibrariesForNET/AuthenticationClient.cs +++ b/src/CommonLibrariesForNET/AuthenticationClient.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System; +using System; using System.Collections.Generic; using System.Net.Http; using System.Threading.Tasks; @@ -46,7 +44,7 @@ public async Task UsernamePasswordAsync(string clientId, string clientSecret, st if (string.IsNullOrEmpty(username)) throw new ArgumentNullException("username"); if (string.IsNullOrEmpty(password)) throw new ArgumentNullException("password"); if (string.IsNullOrEmpty(tokenRequestEndpointUrl)) throw new ArgumentNullException("tokenRequestEndpointUrl"); - //TODO: check to make sure tokenRequestEndpointUrl is a valid URI + if (!Uri.IsWellFormedUriString(tokenRequestEndpointUrl, UriKind.Absolute)) throw new FormatException("tokenRequestEndpointUrl"); var content = new FormUrlEncodedContent(new[] { @@ -57,7 +55,7 @@ public async Task UsernamePasswordAsync(string clientId, string clientSecret, st new KeyValuePair("password", password) }); - var request = new HttpRequestMessage() + var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(tokenRequestEndpointUrl), @@ -94,10 +92,10 @@ public async Task WebServerAsync(string clientId, string clientSecret, string re if (string.IsNullOrEmpty(clientId)) throw new ArgumentNullException("clientId"); if (string.IsNullOrEmpty(clientSecret)) throw new ArgumentNullException("clientSecret"); if (string.IsNullOrEmpty(redirectUri)) throw new ArgumentNullException("redirectUri"); - //TODO: check to make sure redirectUri is a valid URI + if (!Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute)) throw new FormatException("redirectUri"); if (string.IsNullOrEmpty(code)) throw new ArgumentNullException("code"); if (string.IsNullOrEmpty(tokenRequestEndpointUrl)) throw new ArgumentNullException("tokenRequestEndpointUrl"); - //TODO: check to make sure tokenRequestEndpointUrl is a valid URI + if (!Uri.IsWellFormedUriString(tokenRequestEndpointUrl, UriKind.Absolute)) throw new FormatException("tokenRequestEndpointUrl"); var content = new FormUrlEncodedContent(new[] { @@ -105,10 +103,10 @@ public async Task WebServerAsync(string clientId, string clientSecret, string re new KeyValuePair("client_id", clientId), new KeyValuePair("client_secret", clientSecret), new KeyValuePair("redirect_uri", redirectUri), - new KeyValuePair("code", code), + new KeyValuePair("code", code) }); - var request = new HttpRequestMessage() + var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(tokenRequestEndpointUrl), @@ -149,7 +147,7 @@ public async Task TokenRefreshAsync(string clientId, string refreshToken, string refreshToken, clientSecret); - var request = new HttpRequestMessage() + var request = new HttpRequestMessage { Method = HttpMethod.Post, RequestUri = new Uri(url) @@ -177,7 +175,6 @@ public async Task TokenRefreshAsync(string clientId, string refreshToken, string public void Dispose() { - //TODO: catch in case this has already been disposed or deallocated? _httpClient.Dispose(); } } diff --git a/src/CommonLibrariesForNET/Common.cs b/src/CommonLibrariesForNET/Common.cs index a7a36340..ecaf443b 100644 --- a/src/CommonLibrariesForNET/Common.cs +++ b/src/CommonLibrariesForNET/Common.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System; +using System; using Salesforce.Common.Models; namespace Salesforce.Common @@ -13,7 +11,6 @@ public static string FormatUrl(string resourceName, string instanceUrl, string a if (string.IsNullOrEmpty(instanceUrl)) throw new ArgumentNullException("instanceUrl"); if (string.IsNullOrEmpty(apiVersion)) throw new ArgumentNullException("apiVersion"); - // is query a nextRecordUrl request? if (resourceName.StartsWith("/services/data", StringComparison.CurrentCultureIgnoreCase)) { return string.Format("{0}{1}", instanceUrl, resourceName); diff --git a/src/CommonLibrariesForNET/ForceAuthException.cs b/src/CommonLibrariesForNET/ForceAuthException.cs index fb66f417..95e02247 100644 --- a/src/CommonLibrariesForNET/ForceAuthException.cs +++ b/src/CommonLibrariesForNET/ForceAuthException.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using Salesforce.Common.Models; +using Salesforce.Common.Models; namespace Salesforce.Common { diff --git a/src/CommonLibrariesForNET/ForceException.cs b/src/CommonLibrariesForNET/ForceException.cs index 47423f21..6951ae05 100644 --- a/src/CommonLibrariesForNET/ForceException.cs +++ b/src/CommonLibrariesForNET/ForceException.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System; +using System; using Salesforce.Common.Models; namespace Salesforce.Common diff --git a/src/CommonLibrariesForNET/IAuthenticationClient.cs b/src/CommonLibrariesForNET/IAuthenticationClient.cs index 3e2f8782..359f9a96 100644 --- a/src/CommonLibrariesForNET/IAuthenticationClient.cs +++ b/src/CommonLibrariesForNET/IAuthenticationClient.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Salesforce.Common { diff --git a/src/CommonLibrariesForNET/IForceException.cs b/src/CommonLibrariesForNET/IForceException.cs index 2dd6f512..e4158625 100644 --- a/src/CommonLibrariesForNET/IForceException.cs +++ b/src/CommonLibrariesForNET/IForceException.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System; +using System; using System.Collections; namespace Salesforce.Common diff --git a/src/CommonLibrariesForNET/IServiceClient.cs b/src/CommonLibrariesForNET/IServiceClient.cs index b3244b65..c5c7b3c0 100644 --- a/src/CommonLibrariesForNET/IServiceClient.cs +++ b/src/CommonLibrariesForNET/IServiceClient.cs @@ -1,5 +1,3 @@ -//TODO: add license header - using System.Threading.Tasks; using Salesforce.Common.Models; @@ -8,7 +6,6 @@ namespace Salesforce.Common public interface IServiceHttpClient { Task HttpGetAsync(string urlSuffix); - //Task HttpGetAsync(string urlSuffix, string nodeName); Task HttpPostAsync(object inputObject, string urlSuffix); Task HttpPatchAsync(object inputObject, string urlSuffix); Task HttpDeleteAsync(string urlSuffix); diff --git a/src/CommonLibrariesForNET/Models/AuthErrorResponse.cs b/src/CommonLibrariesForNET/Models/AuthErrorResponse.cs index 6516e603..d74a07a3 100644 --- a/src/CommonLibrariesForNET/Models/AuthErrorResponse.cs +++ b/src/CommonLibrariesForNET/Models/AuthErrorResponse.cs @@ -1,7 +1,4 @@ -//TODO: add license header -//TODO: refactor casing? - -namespace Salesforce.Common.Models +namespace Salesforce.Common.Models { public class AuthErrorResponse { diff --git a/src/CommonLibrariesForNET/Models/AuthToken.cs b/src/CommonLibrariesForNET/Models/AuthToken.cs index 18f440df..294bdea7 100644 --- a/src/CommonLibrariesForNET/Models/AuthToken.cs +++ b/src/CommonLibrariesForNET/Models/AuthToken.cs @@ -1,7 +1,4 @@ -//TODO: add license header -//TODO: refactor casing? - -namespace Salesforce.Common.Models +namespace Salesforce.Common.Models { public class AuthToken { diff --git a/src/CommonLibrariesForNET/Models/Error.cs b/src/CommonLibrariesForNET/Models/Error.cs index f68eb9b5..879845ca 100644 --- a/src/CommonLibrariesForNET/Models/Error.cs +++ b/src/CommonLibrariesForNET/Models/Error.cs @@ -1,7 +1,4 @@ -//TODO: add license header -//TODO: refactor casing? - -namespace Salesforce.Common.Models +namespace Salesforce.Common.Models { public enum Error { diff --git a/src/CommonLibrariesForNET/Models/ErrorResponse.cs b/src/CommonLibrariesForNET/Models/ErrorResponse.cs index 00722b1c..b1541cd4 100644 --- a/src/CommonLibrariesForNET/Models/ErrorResponse.cs +++ b/src/CommonLibrariesForNET/Models/ErrorResponse.cs @@ -1,7 +1,4 @@ -//TODO: add license header -//TODO: refactor casing? - -namespace Salesforce.Common.Models +namespace Salesforce.Common.Models { public class ErrorResponse { diff --git a/src/CommonLibrariesForNET/Models/ErrorResponses.cs b/src/CommonLibrariesForNET/Models/ErrorResponses.cs index 02e88f3d..5cebedb5 100644 --- a/src/CommonLibrariesForNET/Models/ErrorResponses.cs +++ b/src/CommonLibrariesForNET/Models/ErrorResponses.cs @@ -1,7 +1,4 @@ -//TODO: add license header -//TODO: refactor casing? - -using System.Collections.Generic; +using System.Collections.Generic; namespace Salesforce.Common.Models { diff --git a/src/CommonLibrariesForNET/Models/SuccessResponse.cs b/src/CommonLibrariesForNET/Models/SuccessResponse.cs index 3e50b2ca..4df91e3f 100644 --- a/src/CommonLibrariesForNET/Models/SuccessResponse.cs +++ b/src/CommonLibrariesForNET/Models/SuccessResponse.cs @@ -1,7 +1,4 @@ -//TODO: add license header -//TODO: refactor casing? - -namespace Salesforce.Common.Models +namespace Salesforce.Common.Models { public class SuccessResponse { diff --git a/src/CommonLibrariesForNET/ServiceHttpClient.cs b/src/CommonLibrariesForNET/ServiceHttpClient.cs index 94929ffb..f10b478f 100644 --- a/src/CommonLibrariesForNET/ServiceHttpClient.cs +++ b/src/CommonLibrariesForNET/ServiceHttpClient.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; @@ -16,21 +14,19 @@ namespace Salesforce.Common { public class ServiceHttpClient : IServiceHttpClient, IDisposable { - private static string _userAgent = "forcedotcom-toolkit-dotnet"; + private const string UserAgent = "forcedotcom-toolkit-dotnet"; private readonly string _instanceUrl; private readonly string _apiVersion; - private readonly string _accessToken; - private HttpClient _httpClient; + private readonly HttpClient _httpClient; public ServiceHttpClient(string instanceUrl, string apiVersion, string accessToken, HttpClient httpClient) { _instanceUrl = instanceUrl; _apiVersion = apiVersion; - _accessToken = accessToken; _httpClient = httpClient; - _httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(string.Concat(_userAgent, "/", _apiVersion)); - _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _accessToken); + _httpClient.DefaultRequestHeaders.UserAgent.ParseAdd(string.Concat(UserAgent, "/", _apiVersion)); + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); _httpClient.DefaultRequestHeaders.Accept.Clear(); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); @@ -45,7 +41,7 @@ public async Task HttpGetAsync(string urlSuffix) { var url = Common.FormatUrl(urlSuffix, _instanceUrl, _apiVersion); - var request = new HttpRequestMessage() + var request = new HttpRequestMessage { RequestUri = new Uri(url), Method = HttpMethod.Get @@ -176,8 +172,7 @@ public async Task HttpPostAsync(object inputObject, Uri uri) NullValueHandling = NullValueHandling.Ignore, }); - var content = new StringContent(inputObject.ToString(), Encoding.UTF8, "application/json"); - + var content = new StringContent(json, Encoding.UTF8, "application/json"); var responseMessage = await _httpClient.PostAsync(uri, content).ConfigureAwait(false); var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); @@ -195,7 +190,7 @@ public async Task HttpPatchAsync(object inputObject, string url { var url = Common.FormatUrl(urlSuffix, _instanceUrl, _apiVersion); - var request = new HttpRequestMessage() + var request = new HttpRequestMessage { RequestUri = new Uri(url), Method = new HttpMethod("PATCH") @@ -233,7 +228,7 @@ public async Task HttpDeleteAsync(string urlSuffix) { var url = Common.FormatUrl(urlSuffix, _instanceUrl, _apiVersion); - var request = new HttpRequestMessage() + var request = new HttpRequestMessage { RequestUri = new Uri(url), Method = HttpMethod.Delete diff --git a/src/ForceToolkitForNET/ForceClient.cs b/src/ForceToolkitForNET/ForceClient.cs index 93f0ebd0..1818318c 100644 --- a/src/ForceToolkitForNET/ForceClient.cs +++ b/src/ForceToolkitForNET/ForceClient.cs @@ -1,7 +1,4 @@ -//TODO: add license header - -using System; -using System.Collections.Generic; +using System; using System.Linq; using System.Net.Http; using System.Threading.Tasks; @@ -13,8 +10,7 @@ namespace Salesforce.Force { public class ForceClient : IForceClient, IDisposable { - private ServiceHttpClient _serviceHttpClient; - private const string UserAgent = "forcedotcom-toolkit-dotnet"; + private readonly ServiceHttpClient _serviceHttpClient; public ForceClient(string instanceUrl, string accessToken, string apiVersion) : this(instanceUrl, accessToken, apiVersion, new HttpClient()) @@ -28,8 +24,6 @@ public ForceClient(string instanceUrl, string accessToken, string apiVersion, Ht if (string.IsNullOrEmpty(apiVersion)) throw new ArgumentNullException("apiVersion"); if (httpClient == null) throw new ArgumentNullException("httpClient"); - //TODO: implement try/catch and throw auth exception if appropriate - _serviceHttpClient = new ServiceHttpClient(instanceUrl, apiVersion, accessToken, httpClient); } @@ -66,8 +60,6 @@ public async Task CreateAsync(string objectName, object record) if (string.IsNullOrEmpty(objectName)) throw new ArgumentNullException("objectName"); if (record == null) throw new ArgumentNullException("record"); - //TODO: implement try/catch and throw auth exception if appropriate - var response = await _serviceHttpClient.HttpPostAsync(record, string.Format("sobjects/{0}", objectName)).ConfigureAwait(false); return response.id; } @@ -78,8 +70,6 @@ public Task UpdateAsync(string objectName, string recordId, obj if (string.IsNullOrEmpty(recordId)) throw new ArgumentNullException("recordId"); if (record == null) throw new ArgumentNullException("record"); - //TODO: implement try/catch and throw auth exception if appropriate - return _serviceHttpClient.HttpPatchAsync(record, string.Format("sobjects/{0}/{1}", objectName, recordId)); } @@ -90,8 +80,6 @@ public Task UpsertExternalAsync(string objectName, string exter if (string.IsNullOrEmpty(externalId)) throw new ArgumentNullException("externalId"); if (record == null) throw new ArgumentNullException("record"); - //TODO: implement try/catch and throw auth exception if appropriate - return _serviceHttpClient.HttpPatchAsync(record, string.Format("sobjects/{0}/{1}/{2}", objectName, externalFieldName, externalId)); } @@ -100,22 +88,17 @@ public Task DeleteAsync(string objectName, string recordId) if (string.IsNullOrEmpty(objectName)) throw new ArgumentNullException("objectName"); if (string.IsNullOrEmpty(recordId)) throw new ArgumentNullException("recordId"); - //TODO: implement try/catch and throw auth exception if appropriate - return _serviceHttpClient.HttpDeleteAsync(string.Format("sobjects/{0}/{1}", objectName, recordId)); } public Task> GetObjectsAsync() { - //TODO: implement try/catch and throw auth exception if appropriate - return _serviceHttpClient.HttpGetAsync>("sobjects"); } public Task BasicInformationAsync(string objectName) { if (string.IsNullOrEmpty(objectName)) throw new ArgumentNullException("objectName"); - //TODO: implement try/catch and throw auth exception if appropriate return _serviceHttpClient.HttpGetAsync(string.Format("sobjects/{0}", objectName)); } @@ -123,7 +106,6 @@ public Task BasicInformationAsync(string objectName) public Task DescribeAsync(string objectName) { if (string.IsNullOrEmpty(objectName)) throw new ArgumentNullException("objectName"); - //TODO: implement try/catch and throw auth exception if appropriate return _serviceHttpClient.HttpGetAsync(string.Format("sobjects/{0}/describe/", objectName)); } @@ -131,7 +113,6 @@ public Task DescribeAsync(string objectName) public Task DescribeLayoutAsync(string objectName) { if (string.IsNullOrEmpty(objectName)) throw new ArgumentNullException("objectName"); - //TODO: implement try/catch and throw auth exception if appropriate return _serviceHttpClient.HttpGetAsync(string.Format("sobjects/{0}/describe/layouts/", objectName)); } @@ -140,24 +121,21 @@ public Task DescribeLayoutAsync(string objectName, string recordTypeId) { if (string.IsNullOrEmpty(objectName)) throw new ArgumentNullException("objectName"); if (string.IsNullOrEmpty(recordTypeId)) throw new ArgumentNullException("recordTypeId"); - //TODO: implement try/catch and throw auth exception if appropriate return _serviceHttpClient.HttpGetAsync(string.Format("sobjects/{0}/describe/layouts/{1}", objectName, recordTypeId)); } public Task RecentAsync(int limit = 200) { - //TODO: implement try/catch and throw auth exception if appropriate - return _serviceHttpClient.HttpGetAsync(string.Format("recent/?limit={0}", limit)); } - public async Task UserInfo(string uri) + public async Task UserInfo(string url) { - if (string.IsNullOrEmpty(uri)) throw new ArgumentNullException("uri"); - //TODO: implement try/catch and throw auth exception if appropriate + if (string.IsNullOrEmpty(url)) throw new ArgumentNullException("url"); + if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) throw new FormatException("url"); - var response = await _serviceHttpClient.HttpGetAsync(new Uri(uri)); + var response = await _serviceHttpClient.HttpGetAsync(new Uri(url)); return response; } diff --git a/src/ForceToolkitForNET/IForceClient.cs b/src/ForceToolkitForNET/IForceClient.cs index 56c89be8..bf752f07 100644 --- a/src/ForceToolkitForNET/IForceClient.cs +++ b/src/ForceToolkitForNET/IForceClient.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System.Threading.Tasks; +using System.Threading.Tasks; using Salesforce.Common.Models; namespace Salesforce.Force diff --git a/src/ForceToolkitForNet.FunctionalTests/Models/Account.cs b/src/ForceToolkitForNet.FunctionalTests/Models/Account.cs index c4f50b68..59715f3c 100644 --- a/src/ForceToolkitForNet.FunctionalTests/Models/Account.cs +++ b/src/ForceToolkitForNet.FunctionalTests/Models/Account.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -namespace Salesforce.Force.FunctionalTests.Models +namespace Salesforce.Force.FunctionalTests.Models { public class Account { diff --git a/src/ForceToolkitForNet.UnitTests/FakeHttpRequestHandler.cs b/src/ForceToolkitForNet.UnitTests/FakeHttpRequestHandler.cs index e2343517..9961bc1a 100644 --- a/src/ForceToolkitForNet.UnitTests/FakeHttpRequestHandler.cs +++ b/src/ForceToolkitForNet.UnitTests/FakeHttpRequestHandler.cs @@ -1,8 +1,4 @@ -//TODO: add license header - -using System; -using System.Net; -using System.Net.Http; +using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -10,7 +6,7 @@ namespace Salesforce.Force.UnitTests { public class FakeHttpRequestHandler : DelegatingHandler { - HttpResponseMessage _expectedResponse; + readonly HttpResponseMessage _expectedResponse; public FakeHttpRequestHandler(HttpResponseMessage expectedResponse) { @@ -24,5 +20,4 @@ protected override Task SendAsync(HttpRequestMessage reques return tsc.Task; } } - } diff --git a/src/ForceToolkitForNet.UnitTests/ForceClientTests.cs b/src/ForceToolkitForNet.UnitTests/ForceClientTests.cs index 357461f2..6a79f7bd 100644 --- a/src/ForceToolkitForNet.UnitTests/ForceClientTests.cs +++ b/src/ForceToolkitForNet.UnitTests/ForceClientTests.cs @@ -9,10 +9,12 @@ namespace Salesforce.Force.UnitTests [TestFixture] public class ForceClientTests { + private const string UserAgent = "forcedotcom-toolkit-dotnet"; + [Test] public async void Requests_CheckHttpRequestMessage_UserAgent() { - var httpClient = new HttpClient(new ServiceClientRouteHandler(r => Assert.AreEqual(r.Headers.UserAgent.ToString(), "forcedotcom-toolkit-dotnet/v32"))); + var httpClient = new HttpClient(new ServiceClientRouteHandler(r => Assert.AreEqual(r.Headers.UserAgent.ToString(), UserAgent + "/v32"))); var forceClient = new ForceClient("http://localhost:1899", "accessToken", "v32", httpClient); try diff --git a/src/ForceToolkitForNet.UnitTests/JsonContent.cs b/src/ForceToolkitForNet.UnitTests/JsonContent.cs index fb338e86..2f8c25b8 100644 --- a/src/ForceToolkitForNet.UnitTests/JsonContent.cs +++ b/src/ForceToolkitForNet.UnitTests/JsonContent.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System.IO; +using System.IO; using System.Net; using System.Net.Http; using System.Net.Http.Headers; diff --git a/src/ForceToolkitForNet.UnitTests/ServiceClientRouteHandler.cs b/src/ForceToolkitForNet.UnitTests/ServiceClientRouteHandler.cs index e93029cf..084b02f8 100644 --- a/src/ForceToolkitForNet.UnitTests/ServiceClientRouteHandler.cs +++ b/src/ForceToolkitForNet.UnitTests/ServiceClientRouteHandler.cs @@ -1,6 +1,4 @@ -//TODO: add license header - -using System; +using System; using System.Net; using System.Net.Http; using System.Threading; @@ -10,7 +8,7 @@ namespace Salesforce.Force.UnitTests { internal class ServiceClientRouteHandler : DelegatingHandler { - Action _testingAction; + readonly Action _testingAction; public ServiceClientRouteHandler(Action testingAction) {