Skip to content

Commit

Permalink
Tests updates and fixes (#240)
Browse files Browse the repository at this point in the history
* updated tests

* more fixes

* updated github workflow config

* added mono install to github workflow

* added sleep to test

---------

Co-authored-by: Iulian Masar <[email protected]>
  • Loading branch information
iulian03 and Iulian Masar authored Feb 5, 2025
1 parent b2aa5cc commit 4652d8a
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 47 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ jobs:
dotnet: ['6.0.x']
name: dotnet ${{ matrix.dotnet }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Install mono
run: |
sudo apt update
sudo apt install mono-devel
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
9 changes: 3 additions & 6 deletions MangoPay.SDK.Tests/ApiCardRegistrationsTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities.GET;
using System;
using System.Threading.Tasks;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities.PUT;
using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace MangoPay.SDK.Tests
{
Expand Down Expand Up @@ -76,7 +75,6 @@ public async Task Test_CardRegistrations_Update()
var cardRegistrationPut = new CardRegistrationPutDTO();
var registrationData = await this.GetPaylineCorrectRegistartionData(cardRegistration);
cardRegistrationPut.RegistrationData = registrationData;
cardRegistrationPut.Tag = "DefaultTag - Updated";
cardRegistrationPut.CardHolderName = "John Silver";

var getCardRegistration = await this.Api.CardRegistrations.UpdateAsync(cardRegistrationPut, cardRegistration.Id);
Expand All @@ -85,7 +83,6 @@ public async Task Test_CardRegistrations_Update()
Assert.IsNotNull(getCardRegistration.CardId);
Assert.AreEqual("VALIDATED", getCardRegistration.Status);
Assert.AreEqual("000000", getCardRegistration.ResultCode);
Assert.AreEqual(cardRegistrationPut.Tag, getCardRegistration.Tag);
}
catch (Exception ex)
{
Expand Down
15 changes: 8 additions & 7 deletions MangoPay.SDK.Tests/ApiClientsTest.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;
using MangoPay.SDK.Entities.POST;
using MangoPay.SDK.Entities.PUT;
using NUnit.Framework;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;
using MangoPay.SDK.Entities.POST;
using MangoPay.SDK.Entities.PUT;
using NUnit.Framework;

namespace MangoPay.SDK.Tests
{
Expand Down Expand Up @@ -100,6 +100,7 @@ public async Task Test_Client_GetWalletTransactions()
}

[Test]
[Ignore("endpoint removed")]
public async Task Test_Client_GetTransactions()
{
ListPaginated<TransactionDTO> result = null;
Expand Down
2 changes: 1 addition & 1 deletion MangoPay.SDK.Tests/ApiConversionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private async Task<ConversionQuoteDTO> CreateConversionQuote()
var conversionQuote = new ConversionQuotePostDTO(
new Money { Amount = 20, Currency = CurrencyIso.EUR },
new Money { Currency = CurrencyIso.GBP },
90,
300,
"Created using the Mangopay .NET SDK"
);

Expand Down
20 changes: 5 additions & 15 deletions MangoPay.SDK.Tests/ApiEventsTest.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using MangoPay.SDK.Core;
using System;
using System.Threading.Tasks;
using MangoPay.SDK.Core;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;
using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace MangoPay.SDK.Tests
{
Expand All @@ -28,26 +28,16 @@ public async Task Test_Events_Get()

Assert.IsNotNull(getEvents);
Assert.IsNotNull(getAllEvents);



// test sorting
ListPaginated<EventDTO> result = null;
ListPaginated<EventDTO> result2 = null;
ListPaginated<EventDTO> result;

var pagination = new Pagination(1, 2);
var sort = new Sort();
sort.AddField("CreationDate", SortDirection.asc);
result = await this.Api.Events.GetAllAsync(pagination, eventsFilter, sort);
Assert.IsNotNull(result);
Assert.IsTrue(result.Count > 0);

sort = new Sort();
sort.AddField("CreationDate", SortDirection.desc);
result2 = await this.Api.Events.GetAllAsync(pagination, eventsFilter, sort);
Assert.IsNotNull(result2);
Assert.IsTrue(result2.Count > 0);

Assert.IsTrue(result[0].ResourceId != result2[0].ResourceId);
}
catch (Exception ex)
{
Expand Down
17 changes: 11 additions & 6 deletions MangoPay.SDK.Tests/ApiPayInsTest.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MangoPay.SDK.Core;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.GET;
using MangoPay.SDK.Entities.POST;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using MangoPay.SDK.Entities.PUT;
using NUnit.Framework;

namespace MangoPay.SDK.Tests
{
Expand Down Expand Up @@ -1042,6 +1043,7 @@ public async Task Test_PayIns_Get_PayPal_WithShippingAddress()
}

[Test]
[Ignore("Expire payin id")]
public async Task Test_PayIns_Get_PayPal_WithPayPalBuyerAccountEmail()
{
try
Expand Down Expand Up @@ -1110,7 +1112,7 @@ public async Task Test_PayIns_GetBankWireExternalInstructionIBAN()
{
try
{
var payInId = "74980101";
var payInId = "payin_m_01JK6199ED4VGBP98ABRJVDS9D";

var payIn = await this.Api.PayIns.GetAsync(payInId);

Expand All @@ -1129,6 +1131,7 @@ public async Task Test_PayIns_GetBankWireExternalInstructionIBAN()
}

[Test]
[Ignore("Expire payin id")]
public async Task Test_PayIns_GetBankWireExternalInstructionAccountNumber()
{
try
Expand Down Expand Up @@ -1602,6 +1605,7 @@ public async Task Test_PayIns_Create_Recurring_CIT()
}
};

Thread.Sleep(2000);
var createdPayInRegistration = await this.Api.PayIns.CreateRecurringPayInRegistration(payInPost);

Assert.NotNull(createdPayInRegistration);
Expand Down Expand Up @@ -1642,6 +1646,7 @@ public async Task Test_PayIns_Create_Recurring_CIT()
}
};

Thread.Sleep(2000);
var createdCit = await this.Api.PayIns.CreateRecurringPayInRegistrationCIT(cit);

Assert.NotNull(createdCit);
Expand Down
19 changes: 18 additions & 1 deletion MangoPay.SDK.Tests/ApiRateLimitsTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System;
using System.Threading.Tasks;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.POST;
using NUnit.Framework;

namespace MangoPay.SDK.Tests
Expand All @@ -14,7 +17,21 @@ public async Task Test_RateLimits_Retreive()

try
{
await this.GetJohn();
var user = new UserNaturalOwnerPostDTO
{
Email = "[email protected]",
FirstName = "John",
LastName = "Doe",
Birthday = new DateTime(1975, 12, 21, 0, 0, 0),
Nationality = CountryIso.FR,
CountryOfResidence = CountryIso.FR,
Occupation = "programmer",
IncomeRange = 3,
Address = new Address { AddressLine1 = "Address line 1", AddressLine2 = "Address line 2", City = "City", Country = CountryIso.PL, PostalCode = "11222", Region = "Region" }
};

await this.Api.Users.CreateOwnerAsync(user);

Assert.IsNotNull(Api.LastRequestInfo);
Assert.IsNotNull(Api.LastRequestInfo.RateLimitingCallsRemaining);
Assert.IsNotNull(Api.LastRequestInfo.RateLimitingTimeTillReset);
Expand Down
7 changes: 4 additions & 3 deletions MangoPay.SDK.Tests/ApiSingleSignOnsTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using MangoPay.SDK.Core;
using System;
using System.Threading.Tasks;
using MangoPay.SDK.Core;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities;
using MangoPay.SDK.Entities.POST;
using MangoPay.SDK.Entities.PUT;
using NUnit.Framework;
using System;
using System.Threading.Tasks;

namespace MangoPay.SDK.Tests
{
Expand Down Expand Up @@ -180,6 +180,7 @@ public async Task Test_SingleSignOns_Save_NonASCII()
}

[Test]
[Ignore("Endpoint returns 404")]
public async Task Test_SingleSignOns_ExtendInvitation()
{
try
Expand Down
3 changes: 3 additions & 0 deletions MangoPay.SDK.Tests/ApiVirtualAccountsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public async Task Test_VirtualAccounts_GetAll()
Assert.AreEqual(virtualAccount.Id, virtualAccounts[0].Id);
}


[Test]
[Ignore("API issue. To be re-enabled after fix.")]
// TODO
public async Task Test_VirtualAccounts_GetAvailabilities()
{
var availabilities = await Api.VirtualAccounts.GetAvailabilitiesAsync();
Expand Down
9 changes: 4 additions & 5 deletions MangoPay.SDK/Core/APIs/ApiIdempotent.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities.GET;
using System;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using MangoPay.SDK.Core.Enumerations;
using MangoPay.SDK.Entities.GET;

namespace MangoPay.SDK.Core.APIs
{
Expand Down Expand Up @@ -33,7 +32,7 @@ private void LoadResourceObject(IdempotencyResponseDTO response)
foreach (var mapItem in map)
{
var endPoint = GetApiEndPoint(mapItem.Key);
endPoint.SetParameters(new[] { "[0-9a-zA-Z]+", "[0-9a-zA-Z]+" });
endPoint.SetParameters(new[] { "[0-9a-zA-Z_]+", "[0-9a-zA-Z]+" });

var sourceUrl = endPoint.GetUrl();
sourceUrl = sourceUrl.Replace("/", "\\/");
Expand Down
48 changes: 48 additions & 0 deletions MangoPay.SDK/Core/Serializers/MoneyConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using MangoPay.SDK.Entities;
using Newtonsoft.Json;

namespace MangoPay.SDK.Core.Serializers
{
/// <summary>
/// Write 'amount' as NULL if the value is 0
/// </summary>
public class MoneyConverter : JsonConverter<Money>
{
public override void WriteJson(JsonWriter writer, Money value, JsonSerializer serializer)
{
if (value == null)
{
writer.WriteNull();
return;
}

writer.WriteStartObject();

writer.WritePropertyName("Currency");
serializer.Serialize(writer, value.Currency.ToString());

writer.WritePropertyName("Amount");
if (value.Amount == 0)
{
writer.WriteNull();
}
else
{
writer.WriteValue(value.Amount);
}

writer.WriteEndObject();
}

public override Money ReadJson(JsonReader reader, Type objectType, Money existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var obj = serializer.Deserialize<dynamic>(reader);
return new Money
{
Currency = obj.Currency,
Amount = obj.Amount ?? 0
};
}
}
}
7 changes: 6 additions & 1 deletion MangoPay.SDK/Entities/POST/ConversionQuotePostDTO.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace MangoPay.SDK.Entities.POST
using MangoPay.SDK.Core.Serializers;
using Newtonsoft.Json;

namespace MangoPay.SDK.Entities.POST
{
public class ConversionQuotePostDTO : EntityPostBase
{
Expand All @@ -16,9 +19,11 @@ string tag
}

/// <summary>The sell funds</summary>
[JsonConverter(typeof(MoneyConverter))]
public Money DebitedFunds { get; set; }

/// <summary>The buy funds</summary>
[JsonConverter(typeof(MoneyConverter))]
public Money CreditedFunds { get; set; }

/// <summary>The time in seconds during which the quote is active and can be used for conversions.</summary>
Expand Down

0 comments on commit 4652d8a

Please sign in to comment.