Skip to content

Commit

Permalink
Changes from gocardless/gocardless-dotnet-template (#123)
Browse files Browse the repository at this point in the history
* Changes generated by 7576ee27e663fe49910aea2d74830697f42b468d

This commit was automatically created from gocardless/gocardless-dotnet-template@7576ee2
by the `push-files` action.

Workflow run: https://github.com/gocardless/gocardless-dotnet-template/actions/runs/8836016263

* Changes generated by 82feafb3c2b47b587a70f12be4a4dbe577b15a9c

This commit was automatically created from gocardless/gocardless-dotnet-template@82feafb
by the `push-files` action.

Workflow run: https://github.com/gocardless/gocardless-dotnet-template/actions/runs/8836129911

* Changes generated by 3b4ce8c8a72faba63487a0c676b54afb669fdcd7

This commit was automatically created from gocardless/gocardless-dotnet-template@3b4ce8c
by the `push-files` action.

Workflow run: https://github.com/gocardless/gocardless-dotnet-template/actions/runs/8836140144

---------

Co-authored-by: gocardless-ci-robot[bot] <123969075+gocardless-ci-robot[bot]@users.noreply.github.com>
  • Loading branch information
gocardless-ci-robot[bot] authored Apr 25, 2024
1 parent c7811a2 commit ccbdd7c
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 97 deletions.
29 changes: 15 additions & 14 deletions GoCardless.Tests/BlockServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using GoCardless.Resources;
using GoCardless.Services;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using FluentAssertions;

namespace GoCardless.Tests
Expand Down Expand Up @@ -34,12 +35,12 @@ public async Task ShouldGetBlock()
TestHelpers.AssertResponseCanSerializeBackToFixture(resp, responseFixture);

GoCardless.Resources.Block block = resp.Block;
Assert.AreEqual(block.Id, "BLC456");
Assert.AreEqual(block.BlockType, "email");
Assert.AreEqual(block.ReasonType, "no_intent_to_pay");
Assert.AreEqual(block.ResourceReference, "[email protected]");
Assert.AreEqual(block.Active, true);
Assert.AreEqual(block.CreatedAt.Value.ToString("o"), "2021-03-25T17:26:28.3050000+00:00");
ClassicAssert.AreEqual(block.Id, "BLC456");
ClassicAssert.AreEqual(block.BlockType, "email");
ClassicAssert.AreEqual(block.ReasonType, "no_intent_to_pay");
ClassicAssert.AreEqual(block.ResourceReference, "[email protected]");
ClassicAssert.AreEqual(block.Active, true);
ClassicAssert.AreEqual(block.CreatedAt.Value.ToString("o"), "2021-03-25T17:26:28.3050000+00:00");
}

[Test]
Expand All @@ -61,14 +62,14 @@ public async Task ShouldBlockByRef()
resp.Meta.Cursors.After.Should().BeNull();

IReadOnlyList<GoCardless.Resources.Block> blocks = resp.Blocks;
Assert.AreEqual(blocks[0].Id, "BLC123");
Assert.AreEqual(blocks[0].BlockType, "email");
Assert.AreEqual(blocks[0].ReasonType, "no_intent_to_pay");
Assert.AreEqual(blocks[0].ResourceReference, "[email protected]");
Assert.AreEqual(blocks[1].Id, "BLC456");
Assert.AreEqual(blocks[1].BlockType, "bank_account");
Assert.AreEqual(blocks[1].ReasonType, "no_intent_to_pay");
Assert.AreEqual(blocks[1].ResourceReference, "BA123");
ClassicAssert.AreEqual(blocks[0].Id, "BLC123");
ClassicAssert.AreEqual(blocks[0].BlockType, "email");
ClassicAssert.AreEqual(blocks[0].ReasonType, "no_intent_to_pay");
ClassicAssert.AreEqual(blocks[0].ResourceReference, "[email protected]");
ClassicAssert.AreEqual(blocks[1].Id, "BLC456");
ClassicAssert.AreEqual(blocks[1].BlockType, "bank_account");
ClassicAssert.AreEqual(blocks[1].ReasonType, "no_intent_to_pay");
ClassicAssert.AreEqual(blocks[1].ResourceReference, "BA123");
}
}
}
73 changes: 37 additions & 36 deletions GoCardless.Tests/ErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using GoCardless.Errors;
using GoCardless.Exceptions;

Expand Down Expand Up @@ -34,14 +35,14 @@ public async Task InsufficentPermissions()
catch (InsufficientPermissionsException ex)
{
TestHelpers.AssertResponseCanSerializeBackToFixture(ex.ApiErrorResponse, responseFixture);
Assert.AreEqual(ApiErrorType.INSUFFICIENT_PERMISSIONS, ex.Type);
Assert.AreEqual("Insufficient permissions", ex.Message);
Assert.AreEqual("Insufficient permissions", ex.Errors.Single().Message);
Assert.AreEqual("insufficient_permissions", ex.Errors.Single().Reason);
Assert.AreEqual("https://developer.gocardless.com/api-reference#insufficient_permissions",
ClassicAssert.AreEqual(ApiErrorType.INSUFFICIENT_PERMISSIONS, ex.Type);
ClassicAssert.AreEqual("Insufficient permissions", ex.Message);
ClassicAssert.AreEqual("Insufficient permissions", ex.Errors.Single().Message);
ClassicAssert.AreEqual("insufficient_permissions", ex.Errors.Single().Reason);
ClassicAssert.AreEqual("https://developer.gocardless.com/api-reference#insufficient_permissions",
ex.DocumentationUrl);
Assert.AreEqual("b0e48853-abcd-41fa-9554-5f71820e915d", ex.RequestId);
Assert.AreEqual(403, ex.Code);
ClassicAssert.AreEqual("b0e48853-abcd-41fa-9554-5f71820e915d", ex.RequestId);
ClassicAssert.AreEqual(403, ex.Code);
return;
}
Assert.Fail("Exception was not thrown");
Expand All @@ -60,15 +61,15 @@ public async Task ValidationErrors()
catch (ValidationFailedException ex)
{
TestHelpers.AssertResponseCanSerializeBackToFixture(ex.ApiErrorResponse, responseFixture);
Assert.AreEqual(ApiErrorType.VALIDATION_FAILED, ex.Type);
Assert.AreEqual("Validation failed", ex.Message);
Assert.AreEqual("scheme", ex.Errors[0].Field);
Assert.AreEqual("must be one of bacs, sepa_core, autogiro", ex.Errors[0].Message);
Assert.AreEqual("/mandates/scheme", ex.Errors[0].RequestPointer);
Assert.AreEqual("https://developer.gocardless.com/api-reference#validation_failed",
ClassicAssert.AreEqual(ApiErrorType.VALIDATION_FAILED, ex.Type);
ClassicAssert.AreEqual("Validation failed", ex.Message);
ClassicAssert.AreEqual("scheme", ex.Errors[0].Field);
ClassicAssert.AreEqual("must be one of bacs, sepa_core, autogiro", ex.Errors[0].Message);
ClassicAssert.AreEqual("/mandates/scheme", ex.Errors[0].RequestPointer);
ClassicAssert.AreEqual("https://developer.gocardless.com/api-reference#validation_failed",
ex.DocumentationUrl);
Assert.AreEqual("2f33a336-abcd-4aeb-85c0-101286065dfd", ex.RequestId);
Assert.AreEqual(422, ex.Code);
ClassicAssert.AreEqual("2f33a336-abcd-4aeb-85c0-101286065dfd", ex.RequestId);
ClassicAssert.AreEqual(422, ex.Code);
return;
}
Assert.Fail("Exception was not thrown");
Expand All @@ -91,10 +92,10 @@ public async Task TrueServerError()
}
catch (ApiException ex)
{
Assert.AreEqual(500, ex.Code);
Assert.AreEqual(ApiErrorType.GOCARDLESS, ex.Type);
Assert.AreEqual("Something went wrong with this request. Please check the ResponseMessage property.", ex.Message);
Assert.AreEqual("500 Internal Server Error", ex.ResponseMessage.Content.ReadAsStringAsync().Result);
ClassicAssert.AreEqual(500, ex.Code);
ClassicAssert.AreEqual(ApiErrorType.GOCARDLESS, ex.Type);
ClassicAssert.AreEqual("Something went wrong with this request. Please check the ResponseMessage property.", ex.Message);
ClassicAssert.AreEqual("500 Internal Server Error", ex.ResponseMessage.Content.ReadAsStringAsync().Result);
return;
}
Assert.Fail("Exception was not thrown");
Expand All @@ -111,10 +112,10 @@ public async Task HtmlErrorPage()
}
catch (ApiException ex)
{
Assert.AreEqual(502, ex.Code);
Assert.AreEqual(ApiErrorType.GOCARDLESS, ex.Type);
Assert.AreEqual("Something went wrong with this request. Please check the ResponseMessage property.", ex.Message);
Assert.AreEqual("<!DOCTYPE html>\n<html>\n <head>\n <title>This is an HTML error page, like one returned by Cloudflare</title>\n </head>\n</html>\n", ex.ResponseMessage.Content.ReadAsStringAsync().Result.Replace("\r\n", "\n"));
ClassicAssert.AreEqual(502, ex.Code);
ClassicAssert.AreEqual(ApiErrorType.GOCARDLESS, ex.Type);
ClassicAssert.AreEqual("Something went wrong with this request. Please check the ResponseMessage property.", ex.Message);
ClassicAssert.AreEqual("<!DOCTYPE html>\n<html>\n <head>\n <title>This is an HTML error page, like one returned by Cloudflare</title>\n </head>\n</html>\n", ex.ResponseMessage.Content.ReadAsStringAsync().Result.Replace("\r\n", "\n"));
return;
}
Assert.Fail("Exception was not thrown");
Expand All @@ -129,7 +130,7 @@ public async Task IdempotencyConflictsAreHandledAutomatically()
//When an attempt to created the mandate is made
var mandate = await this.client.Mandates.CreateAsync(TestHelpers.CreateMandateCreateRequest());
//Then the mandate should be successfully retrieved.
Assert.AreEqual("BA000123", mandate.Mandate.Links.CustomerBankAccount);
ClassicAssert.AreEqual("BA000123", mandate.Mandate.Links.CustomerBankAccount);
}

[Test]
Expand All @@ -149,13 +150,13 @@ public async Task WhenAuthenticationError_ShouldShowSpecificError()
}
catch (AuthenticationFailedException ex)
{
Assert.AreEqual(401, ex.Code);
Assert.AreEqual(ApiErrorType.AUTHENTICATION_FAILED, ex.Type);
Assert.AreEqual("Authentication Failed", ex.Message);
Assert.AreEqual("Authentication Failed", ex.Errors.Single().Message);
Assert.AreEqual("authentication_failed", ex.Errors.Single().Reason);
ClassicAssert.AreEqual(401, ex.Code);
ClassicAssert.AreEqual(ApiErrorType.AUTHENTICATION_FAILED, ex.Type);
ClassicAssert.AreEqual("Authentication Failed", ex.Message);
ClassicAssert.AreEqual("Authentication Failed", ex.Errors.Single().Message);
ClassicAssert.AreEqual("authentication_failed", ex.Errors.Single().Reason);
TestHelpers.AssertResponseCanSerializeBackToFixture(ex.ApiErrorResponse, responseFixture);
Assert.AreEqual("https://developer.gocardless.com/api-reference/#api-usage-errors",
ClassicAssert.AreEqual("https://developer.gocardless.com/api-reference/#api-usage-errors",
ex.DocumentationUrl);
return;
}
Expand All @@ -179,13 +180,13 @@ public async Task WhenRateLimitReachedException_ShouldShowSpecificError()
}
catch (RateLimitReachedException ex)
{
Assert.AreEqual(429, ex.Code);
Assert.AreEqual(ApiErrorType.RATE_LIMIT_REACHED, ex.Type);
Assert.AreEqual("Rate Limit Reached you have made too many requests", ex.Message);
Assert.AreEqual("Rate Limit Reached you have made too many requests", ex.Errors.Single().Message);
Assert.AreEqual("rate_limit_reached", ex.Errors.Single().Reason);
ClassicAssert.AreEqual(429, ex.Code);
ClassicAssert.AreEqual(ApiErrorType.RATE_LIMIT_REACHED, ex.Type);
ClassicAssert.AreEqual("Rate Limit Reached you have made too many requests", ex.Message);
ClassicAssert.AreEqual("Rate Limit Reached you have made too many requests", ex.Errors.Single().Message);
ClassicAssert.AreEqual("rate_limit_reached", ex.Errors.Single().Reason);
TestHelpers.AssertResponseCanSerializeBackToFixture(ex.ApiErrorResponse, responseFixture);
Assert.AreEqual("https://developer.gocardless.com/api-reference/#making-requests-rate-limiting",
ClassicAssert.AreEqual("https://developer.gocardless.com/api-reference/#making-requests-rate-limiting",
ex.DocumentationUrl);
return;
}
Expand Down
37 changes: 19 additions & 18 deletions GoCardless.Tests/FunctionalityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GoCardless.Internals;
using GoCardless.Services;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using System.Threading.Tasks;
using System.Linq;

Expand Down Expand Up @@ -36,7 +37,7 @@ public async Task CanAccessResponseMessageContentAsync()
//Then the responseMessage content can be read
listResponse.ResponseMessage.Should().NotBeNull();
var content = await listResponse.ResponseMessage.Content.ReadAsStringAsync();
Assert.AreEqual(File.ReadAllText("fixtures/client/list_mandates_for_a_customer.json"), content);
ClassicAssert.AreEqual(File.ReadAllText("fixtures/client/list_mandates_for_a_customer.json"), content);
}

[Test]
Expand All @@ -48,9 +49,9 @@ public async Task Headers()
var mandate = mandateResponse.Mandate;
http.AssertRequestMade("POST", "/mandates", null, req =>
{
Assert.AreEqual("Bearer access-token", req.Item1.Headers.GetValues("Authorization").Single());
Assert.AreEqual("2015-07-06", req.Item1.Headers.GetValues("GoCardless-Version").Single());
Assert.AreEqual("gocardless-dotnet", req.Item1.Headers.GetValues("GoCardless-Client-Library").Single());
ClassicAssert.AreEqual("Bearer access-token", req.Item1.Headers.GetValues("Authorization").Single());
ClassicAssert.AreEqual("2015-07-06", req.Item1.Headers.GetValues("GoCardless-Version").Single());
ClassicAssert.AreEqual("gocardless-dotnet", req.Item1.Headers.GetValues("GoCardless-Client-Library").Single());
});
}

Expand All @@ -68,7 +69,7 @@ public async Task IdempotencyKeyIsGeneratedWhenNoneIsSet()
});

//Then an idempotency key should have been set automatically by the client library
Assert.NotNull(idempotencyKey);
ClassicAssert.NotNull(idempotencyKey);

}

Expand All @@ -95,7 +96,7 @@ public async Task ClientCanModifyRequestBeforeSending()
});

//Then the modification should have been applied to the request
Assert.NotNull(customHeader);
ClassicAssert.NotNull(customHeader);
}

[Test]
Expand All @@ -118,11 +119,11 @@ public async Task ClientCanSetCustomHeaders()
http.AssertRequestMade("POST", "/mandates", null, req =>
{
//The brand new header we've set should be there
Assert.AreEqual(req.Item1.Headers.GetValues("Accept-Language").Single(), "fr");
ClassicAssert.AreEqual(req.Item1.Headers.GetValues("Accept-Language").Single(), "fr");
//We should still get the default headers set by the client
Assert.NotNull(req.Item1.Headers.GetValues("Authorization").Single());
ClassicAssert.NotNull(req.Item1.Headers.GetValues("Authorization").Single());
//Headers we set should override the client's default headers
Assert.AreEqual(req.Item1.Headers.GetValues("User-Agent").Single(), "Skynet");
ClassicAssert.AreEqual(req.Item1.Headers.GetValues("User-Agent").Single(), "Skynet");
});
}

Expand Down Expand Up @@ -151,17 +152,17 @@ public async Task RequestRetriesUpToThreeTimesOnTimeout(int numberOfFailures, bo
//Then the idempotency keys should stay the same on successive retries
var newIdempotencyKey = req.Headers.GetValues("Idempotency-Key").Single();
firstIdempotencyKey = firstIdempotencyKey ?? newIdempotencyKey;
Assert.NotNull(newIdempotencyKey);
Assert.AreEqual(firstIdempotencyKey, newIdempotencyKey, "Idempotency keys must match on retried requests");
ClassicAssert.NotNull(newIdempotencyKey);
ClassicAssert.AreEqual(firstIdempotencyKey, newIdempotencyKey, "Idempotency keys must match on retried requests");
}
});
//And if there were enough retries to handle the failures the call should succeed
Assert.True(response.ResponseMessage.IsSuccessStatusCode);
ClassicAssert.True(response.ResponseMessage.IsSuccessStatusCode);
}
catch (TaskCanceledException)
{
//And if not the call should have timed out
Assert.False(requestShouldSucceed);
ClassicAssert.False(requestShouldSucceed);
}

}
Expand Down Expand Up @@ -191,17 +192,17 @@ public async Task RequestRetriesUpToThreeTimesOnConnectionFailure(int numberOfFa
// Then the idempotency keys should stay the same on successive retries
var newIdempotencyKey = req.Headers.GetValues("Idempotency-Key").Single();
firstIdempotencyKey = firstIdempotencyKey ?? newIdempotencyKey;
Assert.NotNull(newIdempotencyKey);
Assert.AreEqual(firstIdempotencyKey, newIdempotencyKey, "Idempotency keys must match on retried requests");
ClassicAssert.NotNull(newIdempotencyKey);
ClassicAssert.AreEqual(firstIdempotencyKey, newIdempotencyKey, "Idempotency keys must match on retried requests");
}
});
//And if there were enough retries to handle the failures the call should succeed
Assert.True(response.ResponseMessage.IsSuccessStatusCode);
ClassicAssert.True(response.ResponseMessage.IsSuccessStatusCode);
}
catch (HttpRequestException)
{
//And if not the call should have timed out
Assert.False(requestShouldSucceed);
ClassicAssert.False(requestShouldSucceed);
}

}
Expand Down Expand Up @@ -234,7 +235,7 @@ public async Task RequestRetriesWithCustomValues(int numberOfFailures, bool shou

}

Assert.AreEqual(shouldBeSuccessful, wasSuccessful);
ClassicAssert.AreEqual(shouldBeSuccessful, wasSuccessful);

}

Expand Down
6 changes: 3 additions & 3 deletions GoCardless.Tests/GoCardless.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.2" />
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="NUnit" Version="3.7.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0-alpha1" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit ccbdd7c

Please sign in to comment.