-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes generated by c35f26643f46cec4fb4fe628e784bbe79ffc184f
- Loading branch information
1 parent
c14809c
commit ba68b3e
Showing
8 changed files
with
125 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
GoCardless.Tests/fixtures/client/block_service/blockbyref_request.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
GoCardless.Tests/fixtures/client/block_service/blockbyref_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
GoCardless.Tests/fixtures/client/block_service/get_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters