Skip to content

Commit 26823da

Browse files
committed
Merge branch 'release-0.11.0'
2 parents 325af4c + dbc0895 commit 26823da

File tree

94 files changed

+1939
-1233
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1939
-1233
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
BunqSdk/Model/Generated linguist-generated=true

BunqSdk.Samples/PaymentListSample.cs

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,61 @@
11
using System;
2+
using System.Collections.Generic;
23
using Bunq.Sdk.Context;
4+
using Bunq.Sdk.Http;
35
using Bunq.Sdk.Model.Generated;
46
using Bunq.Sdk.Samples.Utils;
57

68
namespace Bunq.Sdk.Samples
79
{
810
public class PaymentListSample : ISample
911
{
12+
/// <summary>
13+
/// Message constants.
14+
/// </summary>
15+
private const string MESSAGE_LATEST_PAGE_IDS = "Latest page IDs: ";
16+
private const string MESSAGE_SECOND_LATEST_PAGE_IDS = "Second latest page IDs: ";
17+
private const string MESSAGE_NO_PRIOR_PAYMENTS_FOUND = "No prior payments found!";
18+
19+
/// <summary>
20+
/// Size of each page of payment listing.
21+
/// </summary>
22+
private const int PAGE_SIZE = 3;
23+
24+
/// <summary>
25+
/// Constants to be changed to run the example.
26+
/// </summary>
1027
private const int USER_ITEM_ID = 0; // Put your user ID here
1128
private const int MONETARY_ACCOUNT_ITEM_ID = 0; // Put your monetary account ID here
1229

1330
public void Run()
1431
{
1532
var apiContext = ApiContext.Restore();
16-
var paymentList = Payment.List(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID).Value;
33+
var paginationCountOnly = new Pagination
34+
{
35+
Count = PAGE_SIZE,
36+
};
37+
Console.WriteLine(MESSAGE_LATEST_PAGE_IDS);
38+
var paymentResponse = Payment.List(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID,
39+
paginationCountOnly.UrlParamsCountOnly);
40+
PrintPayments(paymentResponse.Value);
41+
var pagination = paymentResponse.Pagination;
42+
43+
if (pagination.HasPreviousPage())
44+
{
45+
Console.WriteLine(MESSAGE_SECOND_LATEST_PAGE_IDS);
46+
var previousPaymentResponse = Payment.List(apiContext, USER_ITEM_ID, MONETARY_ACCOUNT_ITEM_ID,
47+
pagination.UrlParamsPreviousPage);
48+
PrintPayments(previousPaymentResponse.Value);
49+
}
50+
else
51+
{
52+
Console.WriteLine(MESSAGE_NO_PRIOR_PAYMENTS_FOUND);
53+
}
54+
}
1755

18-
foreach (var payment in paymentList)
56+
private static void PrintPayments(IEnumerable<Payment> payments)
57+
{
58+
foreach (var payment in payments)
1959
{
2060
Console.WriteLine(payment.Id);
2161
}

BunqSdk.Tests/BunqSdkTestBase.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class BunqSdkTestBase
2424
/// Configuration items.
2525
/// </summary>
2626
private static readonly string API_KEY = Config.GetApiKey();
27-
private static readonly string FIELD_PERMITTED_IP = Config.GetPermittedIp();
27+
private static readonly string[] FIELD_PERMITTED_IPS = Config.GetPermittedIps();
2828

2929
/// <summary>
3030
/// Gets an Api Context, re-creates if needed and returns it.
@@ -54,9 +54,8 @@ protected static ApiContext GetApiContext()
5454

5555
private static ApiContext CreateApiContext()
5656
{
57-
var permittedIps = new List<string> {FIELD_PERMITTED_IP};
58-
59-
return ApiContext.Create(ApiEnvironmentType.SANDBOX, API_KEY, DEVICE_DESCRIPTION_TEST, permittedIps);
57+
return ApiContext.Create(ApiEnvironmentType.SANDBOX, API_KEY, DEVICE_DESCRIPTION_TEST,
58+
new List<string>(FIELD_PERMITTED_IPS));
6059
}
6160
}
6261
}

BunqSdk.Tests/Config.cs

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
using System.IO;
1+
using System.Collections.Immutable;
2+
using System.IO;
23
using Bunq.Sdk.Model.Generated.Object;
34
using Newtonsoft.Json.Linq;
45

56
namespace Bunq.Sdk.Tests
67
{
78
public class Config
89
{
10+
/// <summary>
11+
/// Delimiter between the IP addresses in the PERMITTED_IPS field.
12+
/// </summary>
13+
private const char DELIMITER_IPS = ',';
14+
15+
/// <summary>
16+
/// Length of an empty array.
17+
/// </summary>
18+
private const int LENGTH_NONE = 0;
19+
20+
/// <summary>
21+
/// Field constants.
22+
/// </summary>
923
private const string FIELD_CONFIG_FILE_PATH = "../../../Resources/config.json";
1024
private const string FIELD_USER_ID = "USER_ID";
1125
private const string FIELD_API_KEY = "API_KEY";
12-
private const string FIELD_PERMITTED_IP = "ipAddress";
26+
private const string FIELD_PERMITTED_IPS = "PERMITTED_IPS";
1327
private const string FIELD_ATTACHMENT_PUBLIC_TEST = "AttachmentPublicTest";
1428
private const string FIELD_ATTACHMENT_PATH_IN = "PATH_IN";
1529
private const string FIELD_ATTACHMENT_DESCRIPTION = "DESCRIPTION";
@@ -28,15 +42,15 @@ public static int GetCashRegisterId()
2842
return GetConfig()[FIELD_TAB_USAGE_SINGLE][FIELD_CASH_REGISTER_ID].ToObject<int>();
2943
}
3044

31-
public static Pointer GetCounterAliasOther()
45+
public static Pointer GetCounterPartyAliasOther()
3246
{
3347
var alias = GetConfig()[FIELD_COUNTER_PARTY_OTHER][FIELD_COUNTER_ALIAS].ToString();
3448
var type = GetConfig()[FIELD_COUNTER_PARTY_OTHER][FIELD_COUNTER_TYPE].ToString();
3549

3650
return new Pointer(type, alias);
3751
}
3852

39-
public static Pointer GetCounterAliasSelf()
53+
public static Pointer GetCounterPartyAliasSelf()
4054
{
4155
var alias = GetConfig()[FIELD_COUNTER_PARTY_SELF][FIELD_COUNTER_ALIAS].ToString();
4256
var type = GetConfig()[FIELD_COUNTER_PARTY_SELF][FIELD_COUNTER_TYPE].ToString();
@@ -69,9 +83,13 @@ public static string GetAttachmentContentType()
6983
return GetConfig()[FIELD_ATTACHMENT_PUBLIC_TEST][FIELD_ATTACHMENT_CONTENT_TYPE].ToString();
7084
}
7185

72-
public static string GetPermittedIp()
86+
public static string[] GetPermittedIps()
7387
{
74-
return GetConfig()[FIELD_PERMITTED_IP].ToString();
88+
var permittedIpsString = GetConfig()[FIELD_PERMITTED_IPS].ToString();
89+
90+
return permittedIpsString.Length == LENGTH_NONE ?
91+
new string[LENGTH_NONE] :
92+
permittedIpsString.Split(DELIMITER_IPS);
7593
}
7694

7795
public static string GetApiKey()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System.Collections.Generic;
2+
using Bunq.Sdk.Context;
3+
using Bunq.Sdk.Http;
4+
using Bunq.Sdk.Json;
5+
using Bunq.Sdk.Model.Generated;
6+
using Bunq.Sdk.Model.Generated.Object;
7+
using Xunit;
8+
9+
namespace Bunq.Sdk.Tests.Http
10+
{
11+
/// <summary>
12+
/// Tests:
13+
/// Pagination
14+
/// </summary>
15+
public class PaginationScenarioTest : BunqSdkTestBase
16+
{
17+
/// <summary>
18+
/// Config values.
19+
/// </summary>
20+
private static readonly int USER_ID = Config.GetUserId();
21+
private static readonly int MONETARY_ACCOUNT_ID = Config.GetMonetarytAccountId();
22+
private static readonly Pointer COUNTER_PARTY_OTHER = Config.GetCounterPartyAliasOther();
23+
24+
/// <summary>
25+
/// Constants for scenario testing.
26+
/// </summary>
27+
private const int PAYMENT_LISTING_PAGE_SIZE = 2;
28+
private const int PAYMENT_REQUIRED_COUNT_MINIMUM = PAYMENT_LISTING_PAGE_SIZE * 2;
29+
private const int NUMBER_ZERO = 0;
30+
31+
/// <summary>
32+
/// Constants for payment creation.
33+
/// </summary>
34+
private const string PAYMENT_AMOUNT_EUR = "0.01";
35+
private const string PAYMENT_CURRENCY = "EUR";
36+
private const string PAYMENT_DESCRIPTION = "C# test Payment";
37+
38+
/// <summary>
39+
/// API context to use for the test API calls.
40+
/// </summary>
41+
private static readonly ApiContext API_CONTEXT = GetApiContext();
42+
43+
[Fact]
44+
public void TestApiScenarioPaymentListingWithPagination()
45+
{
46+
EnsureEnoughPayments();
47+
var paymentsExpected = new List<Payment>(GetPaymentsRequired());
48+
var paginationCountOnly = new Pagination
49+
{
50+
Count = PAYMENT_LISTING_PAGE_SIZE
51+
};
52+
53+
var responseLatest = ListPayments(paginationCountOnly.UrlParamsCountOnly);
54+
var paginationLatest = responseLatest.Pagination;
55+
var responsePrevious = ListPayments(paginationLatest.UrlParamsPreviousPage);
56+
var paginationPrevious = responsePrevious.Pagination;
57+
var responsePreviousNext = ListPayments(paginationPrevious.UrlParamsNextPage);
58+
59+
var paymentsActual = new List<Payment>();
60+
paymentsActual.AddRange(responsePreviousNext.Value);
61+
paymentsActual.AddRange(responsePrevious.Value);
62+
var paymentsExpectedSerialized = BunqJsonConvert.SerializeObject(paymentsExpected);
63+
var paymentsActualSerialized = BunqJsonConvert.SerializeObject(paymentsActual);
64+
65+
Assert.Equal(paymentsExpectedSerialized, paymentsActualSerialized);
66+
}
67+
68+
private static void EnsureEnoughPayments()
69+
{
70+
for (var i = NUMBER_ZERO; i < GetPaymentsMissingCount(); ++i)
71+
{
72+
CreatePayment();
73+
}
74+
}
75+
76+
private static int GetPaymentsMissingCount()
77+
{
78+
return PAYMENT_REQUIRED_COUNT_MINIMUM - GetPaymentsRequired().Count;
79+
}
80+
81+
private static IList<Payment> GetPaymentsRequired()
82+
{
83+
var pagination = new Pagination
84+
{
85+
Count = PAYMENT_REQUIRED_COUNT_MINIMUM
86+
};
87+
88+
return ListPayments(pagination.UrlParamsCountOnly).Value;
89+
}
90+
91+
private static BunqResponse<List<Payment>> ListPayments(IDictionary<string, string> urlParams)
92+
{
93+
return Payment.List(API_CONTEXT, USER_ID, MONETARY_ACCOUNT_ID, urlParams);
94+
}
95+
96+
private static void CreatePayment()
97+
{
98+
var requestMap = new Dictionary<string, object>
99+
{
100+
{Payment.FIELD_AMOUNT, new Amount(PAYMENT_AMOUNT_EUR, PAYMENT_CURRENCY)},
101+
{Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION},
102+
{Payment.FIELD_COUNTERPARTY_ALIAS, COUNTER_PARTY_OTHER}
103+
};
104+
105+
Payment.Create(API_CONTEXT, requestMap, USER_ID, MONETARY_ACCOUNT_ID);
106+
}
107+
}
108+
}

0 commit comments

Comments
 (0)