Skip to content

Commit 7b74c5c

Browse files
committed
split tests into unit test and scenario test [#17]
1 parent 95746f3 commit 7b74c5c

File tree

2 files changed

+108
-95
lines changed

2 files changed

+108
-95
lines changed
Lines changed: 108 additions & 0 deletions
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.GetCounterAliasOther();
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 AMOUNT_IN_EUR = "0.01";
35+
private const string FIELD_CURRENCY = "EUR";
36+
private const string FIELD_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 HashSet<Payment>(GetPaymentsRequired());
48+
var paginationCountOnly = new Pagination
49+
{
50+
Count = PAYMENT_LISTING_PAGE_SIZE
51+
};
52+
53+
var paymentResponseLatest = ListPayments(paginationCountOnly.UrlParamsCountOnly);
54+
var paginationLatest = paymentResponseLatest.Pagination;
55+
var paymentResponsePrevious = ListPayments(paginationLatest.UrlParamsPreviousPage);
56+
var paginationPrevious = paymentResponsePrevious.Pagination;
57+
var paymentResponsePreviousNext = ListPayments(paginationPrevious.UrlParamsNextPage);
58+
59+
var paymentsActual = new HashSet<Payment>();
60+
paymentsActual.UnionWith(paymentResponsePreviousNext.Value);
61+
paymentsActual.UnionWith(paymentResponsePrevious.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 List<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(AMOUNT_IN_EUR, FIELD_CURRENCY)},
101+
{Payment.FIELD_DESCRIPTION, FIELD_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+
}

BunqSdk.Tests/Http/PaginationTest.cs

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using System.Collections.Generic;
2-
using Bunq.Sdk.Context;
32
using Bunq.Sdk.Exception;
43
using Bunq.Sdk.Http;
5-
using Bunq.Sdk.Json;
6-
using Bunq.Sdk.Model.Generated;
7-
using Bunq.Sdk.Model.Generated.Object;
84
using Xunit;
95

106
namespace Bunq.Sdk.Tests.Http
@@ -15,13 +11,6 @@ namespace Bunq.Sdk.Tests.Http
1511
/// </summary>
1612
public class PaginationTest : BunqSdkTestBase
1713
{
18-
/// <summary>
19-
/// Config values.
20-
/// </summary>
21-
private static readonly int USER_ID = Config.GetUserId();
22-
private static readonly int MONETARY_ACCOUNT_ID = Config.GetMonetarytAccountId();
23-
private static readonly Pointer COUNTER_PARTY_OTHER = Config.GetCounterAliasOther();
24-
2514
/// <summary>
2615
/// Values of pagination properties for testing.
2716
/// </summary>
@@ -30,25 +19,6 @@ public class PaginationTest : BunqSdkTestBase
3019
private const int PAGINATION_FUTURE_ID_CUSTOM = 3;
3120
private const int PAGINATION_COUNT_CUSTOM = 5;
3221

33-
/// <summary>
34-
/// Constants for scenario testing.
35-
/// </summary>
36-
private const int PAYMENT_LISTING_PAGE_SIZE = 2;
37-
private const int PAYMENT_REQUIRED_COUNT_MINIMUM = PAYMENT_LISTING_PAGE_SIZE * 2;
38-
private const int NUMBER_ZERO = 0;
39-
40-
/// <summary>
41-
/// Constants for payment creation.
42-
/// </summary>
43-
private const string AMOUNT_IN_EUR = "0.01";
44-
private const string FIELD_CURRENCY = "EUR";
45-
private const string FIELD_PAYMENT_DESCRIPTION = "C# test Payment";
46-
47-
/// <summary>
48-
/// API context to use for the test API calls.
49-
/// </summary>
50-
private static readonly ApiContext API_CONTEXT = GetApiContext();
51-
5222
[Fact]
5323
public void TestGetUrlParamsCountOnly()
5424
{
@@ -152,70 +122,5 @@ private static Pagination CreatePaginationWithNoNextPage()
152122

153123
return pagination;
154124
}
155-
156-
[Fact]
157-
public void TestApiScenarioPaymentListingWithPagination()
158-
{
159-
EnsureEnoughPayments();
160-
var paymentsExpected = new HashSet<Payment>(GetPaymentsRequired());
161-
var paginationCountOnly = new Pagination
162-
{
163-
Count = PAYMENT_LISTING_PAGE_SIZE
164-
};
165-
166-
var paymentResponseLatest = ListPayments(paginationCountOnly.UrlParamsCountOnly);
167-
var paginationLatest = paymentResponseLatest.Pagination;
168-
var paymentResponsePrevious = ListPayments(paginationLatest.UrlParamsPreviousPage);
169-
var paginationPrevious = paymentResponsePrevious.Pagination;
170-
var paymentResponsePreviousNext = ListPayments(paginationPrevious.UrlParamsNextPage);
171-
172-
var paymentsActual = new HashSet<Payment>();
173-
paymentsActual.UnionWith(paymentResponsePreviousNext.Value);
174-
paymentsActual.UnionWith(paymentResponsePrevious.Value);
175-
var paymentsExpectedSerialized = BunqJsonConvert.SerializeObject(paymentsExpected);
176-
var paymentsActualSerialized = BunqJsonConvert.SerializeObject(paymentsActual);
177-
178-
Assert.Equal(paymentsExpectedSerialized, paymentsActualSerialized);
179-
}
180-
181-
private static void EnsureEnoughPayments()
182-
{
183-
for (var i = NUMBER_ZERO; i < GetPaymentsMissingCount(); ++i)
184-
{
185-
CreatePayment();
186-
}
187-
}
188-
189-
private static int GetPaymentsMissingCount()
190-
{
191-
return PAYMENT_REQUIRED_COUNT_MINIMUM - GetPaymentsRequired().Count;
192-
}
193-
194-
private static List<Payment> GetPaymentsRequired()
195-
{
196-
var pagination = new Pagination
197-
{
198-
Count = PAYMENT_REQUIRED_COUNT_MINIMUM
199-
};
200-
201-
return ListPayments(pagination.UrlParamsCountOnly).Value;
202-
}
203-
204-
private static BunqResponse<List<Payment>> ListPayments(IDictionary<string, string> urlParams)
205-
{
206-
return Payment.List(API_CONTEXT, USER_ID, MONETARY_ACCOUNT_ID, urlParams);
207-
}
208-
209-
private static void CreatePayment()
210-
{
211-
var requestMap = new Dictionary<string, object>
212-
{
213-
{Payment.FIELD_AMOUNT, new Amount(AMOUNT_IN_EUR, FIELD_CURRENCY)},
214-
{Payment.FIELD_DESCRIPTION, FIELD_PAYMENT_DESCRIPTION},
215-
{Payment.FIELD_COUNTERPARTY_ALIAS, COUNTER_PARTY_OTHER}
216-
};
217-
218-
Payment.Create(API_CONTEXT, requestMap, USER_ID, MONETARY_ACCOUNT_ID);
219-
}
220125
}
221126
}

0 commit comments

Comments
 (0)