Skip to content

Commit b76f3f4

Browse files
author
Kevin Hellemun
committed
Fixed failing tests.
1 parent 41dc090 commit b76f3f4

14 files changed

+71
-150
lines changed

BunqSdk.Tests/BunqSdkTestBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class BunqSdkTestBase
2929
/// <summary>
3030
/// Gets an Api Context, re-creates if needed and returns it.
3131
/// </summary>
32-
protected static ApiContext GetApiContext()
32+
protected static ApiContext SetUpApiContext()
3333
{
3434
ApiContext apiContext;
3535

@@ -44,6 +44,8 @@ protected static ApiContext GetApiContext()
4444

4545
apiContext.EnsureSessionActive();
4646
apiContext.Save(FILENAME_CONTEXT_CONF);
47+
48+
BunqContext.LoadApiContext(apiContext);
4749

4850
return apiContext;
4951
}

BunqSdk.Tests/Context/ApiContextTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ApiContextTest : BunqSdkTestBase, IClassFixture<ApiContextTest>
1818

1919
public ApiContextTest()
2020
{
21-
if (apiContext == null) apiContext = GetApiContext();
21+
if (apiContext == null) apiContext = SetUpApiContext();
2222
}
2323

2424
/// <summary>
@@ -27,7 +27,7 @@ public ApiContextTest()
2727
[Fact]
2828
public void TestApiContextSerializeDeserialize()
2929
{
30-
var apiContextJson = apiContext.ToJson();
30+
var apiContextJson = BunqContext.ApiContext.ToJson();
3131
var apiContextDeSerialised = ApiContext.FromJson(apiContextJson);
3232

3333
Assert.Equal(apiContextJson, apiContextDeSerialised.ToJson());

BunqSdk.Tests/Http/PaginationScenarioTest.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class PaginationScenarioTest : BunqSdkTestBase
3838
/// <summary>
3939
/// API context to use for the test API calls.
4040
/// </summary>
41-
private static readonly ApiContext API_CONTEXT = GetApiContext();
41+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
4242

4343
[Fact]
4444
public void TestApiScenarioPaymentListingWithPagination()
@@ -90,19 +90,12 @@ private static IList<Payment> GetPaymentsRequired()
9090

9191
private static BunqResponse<List<Payment>> ListPayments(IDictionary<string, string> urlParams)
9292
{
93-
return Payment.List(API_CONTEXT, USER_ID, MONETARY_ACCOUNT_ID, urlParams);
93+
return Payment.List(urlParams: urlParams);
9494
}
9595

9696
private static void CreatePayment()
9797
{
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);
98+
Payment.Create(new Amount(PAYMENT_AMOUNT_EUR, PAYMENT_CURRENCY), COUNTER_PARTY_OTHER, PAYMENT_DESCRIPTION);
10699
}
107100
}
108101
}

BunqSdk.Tests/Http/ResponseIdOnBadRequestTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ResponseIdOnBadRequestTest : BunqSdkTestBase
1111
/// <summary>
1212
/// API context to use for the test API calls.
1313
/// </summary>
14-
private static readonly ApiContext API_CONTEXT = GetApiContext();
14+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
1515

1616
/// <summary>
1717
/// Invalid user id to trigger BadRequestException
@@ -22,7 +22,7 @@ public class ResponseIdOnBadRequestTest : BunqSdkTestBase
2222
public void TestBadRequestWithResponseId()
2323
{
2424
var caughtException = Assert.Throws<BadRequestException>(
25-
() => UserPerson.Get(API_CONTEXT, INVALID_USER_PERSON_ID)
25+
() => UserPerson.Get()
2626
);
2727

2828
Assert.NotNull(caughtException.ResponseId);

BunqSdk.Tests/Model/Generated/Endpoint/AttachmentPublicTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AttachmentPublicTest : BunqSdkTestBase
2626
/// <summary>
2727
/// API context to use for the test API calls.
2828
/// </summary>
29-
private static readonly ApiContext API_CONTEXT = GetApiContext();
29+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
3030

3131
/// <summary>
3232
/// Tests if the file we upload is the file we are getting back once successfully uploaded does.
@@ -42,8 +42,8 @@ public void TestAttachmentUploadAndRetrieval()
4242
{ApiClient.HEADER_ATTACHMENT_DESCRIPTION, ATTACHMENT_DESCRIPTION}
4343
};
4444

45-
var attachmentUuid = AttachmentPublic.Create(API_CONTEXT, fileContentBytes, customHeaders).Value;
46-
var responseBytes = AttachmentPublicContent.List(API_CONTEXT, attachmentUuid).Value;
45+
var attachmentUuid = AttachmentPublic.Create(fileContentBytes, customHeaders).Value;
46+
var responseBytes = AttachmentPublicContent.List(attachmentUuid).Value;
4747

4848
Assert.Equal(fileContentBytes, responseBytes);
4949
}

BunqSdk.Tests/Model/Generated/Endpoint/AvatarTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class AvatarTest : BunqSdkTestBase
2828
/// <summary>
2929
/// API context to use for the test API calls.
3030
/// </summary>
31-
private static readonly ApiContext API_CONTEXT = GetApiContext();
31+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
3232

3333
/// <summary>
3434
/// Tests the creation of an avatar by uploading a picture via AttachmentPublic and setting it as avatar
@@ -44,11 +44,11 @@ public void TestCreateAvatarAndRetrieval()
4444
{
4545
{Avatar.FIELD_ATTACHMENT_PUBLIC_UUID, attachmentUuid}
4646
};
47-
var avatarUuid = Avatar.Create(API_CONTEXT, avatarMap).Value;
47+
var avatarUuid = Avatar.Create(attachmentUuid).Value;
4848

49-
var attachmentUuidFromAvatar = Avatar.Get(API_CONTEXT, avatarUuid).Value
49+
var attachmentUuidFromAvatar = Avatar.Get(avatarUuid).Value
5050
.Image[INDEX_FIRST].AttachmentPublicUuid;
51-
var revievedFileContentByte = AttachmentPublicContent.List(API_CONTEXT, attachmentUuidFromAvatar).Value;
51+
var revievedFileContentByte = AttachmentPublicContent.List(attachmentUuidFromAvatar).Value;
5252

5353
Assert.Equal(attachmentUuid, attachmentUuidFromAvatar);
5454
Assert.Equal(fileContentByte, revievedFileContentByte);
@@ -61,8 +61,8 @@ private static string UploadAvatarAndGetUuid(byte[] fileContentByte)
6161
{ApiClient.HEADER_ATTACHMENT_DESCRIPTION, ATTACHMENT_DECSRIPTION},
6262
{ApiClient.HEADER_CONTENT_TYPE, CONTEN_TYPE},
6363
};
64-
65-
return AttachmentPublic.Create(API_CONTEXT, fileContentByte, customHeaders).Value;
64+
65+
return AttachmentPublic.Create(fileContentByte, customHeaders).Value;
6666
}
6767
}
6868
}

BunqSdk.Tests/Model/Generated/Endpoint/CardDebitTest.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using Bunq.Sdk.Context;
45
using Bunq.Sdk.Model.Generated.Endpoint;
56
using Bunq.Sdk.Model.Generated.Object;
@@ -25,13 +26,14 @@ public class CardDebitTest : BunqSdkTestBase
2526
private const int BASE_DECIMAL = 10;
2627
private const int CARD_SECOND_LINE_LENGTH_MAXIMUM = 20;
2728
private const int NUMBER_ONE = 1;
29+
private const string CardTypeMaestro = "MAESTRO";
2830

2931
private static readonly int USER_ID = Config.GetUserId();
3032

3133
/// <summary>
3234
/// API context used to for the test API calls.
3335
/// </summary>
34-
private static readonly ApiContext API_CONTEXT = GetApiContext();
36+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
3537

3638
/// <summary>
3739
/// Tests ordering a new card and checks if the fields we have entered are indeed correct by.
@@ -40,20 +42,16 @@ public class CardDebitTest : BunqSdkTestBase
4042
public void TestOrderNewMaestroCard()
4143
{
4244
var cardPinAssignment = new CardPinAssignment(
43-
CARD_PIN_ASSIGNMENT_TYPE_PRIMARY,
45+
CARD_PIN_ASSIGNMENT_TYPE_PRIMARY,
4446
PIN_CODE,
4547
Config.GetMonetarytAccountId());
4648
var allCardPinAssignments = new List<CardPinAssignment> {cardPinAssignment};
47-
var cardDebitMap = new Dictionary<string, object>
48-
{
49-
{CardDebit.FIELD_ALIAS, GetAlias()},
50-
{CardDebit.FIELD_NAME_ON_CARD, GetAnAllowedName()},
51-
{CardDebit.FIELD_PIN_CODE_ASSIGNMENT, allCardPinAssignments},
52-
{CardDebit.FIELD_SECOND_LINE, GenerateRandomSecondLine()}
53-
};
54-
var cardDebit = CardDebit.Create(API_CONTEXT, cardDebitMap, USER_ID).Value;
49+
var cardDebit = CardDebit.Create(GenerateRandomSecondLine(), GetAnAllowedName(), GetAlias(), CardTypeMaestro,
50+
allCardPinAssignments).Value;
5551

56-
var cardFromCardEndpoint = Card.Get(API_CONTEXT, USER_ID, cardDebit.Id.Value).Value;
52+
Assert.True(cardDebit.Id != null);
53+
54+
var cardFromCardEndpoint = Card.Get(cardDebit.Id.Value).Value;
5755

5856
Assert.Equal(cardDebit.SecondLine, cardFromCardEndpoint.SecondLine);
5957
Assert.Equal(cardDebit.Created, cardFromCardEndpoint.Created);
@@ -62,7 +60,7 @@ public void TestOrderNewMaestroCard()
6260

6361
private static string GetAnAllowedName()
6462
{
65-
return CardName.List(API_CONTEXT, USER_ID).Value[INDEX_FIRST].PossibleCardNameArray[INDEX_FIRST];
63+
return CardName.List().Value[INDEX_FIRST].PossibleCardNameArray[INDEX_FIRST];
6664
}
6765

6866
private static string GenerateRandomSecondLine()
@@ -77,7 +75,7 @@ private static string GenerateRandomSecondLine()
7775

7876
private static Pointer GetAlias()
7977
{
80-
return User.Get(API_CONTEXT, USER_ID).Value.UserCompany.Alias[INDEX_FIRST];
78+
return User.Get().Value.UserCompany.Alias[INDEX_FIRST];
8179
}
8280
}
8381
}

BunqSdk.Tests/Model/Generated/Endpoint/DraftShareInviteBankQrCodeContentTest.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class DraftShareInviteBankQrCodeContentTest : BunqSdkTestBase
2828
/// <summary>
2929
/// API context to use for the test API calls
3030
/// </summary>
31-
private static readonly ApiContext API_CONTEXT = GetApiContext();
31+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
3232

3333
/// <summary>
3434
/// Tests the creation of a connect and getting the qr code related to this connect.
@@ -40,7 +40,7 @@ public void TestCreateInviteBankAndGetQrCode()
4040
{
4141
var draftId = GetShareInviteId();
4242

43-
var qrContent = DraftShareInviteBankQrCodeContent.List(API_CONTEXT, USER_ID, draftId).Value;
43+
var qrContent = DraftShareInviteBankQrCodeContent.List(draftId).Value;
4444

4545
var fileOut = new FileInfo(FILENAME_QR_CODE_IMAGE);
4646
fileOut.Directory.Create();
@@ -53,16 +53,10 @@ private static int GetShareInviteId()
5353
var addTime = new TimeSpan(TIME_UNIT_AMOUNT_ZERO, TIME_UNIT_AMOUNT_ONE, TIME_UNIT_AMOUNT_ZERO);
5454
var expirationTime = currentDate.Add(addTime).ToString(FORMAT_DATE);
5555

56-
var draftShareInviteBankEntry = new DraftShareInviteBankEntry(new ShareDetail
56+
var draftShareInviteEntry = new DraftShareInviteEntry(new ShareDetail
5757
{Payment = new ShareDetailPayment(true, true, true, true)});
5858

59-
var requestMap = new Dictionary<string, object>
60-
{
61-
{DraftShareInviteBank.FIELD_DRAFT_SHARE_SETTINGS, draftShareInviteBankEntry},
62-
{DraftShareInviteBank.FIELD_EXPIRATION, expirationTime}
63-
};
64-
65-
return DraftShareInviteBank.Create(API_CONTEXT, requestMap, USER_ID).Value;
59+
return DraftShareInviteBank.Create(expirationTime, draftShareInviteEntry).Value;
6660
}
6761
}
6862
}

BunqSdk.Tests/Model/Generated/Endpoint/MonetaryAccountBankTest.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public class MonetaryAccountBankTest : BunqSdkTestBase
1515
/// Config values
1616
/// </summary>
1717
private const string STATUS = "CANCELLED";
18+
1819
private const string SUBS_STATUS = "REDEMPTION_VOLUNTARY";
1920
private const string REASON = "OTHER";
2021
private const string REASON_DESCRIPTION = "Because this is a test";
@@ -26,34 +27,23 @@ public class MonetaryAccountBankTest : BunqSdkTestBase
2627
/// <summary>
2728
/// API context used for the test API calls.
2829
/// </summary>
29-
private static readonly ApiContext API_CONTEXT = GetApiContext();
30+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
3031

3132
/// <summary>
3233
/// Tests the creation of a new monetary account. This accoult will then be removed afterwards.
3334
/// </summary>
3435
[Fact]
3536
public void TestCreationNewMonetaryAccount()
3637
{
37-
var requestMap = new Dictionary<string, object>
38-
{
39-
{MonetaryAccountBank.FIELD_CURRENCY, CURRENCY},
40-
{MonetaryAccountBank.FIELD_DESCRIPTION, MONETARY_ACCOUNT_DESCRIPTION}
41-
};
42-
var monetaryAccountToCloseId = MonetaryAccountBank.Create(API_CONTEXT, requestMap, USER_ID).Value;
38+
var monetaryAccountToCloseId = MonetaryAccountBank.Create(CURRENCY, MONETARY_ACCOUNT_DESCRIPTION).Value;
4339

4440
DeleteMonetaryAccount(monetaryAccountToCloseId);
4541
}
4642

4743
private static void DeleteMonetaryAccount(int idToClose)
4844
{
49-
var requestMap = new Dictionary<string, object>
50-
{
51-
{MonetaryAccountBank.FIELD_STATUS, STATUS},
52-
{MonetaryAccountBank.FIELD_SUB_STATUS, SUBS_STATUS},
53-
{MonetaryAccountBank.FIELD_REASON, REASON},
54-
{MonetaryAccountBank.FIELD_REASON_DESCRIPTION, REASON_DESCRIPTION}
55-
};
56-
MonetaryAccountBank.Update(API_CONTEXT, requestMap, USER_ID, idToClose);
45+
MonetaryAccountBank.Update(idToClose, status: STATUS, subStatus: SUBS_STATUS, reason: REASON,
46+
reasonDescription: REASON_DESCRIPTION);
5747
}
5848
}
59-
}
49+
}

BunqSdk.Tests/Model/Generated/Endpoint/PaymentChatTest.cs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,22 @@ public class PaymentChatTest : BunqSdkTestBase
2929
/// <summary>
3030
/// API context used for the test API calls.
3131
/// </summary>
32-
private static readonly ApiContext API_CONTEXT = GetApiContext();
32+
private static readonly ApiContext API_CONTEXT = SetUpApiContext();
3333

3434
/// <summary>
3535
/// Tests sending a chat message in a newly created payment.
3636
/// </summary>
3737
[Fact]
3838
public void TestSendPaymentChat()
3939
{
40-
var paymentChatMap = new Dictionary<string, object>();
41-
var chatId = PaymentChat.Create(API_CONTEXT, paymentChatMap, USER_ID, MONETARTY_ACCOUNT_ID,
42-
CreatePaymentAndGetId()).Value;
40+
var chatId = PaymentChat.Create(CreatePaymentAndGetId()).Value;
4341

44-
var chatMessageMap = new Dictionary<string, object>
45-
{
46-
{ChatMessageText.FIELD_TEXT, MESSAGE_TEXT}
47-
};
48-
ChatMessageText.Create(API_CONTEXT, chatMessageMap, USER_ID, chatId);
42+
ChatMessageText.Create(chatId, MESSAGE_TEXT);
4943
}
5044

5145
private static int CreatePaymentAndGetId()
5246
{
53-
var requestMap = new Dictionary<string, object>
54-
{
55-
{Payment.FIELD_AMOUNT, new Amount(AMOUNT_EUR, CURRENCY)},
56-
{Payment.FIELD_COUNTERPARTY_ALIAS, COUNTER_PARTY_ALIAS},
57-
{Payment.FIELD_DESCRIPTION, PAYMENT_DESCRIPTION},
58-
};
59-
60-
return Payment.Create(API_CONTEXT, requestMap, USER_ID, MONETARTY_ACCOUNT_ID).Value;
47+
return Payment.Create(new Amount(AMOUNT_EUR, CURRENCY), COUNTER_PARTY_ALIAS, PAYMENT_DESCRIPTION).Value;
6148
}
6249
}
6350
}

0 commit comments

Comments
 (0)