Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests updates and fixes #240

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -65,9 +66,9 @@
var wallet = await this.GetJohnsWallet();
var user = await this.GetJohn();

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test");

Check warning on line 69 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

var payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 71 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsTrue(payIn.Id.Length > 0);
Assert.IsTrue(payIn.PaymentType == PayInPaymentType.PAYPAL);
Expand Down Expand Up @@ -197,12 +198,12 @@
PostalCode = "11222",
Region = "Region"
};
var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test")

Check warning on line 201 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'
{
ShippingAddress = new ShippingAddress("recipient name", AddressForShippingAddress)
};

var payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 206 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsNotNull(payIn.ShippingAddress);
Assert.AreEqual("recipient name", payIn.ShippingAddress.RecipientName);
Expand Down Expand Up @@ -979,15 +980,15 @@
var wallet = await this.GetJohnsWallet();
var user = await this.GetJohn();

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test");

Check warning on line 983 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'

payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 985 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

Assert.IsTrue(payIn.Id.Length > 0);
Assert.IsTrue(payIn.PaymentType == PayInPaymentType.PAYPAL);
Assert.IsTrue(payIn.ExecutionType == PayInExecutionType.WEB);

var getPayIn = await this.Api.PayIns.GetPayPalAsync(payIn.Id);

Check warning on line 991 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Assert.IsNotNull(getPayIn);
Assert.IsTrue(getPayIn.Id == payIn.Id);
Expand Down Expand Up @@ -1016,14 +1017,14 @@
Region = "Region"
};

var payInPost = new PayInPayPalPostDTO(user.Id, new Money { Amount = 1000, Currency = CurrencyIso.EUR }, new Money { Amount = 0, Currency = CurrencyIso.EUR }, wallet.Id, "http://test/test")

Check warning on line 1020 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'PayInPayPalPostDTO' is obsolete: 'PayInPayPalPostDTO is deprecated, please use PayInPayPalWebPostDTO instead.'
{
ShippingAddress = new ShippingAddress("recipient name", addressForShippingAddress)
};

payIn = await this.Api.PayIns.CreatePayPalAsync(payInPost);

Check warning on line 1025 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.CreatePayPalAsync(PayInPayPalPostDTO, string)' is obsolete: 'CreatePayPalAsync is deprecated, please use CreatePayPalWebAsync instead.'

var getPayIn = await this.Api.PayIns.GetPayPalAsync(payIn.Id);

Check warning on line 1027 in MangoPay.SDK.Tests/ApiPayInsTest.cs

View workflow job for this annotation

GitHub Actions / dotnet 6.0.x

'ApiPayIns.GetPayPalAsync(string)' is obsolete: 'GetPayPalAsync is deprecated, please use GetPayPalWebAsync instead.'

Assert.IsNotNull(getPayIn.ShippingAddress);
Assert.AreEqual("recipient name", getPayIn.ShippingAddress.RecipientName);
Expand All @@ -1042,6 +1043,7 @@
}

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

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

Expand All @@ -1129,6 +1131,7 @@
}

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

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

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

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