Skip to content

Commit

Permalink
Merge pull request #11 from FrendsPlatform/ISSUE_9
Browse files Browse the repository at this point in the history
Result object structure fixes implemented to Salesforce tasks
  • Loading branch information
Svenskapojkarna authored Jun 8, 2022
2 parents bf5a03b + 4039d20 commit 721f315
Show file tree
Hide file tree
Showing 18 changed files with 464 additions and 308 deletions.
6 changes: 5 additions & 1 deletion Frends.Salesforce.CreateSObject/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.1] - 2022-05-27
### Changed
- Fix for issue with referencing result-object in other elements.

## [1.0.0] - 2022-05-06
### Added
- Initial implementation of Frends.Salesforce.CreateSObject
- Initial implementation of Frends.Salesforce.CreateSObject.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ public async Task CreateCaseTest()
_result.Add(new { Type = "Case", Id = caseObj.id });
}

[TestMethod]
public async Task GetReturnedAccessTokenTest()
{
var input = new Input
{
Domain = _domain,
SObjectAsJson = _userJson,
SObjectType = "Account"
};

var options = new Options
{
AuthenticationMethod = AuthenticationMethod.OAuth2WithPassword,
AuthUrl = _authurl,
ClientID = _clientID,
ClientSecret = _clientSecret,
Username = _username,
Password = _password + _securityToken,
ReturnAccessToken = true
};
var result = await Salesforce.CreateSObject(input, options, _cancellationToken);
Assert.IsNotNull(result.Token);

var body = JsonConvert.SerializeObject(result.Body);
var obj = JsonConvert.DeserializeObject<dynamic>(body);
_result.Add(new { Type = "Account", Id = obj.id });
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public async Task EmptyAccessToken_ThrowTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Salesforce
/// <param name="input">Information to create the sobject.</param>
/// <param name="options">Information about the salesforce destination.</param>
/// <param name="cancellationToken"></param>
/// <returns>Object { object Body, bool RequestIsSuccessful, Exception ErrorException, string ErrorMessage }</returns>
/// <returns>Object { object Body, bool RequestIsSuccessful, Exception ErrorException, string ErrorMessage, string Token }</returns>
public static async Task<Result> CreateSObject(
[PropertyTab] Input input,
[PropertyTab] Options options,
Expand Down Expand Up @@ -55,12 +55,10 @@ CancellationToken cancellationToken
var response = await client.ExecuteAsync(request, cancellationToken);
var content = JsonConvert.DeserializeObject<dynamic>(response.Content);

Console.WriteLine(response.ErrorMessage);

if (options.AuthenticationMethod is Definitions.AuthenticationMethod.OAuth2WithPassword && options.ReturnAccessToken)
return new ResultWithToken(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage, accessToken);
if (options.AuthenticationMethod is AuthenticationMethod.OAuth2WithPassword && options.ReturnAccessToken)
return new Result(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage, accessToken);
else
return new Result(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage);
return new Result(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage, string.Empty);
}
catch (JsonException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,18 @@ public class Result
/// <example>System.Net.Http.HttpRequestException: Request failed with status code Unauthorized</example>
public string ErrorMessage { get; private set; }

internal Result(object body, bool succesful, Exception error, string errormessage)
{
Body = body;
RequestIsSuccessful = succesful;
ErrorException = error;
ErrorMessage = errormessage;
}
}

/// <summary>
/// Extended Result-class with access token.
/// </summary>
public class ResultWithToken : Result
{
/// <summary>
/// OAuth2 access token.
/// </summary>
/// <example>abcdefghjklmn123456789</example>
public string Token { get; private set; }

internal ResultWithToken(object body, bool succesful, Exception error, string errormessage, string token) : base(body, succesful, error, errormessage)
internal Result(object body, bool succesful, Exception error, string errormessage, string token)
{
Body = body;
RequestIsSuccessful = succesful;
ErrorException = error;
ErrorMessage = errormessage;
Token = token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand Down
6 changes: 5 additions & 1 deletion Frends.Salesforce.DeleteSObject/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.1] - 2022-05-27
### Changed
- Fix for issue with referencing result-object in other elements.

## [1.0.0] - 2022-05-09
### Added
- Initial implementation of Frends.Salesforce.DeleteSObject
- Initial implementation of Frends.Salesforce.DeleteSObject.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ public async Task DeleteCaseTest()
Assert.IsTrue(accountResult.RequestIsSuccessful);
}

[TestMethod]
public async Task GetReturnedAccessTokenTest()
{
var id = await CreateSObject("Account", _userJson);
var options = new Options
{
AuthenticationMethod = AuthenticationMethod.OAuth2WithPassword,
AuthUrl = _authurl,
ClientID = _clientID,
ClientSecret = _clientSecret,
Username = _username,
Password = _password + _securityToken,
ReturnAccessToken = true
};
var result = await Salesforce.DeleteSObject(new Input { Domain = _domain, SObjectId = id, SObjectType = "Account" }, options, _cancellationToken);

Assert.IsNotNull(result.Token);
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public async Task EmptyAccessToken_ThrowTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,18 @@ public class Result
/// <example>System.Net.Http.HttpRequestException: Request failed with status code Unauthorized</example>
public string ErrorMessage { get; private set; }

internal Result(object body, bool succesful, Exception error, string errormessage)
{
Body = body;
RequestIsSuccessful = succesful;
ErrorException = error;
ErrorMessage = errormessage;
}
}

/// <summary>
/// Extended Result-class with access token.
/// </summary>
public class ResultWithToken : Result
{
/// <summary>
/// OAuth2 access token.
/// </summary>
/// <example>abcdefghjklmn123456789</example>
public string Token { get; private set; }

internal ResultWithToken(object body, bool succesful, Exception error, string errormessage, string token) : base(body, succesful, error, errormessage)
internal Result(object body, bool succesful, Exception error, string errormessage, string token)
{
Body = body;
RequestIsSuccessful = succesful;
ErrorException = error;
ErrorMessage = errormessage;
Token = token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Salesforce
/// <param name="input">Information to delete the sobject.</param>
/// <param name="options">Information about the salesforce destination.</param>
/// <param name="cancellationToken"></param>
/// <returns>Object { object Body, bool RequestIsSuccessful, Exception ErrorException, string ErrorMessage }</returns>
/// <returns>Object { object Body, bool RequestIsSuccessful, Exception ErrorException, string ErrorMessage, string Token }</returns>
public static async Task<Result> DeleteSObject(
[PropertyTab] Input input,
[PropertyTab] Options options,
Expand Down Expand Up @@ -56,10 +56,10 @@ CancellationToken cancellationToken
if (options.ThrowAnErrorIfNotFound && response.ErrorException.ToString().Equals(new HttpRequestException("Request failed with status code NotFound").ToString()))
throw new HttpRequestException("Target couldn't be found with given id.");

if (options.AuthenticationMethod is Definitions.AuthenticationMethod.OAuth2WithPassword && options.ReturnAccessToken)
return new ResultWithToken(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage, accessToken);
if (options.AuthenticationMethod is AuthenticationMethod.OAuth2WithPassword && options.ReturnAccessToken)
return new Result(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage, accessToken);
else
return new Result(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage);
return new Result(content, response.IsSuccessful, response.ErrorException, response.ErrorMessage, string.Empty);
}
catch (ArgumentException)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand Down
6 changes: 5 additions & 1 deletion Frends.Salesforce.ExecuteQuery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [1.0.1] - 2022-05-27
### Changed
- Fix for issue with referencing result-object in other elements.

## [1.0.0] - 2022-03-07
### Added
- Initial implementation of Frends.Salesforce.ExecuteQuery
- Initial implementation of Frends.Salesforce.ExecuteQuery.
Loading

0 comments on commit 721f315

Please sign in to comment.