diff --git a/NordigenClientModified.zip b/NordigenClientModified.zip deleted file mode 100644 index 5226bfc..0000000 Binary files a/NordigenClientModified.zip and /dev/null differ diff --git a/src/RobinTTY.NordigenApiClient.Tests/Serialization/TransactionTests.cs b/src/RobinTTY.NordigenApiClient.Tests/Serialization/TransactionTests.cs index 291e11f..431eba6 100644 --- a/src/RobinTTY.NordigenApiClient.Tests/Serialization/TransactionTests.cs +++ b/src/RobinTTY.NordigenApiClient.Tests/Serialization/TransactionTests.cs @@ -10,20 +10,48 @@ namespace RobinTTY.NordigenApiClient.Tests.Serialization; internal class TransactionTests { /// - /// Tests the correct deserialization of transactions. + /// Tests the correct deserialization of transactions with a single embedded currency exchange object. /// [Test] - public void DeserializeTransaction() + public void DeserializeTransactionWithSingleCurrencyExchange() + { + const string json = + "{ \"transactionId\": \"AB123456789\", \"entryReference\": \"123456789\", \"bookingDate\": \"2023-03-20\", \"bookingDateTime\": \"2023-03-20T00:00:00+00:00\", \"transactionAmount\": { \"amount\": \"-33.06\", \"currency\": \"GBP\" }, \"currencyExchange\": { \"sourceCurrency\": \"USD\", \"exchangeRate\": \"1.20961887\", \"unitCurrency\": \"USD\", \"targetCurrency\": \"GBP\", \"instructedAmount\": { \"amount\": \"-33.06\", \"currency\": \"GBP\" } }, \"remittanceInformationUnstructured\": \"my reference here\", \"additionalInformation\": \"123456789\", \"proprietaryBankTransactionCode\": \"OTHER_PURCHASE\", \"merchantCategoryCode\": \"5045\", \"internalTransactionId\": \"abcdef\" }"; + + var options = new JsonSerializerOptions + { + Converters = {new CultureSpecificDecimalConverter()} + }; + var transaction = JsonSerializer.Deserialize(json, options); + + Assert.Multiple(() => + { + Assert.That(transaction!.CurrencyExchange, Is.Not.Null); + Assert.That(transaction.CurrencyExchange!.First().ExchangeRate, Is.EqualTo(1.20961887)); + Assert.That(transaction.CurrencyExchange!.First().InstructedAmount!.Amount, Is.EqualTo(-33.06)); + Assert.That(transaction.CurrencyExchange!.First().InstructedAmount!.Currency, Is.EqualTo("GBP")); + Assert.That(transaction.CurrencyExchange!.First().SourceCurrency, Is.EqualTo("USD")); + Assert.That(transaction.CurrencyExchange!.First().TargetCurrency, Is.EqualTo("GBP")); + Assert.That(transaction.CurrencyExchange!.First().UnitCurrency, Is.EqualTo("USD")); + Assert.That(transaction.CurrencyExchange!.First().QuotationDate, Is.Null); + }); + } + + /// + /// Tests the correct deserialization of transactions with multiple embedded currency exchange objects. + /// + [Test] + public void DeserializeTransactionWithMultipleCurrencyExchange() { const string json = "{ \"transactionId\": \"AB123456789\", \"entryReference\": \"123456789\", \"bookingDate\": \"2023-03-20\", \"bookingDateTime\": \"2023-03-20T00:00:00+00:00\", \"transactionAmount\": { \"amount\": \"-33.06\", \"currency\": \"GBP\" }, \"currencyExchange\":[{\"sourceCurrency\":\"USD\",\"exchangeRate\":\"1.20961887\",\"unitCurrency\":\"USD\",\"targetCurrency\":\"GBP\"}], \"remittanceInformationUnstructured\": \"my reference here\", \"additionalInformation\": \"123456789\", \"proprietaryBankTransactionCode\": \"OTHER_PURCHASE\", \"merchantCategoryCode\": \"5045\", \"internalTransactionId\": \"abcdef\" }"; - // We need the culture specific decimal converter here, since it it accepting strings var options = new JsonSerializerOptions { - Converters = {new JsonWebTokenConverter(), new GuidConverter(), new CultureSpecificDecimalConverter()} + Converters = { new CultureSpecificDecimalConverter() } }; var transaction = JsonSerializer.Deserialize(json, options); + Assert.Multiple(() => { Assert.That(transaction!.CurrencyExchange, Is.Not.Null); diff --git a/src/RobinTTY.NordigenApiClient/JsonConverters/SingleOrArrayConverter.cs b/src/RobinTTY.NordigenApiClient/JsonConverters/SingleOrArrayConverter.cs index 1eadbd3..7feca25 100644 --- a/src/RobinTTY.NordigenApiClient/JsonConverters/SingleOrArrayConverter.cs +++ b/src/RobinTTY.NordigenApiClient/JsonConverters/SingleOrArrayConverter.cs @@ -3,7 +3,8 @@ namespace RobinTTY.NordigenApiClient.JsonConverters; -internal class SingleOrArrayConverter : JsonConverter where TCollection : class, ICollection, new() +internal class SingleOrArrayConverter : JsonConverter + where TCollection : class, ICollection, new() { public override TCollection? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { @@ -15,27 +16,21 @@ namespace RobinTTY.NordigenApiClient.JsonConverters; var list = new TCollection(); while (reader.Read()) { - if (reader.TokenType == JsonTokenType.EndArray) - break; + if (reader.TokenType == JsonTokenType.EndArray) break; var listItem = JsonSerializer.Deserialize(ref reader, options); - if (listItem != null) - { - list.Add(listItem); - } + if (listItem != null) list.Add(listItem); } return list; default: var item = JsonSerializer.Deserialize(ref reader, options); - return item != null ? new TCollection { item } : null; + return item != null ? new TCollection {item} : null; } } public override void Write(Utf8JsonWriter writer, TCollection value, JsonSerializerOptions options) { if (value.Count == 1) - { JsonSerializer.Serialize(writer, value.First(), options); - } else { writer.WriteStartArray(); @@ -44,4 +39,4 @@ public override void Write(Utf8JsonWriter writer, TCollection value, JsonSeriali writer.WriteEndArray(); } } -} +} \ No newline at end of file diff --git a/src/RobinTTY.NordigenApiClient/Models/Responses/AmountCurrencyPair.cs b/src/RobinTTY.NordigenApiClient/Models/Responses/AmountCurrencyPair.cs index 7714943..5458c5e 100644 --- a/src/RobinTTY.NordigenApiClient/Models/Responses/AmountCurrencyPair.cs +++ b/src/RobinTTY.NordigenApiClient/Models/Responses/AmountCurrencyPair.cs @@ -5,7 +5,6 @@ namespace RobinTTY.NordigenApiClient.Models.Responses; /// /// Pair representing an amount and the currency the amount is denominated in. /// -[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public class AmountCurrencyPair { /// @@ -31,4 +30,4 @@ public AmountCurrencyPair(decimal amount, string currency) Amount = amount; Currency = currency; } -} +} \ No newline at end of file diff --git a/src/RobinTTY.NordigenApiClient/Models/Responses/CurrencyExchange.cs b/src/RobinTTY.NordigenApiClient/Models/Responses/CurrencyExchange.cs index 850cdfd..a3aae10 100644 --- a/src/RobinTTY.NordigenApiClient/Models/Responses/CurrencyExchange.cs +++ b/src/RobinTTY.NordigenApiClient/Models/Responses/CurrencyExchange.cs @@ -5,7 +5,6 @@ namespace RobinTTY.NordigenApiClient.Models.Responses; /// /// Detailed information about a currency exchange. /// -[JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public class CurrencyExchange { ///