Skip to content

Commit

Permalink
Changes generated by c35f26643f46cec4fb4fe628e784bbe79ffc184f
Browse files Browse the repository at this point in the history
  • Loading branch information
gocardless-robot authored and markrofail-gc committed Nov 30, 2021
1 parent c14809c commit ba68b3e
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 5 deletions.
71 changes: 71 additions & 0 deletions GoCardless.Tests/BlockServiceTests.cs
Original file line number Diff line number Diff line change
@@ -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<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, "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");
}
}
}
9 changes: 9 additions & 0 deletions GoCardless.Tests/GoCardless.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@
<None Update="fixtures\rate_limit_reached.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="fixtures\client\block_service\get_response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="fixtures\client\block_service\blockbyref_request.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="fixtures\client\block_service\blockbyref_response.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"blocks": {
"reference_type": "customer",
"reference_value": "CU123",
"reason_type": "no_intent_to_pay"
}
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
11 changes: 11 additions & 0 deletions GoCardless.Tests/fixtures/client/block_service/get_response.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
4 changes: 2 additions & 2 deletions GoCardless/GoCardless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageId>GoCardless</PackageId>
<PackageVersion>5.1.0</PackageVersion>
<PackageVersion>5.2.0</PackageVersion>
<Authors>GoCardless Ltd</Authors>
<Description>Client for the GoCardless API - a powerful, simple solution for the collection of recurring bank-to-bank payments</Description>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
Expand All @@ -11,7 +11,7 @@
<Copyright>GoCardless Ltd</Copyright>
<PackageTags>gocardless payments rest api direct debit</PackageTags>
<PackageLicenseUrl>https://github.com/gocardless/gocardless-dotnet/blob/master/LICENSE.txt</PackageLicenseUrl>
<PackageReleaseNotes>https://github.com/gocardless/gocardless-dotnet/releases/tag/v5.1.0</PackageReleaseNotes>
<PackageReleaseNotes>https://github.com/gocardless/gocardless-dotnet/releases/tag/v5.2.0</PackageReleaseNotes>
<TargetFrameworks>netstandard1.6;netstandard2.0;net46</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
4 changes: 2 additions & 2 deletions GoCardless/GoCardlessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ private HttpRequestMessage BuildHttpRequestMessage<T>(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);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ba68b3e

Please sign in to comment.