From ba68b3e7b0261701c7183c1299254650ca116697 Mon Sep 17 00:00:00 2001 From: Robot Date: Tue, 30 Nov 2021 11:55:08 +0000 Subject: [PATCH] Changes generated by c35f26643f46cec4fb4fe628e784bbe79ffc184f --- GoCardless.Tests/BlockServiceTests.cs | 71 +++++++++++++++++++ GoCardless.Tests/GoCardless.Tests.csproj | 9 +++ .../block_service/blockbyref_request.json | 7 ++ .../block_service/blockbyref_response.json | 22 ++++++ .../client/block_service/get_response.json | 11 +++ GoCardless/GoCardless.csproj | 4 +- GoCardless/GoCardlessClient.cs | 4 +- README.md | 2 +- 8 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 GoCardless.Tests/BlockServiceTests.cs create mode 100644 GoCardless.Tests/fixtures/client/block_service/blockbyref_request.json create mode 100644 GoCardless.Tests/fixtures/client/block_service/blockbyref_response.json create mode 100644 GoCardless.Tests/fixtures/client/block_service/get_response.json diff --git a/GoCardless.Tests/BlockServiceTests.cs b/GoCardless.Tests/BlockServiceTests.cs new file mode 100644 index 0000000..bc440da --- /dev/null +++ b/GoCardless.Tests/BlockServiceTests.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using GoCardless.Resources; +using GoCardless.Services; +using NUnit.Framework; +using FluentAssertions; + +namespace GoCardless.Tests +{ + public class BlockServiceTests + { + private GoCardlessClient client; + public MockHttp mockHttp; + + [SetUp] + public void SetUp() + { + mockHttp = new MockHttp(); + var httpClient = new HttpClient(mockHttp); + client = GoCardlessClient.Create("access-token", "https://api.example.com", httpClient); + } + + [Test] + public async Task ShouldGetBlock() + { + var responseFixture = "fixtures/client/block_service/get_response.json"; + mockHttp.EnqueueResponse(200, responseFixture); + + var resp = await client.Blocks.GetAsync("BLC456"); + mockHttp.AssertRequestMade("GET","/blocks/BLC456"); + 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, "example@example.com"); + Assert.AreEqual(block.Active, true); + Assert.AreEqual(block.CreatedAt.ToString(), "03/25/2021 17:26:28 +00:00"); + } + + [Test] + public async Task ShouldBlockByRef() + { + var responseFixture = "fixtures/client/block_service/blockbyref_response.json"; + mockHttp.EnqueueResponse(200, responseFixture); + + var request = new BlockBlockByRefRequest(){ + ReasonType = BlockBlockByRefRequest.BlockReasonType.NoIntentToPay.ToString(), + ReferenceType = BlockBlockByRefRequest.BlockReferenceType.Customer.ToString(), + ReferenceValue = "CU123", + }; + var resp = await client.Blocks.BlockByRefAsync(request); + mockHttp.AssertRequestMade("POST","/block_by_ref"); + TestHelpers.AssertResponseCanSerializeBackToFixture(resp, responseFixture); + + IReadOnlyList 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, "example@example.com"); + 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"); + } + } +} diff --git a/GoCardless.Tests/GoCardless.Tests.csproj b/GoCardless.Tests/GoCardless.Tests.csproj index 6acb654..0f7a04c 100644 --- a/GoCardless.Tests/GoCardless.Tests.csproj +++ b/GoCardless.Tests/GoCardless.Tests.csproj @@ -103,6 +103,15 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/GoCardless.Tests/fixtures/client/block_service/blockbyref_request.json b/GoCardless.Tests/fixtures/client/block_service/blockbyref_request.json new file mode 100644 index 0000000..7877afc --- /dev/null +++ b/GoCardless.Tests/fixtures/client/block_service/blockbyref_request.json @@ -0,0 +1,7 @@ +{ + "blocks": { + "reference_type": "customer", + "reference_value": "CU123", + "reason_type": "no_intent_to_pay" + } + } \ No newline at end of file diff --git a/GoCardless.Tests/fixtures/client/block_service/blockbyref_response.json b/GoCardless.Tests/fixtures/client/block_service/blockbyref_response.json new file mode 100644 index 0000000..c18a97b --- /dev/null +++ b/GoCardless.Tests/fixtures/client/block_service/blockbyref_response.json @@ -0,0 +1,22 @@ +{ + "blocks": [ + { + "id": "BLC123", + "block_type": "email", + "reason_type": "no_intent_to_pay", + "resource_reference": "example@example.com", + "active": true, + "created_at": "2021-03-25T17:26:28.305Z", + "updated_at": "2021-03-25T17:26:28.305Z" + }, + { + "id": "BLC456", + "block_type": "bank_account", + "reason_type": "no_intent_to_pay", + "resource_reference": "BA123", + "active": true, + "created_at": "2021-03-25T17:26:28.305Z", + "updated_at": "2021-03-25T17:26:28.305Z" + } + ] + } \ No newline at end of file diff --git a/GoCardless.Tests/fixtures/client/block_service/get_response.json b/GoCardless.Tests/fixtures/client/block_service/get_response.json new file mode 100644 index 0000000..fff1cf2 --- /dev/null +++ b/GoCardless.Tests/fixtures/client/block_service/get_response.json @@ -0,0 +1,11 @@ +{ + "blocks": { + "id": "BLC456", + "block_type": "email", + "reason_type": "no_intent_to_pay", + "resource_reference": "example@example.com", + "active": true, + "created_at": "2021-03-25T17:26:28.305Z", + "updated_at": "2021-03-25T17:26:28.305Z" + } +} \ No newline at end of file diff --git a/GoCardless/GoCardless.csproj b/GoCardless/GoCardless.csproj index 212f62a..04d2c91 100644 --- a/GoCardless/GoCardless.csproj +++ b/GoCardless/GoCardless.csproj @@ -2,7 +2,7 @@ GoCardless - 5.1.0 + 5.2.0 GoCardless Ltd Client for the GoCardless API - a powerful, simple solution for the collection of recurring bank-to-bank payments false @@ -11,7 +11,7 @@ GoCardless Ltd gocardless payments rest api direct debit https://github.com/gocardless/gocardless-dotnet/blob/master/LICENSE.txt - https://github.com/gocardless/gocardless-dotnet/releases/tag/v5.1.0 + https://github.com/gocardless/gocardless-dotnet/releases/tag/v5.2.0 netstandard1.6;netstandard2.0;net46 True true diff --git a/GoCardless/GoCardlessClient.cs b/GoCardless/GoCardlessClient.cs index cbdf6b3..7acac41 100644 --- a/GoCardless/GoCardlessClient.cs +++ b/GoCardless/GoCardlessClient.cs @@ -277,11 +277,11 @@ private HttpRequestMessage BuildHttpRequestMessage(string method, string path runtimeFrameworkInformation = System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion(); #endif - var userAgentInformation = $" gocardless-dotnet/5.1.0 {runtimeFrameworkInformation} {Helpers.CleanupOSDescriptionString(OSRunningOn)}"; + var userAgentInformation = $" gocardless-dotnet/5.2.0 {runtimeFrameworkInformation} {Helpers.CleanupOSDescriptionString(OSRunningOn)}"; requestMessage.Headers.Add("User-Agent", userAgentInformation); requestMessage.Headers.Add("GoCardless-Version", "2015-07-06"); - requestMessage.Headers.Add("GoCardless-Client-Version", "5.1.0"); + requestMessage.Headers.Add("GoCardless-Client-Version", "5.2.0"); requestMessage.Headers.Add("GoCardless-Client-Library", "gocardless-dotnet"); requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _accessToken); diff --git a/README.md b/README.md index 360ef14..ea69411 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ For full details of the GoCardless API, see the [API docs](https://developer.goc To install `GoCardless`, run the following command in the [Package Manager Console](https://docs.microsoft.com/en-us/nuget/tools/package-manager-console) -`Install-Package GoCardless -Version 5.1.0` +`Install-Package GoCardless -Version 5.2.0` ## Usage