Skip to content

Commit

Permalink
Added compatability with .NET Standard 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTTY committed Jan 18, 2023
1 parent 0145ef3 commit ca4bc9f
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ public async Task GetTransactions()
[Test]
public async Task GetTransactionRange()
{
#if NET6_0_OR_GREATER
var startDate = new DateOnly(2022, 08, 04);
var balancesResponse = await _apiClient.AccountsEndpoint.GetTransactions(_accountId, startDate, DateOnly.FromDateTime(DateTime.Now.Subtract(TimeSpan.FromMinutes(1))));
#else
var startDate = new DateTime(2022, 08, 04);
var balancesResponse = await _apiClient.AccountsEndpoint.GetTransactions(_accountId, startDate, DateTime.Now.Subtract(TimeSpan.FromMinutes(1)));
#endif

TestExtensions.AssertNordigenApiResponseIsSuccessful(balancesResponse, HttpStatusCode.OK);
Assert.That(balancesResponse.Result!.BookedTransactions, Has.Count.AtLeast(10));
}
Expand All @@ -117,7 +123,11 @@ public async Task GetTransactionRange()
public async Task GetTransactionRangeInFuture()
{
var dateInFuture = DateTime.Now.AddDays(1);
#if NET6_0_OR_GREATER
var balancesResponse = await _apiClient.AccountsEndpoint.GetTransactions(_accountId, DateOnly.FromDateTime(dateInFuture), DateOnly.FromDateTime(dateInFuture.AddDays(1)));
#else
var balancesResponse = await _apiClient.AccountsEndpoint.GetTransactions(_accountId, dateInFuture, dateInFuture.AddDays(1));
#endif
TestExtensions.AssertNordigenApiResponseIsUnsuccessful(balancesResponse, HttpStatusCode.BadRequest);
Assert.Multiple(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public async Task GetTokenWithInvalidCredentials()
[Test]
public async Task ReuseExpiredToken()
{
#if NET6_0_OR_GREATER
var secrets = await File.ReadAllLinesAsync("secrets.txt");
#else
var secrets = File.ReadAllLines("secrets.txt");
#endif
var httpClient = new HttpClient();
var credentials = new NordigenClientCredentials(secrets[0], secrets[1]);
var tokenPair = new JsonWebTokenPair(secrets[6], secrets[7]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void CreateValidJsonWebTokenPair()
public void CreateInvalidJsonWebTokenPair()
{
var exampleToken = "eyJhbGciOiJIUzI1NisInR5cCI6IkpXVCJ9.eyJ0eXBlIjoiYWNjZXNzIiwic3ViIjoiMTIzNDU2Nzg5MCIsIm5iZiI6MTY1OTE5OTU5MiwiZXhwIjoxNjU5MjE5NTkyLCJuYWIjoiSm9obiBEb2UiLCJpYXQiOjE1MTYyMzkwMjJ9.WP7xByegwjRvWZMwHScxunAOkwkW77ocaLvGen2PAU";
// ReSharper disable once ObjectCreationAsStatement
Assert.Throws<ArgumentException>(() => new JsonWebTokenPair(exampleToken, exampleToken));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<TargetFrameworks>net6.0;net7.0;net48</TargetFrameworks>
<LangVersion>11.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.5.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RobinTTY.NordigenApiClient\RobinTTY.NordigenApiClient.csproj" />
</ItemGroup>

Expand Down
18 changes: 18 additions & 0 deletions src/RobinTTY.NordigenApiClient/Endpoints/AccountsEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,13 @@ private async Task<NordigenApiResponse<BankAccountDetails, AccountsError>> GetAc
/// <param name="endDate">Optional date to limit the transactions which are returned to those before the specified date.</param>
/// <param name="cancellationToken">Optional token to signal cancellation of the operation.</param>
/// <returns>A <see cref="NordigenApiResponse{TResponse, TError}"/> which contains transaction data of the specified account.</returns>
#if NET6_0_OR_GREATER
public async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetTransactions(Guid id, DateOnly? startDate = null, DateOnly? endDate = null, CancellationToken cancellationToken = default)
=> await GetTransactionsInternal(id.ToString(), startDate, endDate, cancellationToken);
#else
public async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetTransactions(Guid id, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default)
=> await GetTransactionsInternal(id.ToString(), startDate, endDate, cancellationToken);
#endif

/// <summary>
/// Gets the transactions of the specified bank account.
Expand All @@ -118,10 +123,19 @@ public async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetTr
/// <param name="endDate">Optional date to limit the transactions which are returned to those before the specified date.</param>
/// <param name="cancellationToken">Optional token to signal cancellation of the operation.</param>
/// <returns>A <see cref="NordigenApiResponse{TResponse, TError}"/> which contains transaction data of the specified account.</returns>
#if NET6_0_OR_GREATER
public async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetTransactions(string id, DateOnly? startDate = null, DateOnly? endDate = null, CancellationToken cancellationToken = default)
=> await GetTransactionsInternal(id, startDate, endDate, cancellationToken);
#else
public async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetTransactions(string id, DateTime? startDate = null, DateTime? endDate = null, CancellationToken cancellationToken = default)
=> await GetTransactionsInternal(id, startDate, endDate, cancellationToken);
#endif

#if NET6_0_OR_GREATER
private async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetTransactionsInternal(string id, DateOnly? startDate, DateOnly? endDate, CancellationToken cancellationToken)
#else
private async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetTransactionsInternal(string id, DateTime? startDate, DateTime? endDate, CancellationToken cancellationToken)
#endif
{
var query = new List<KeyValuePair<string, string>>();
if (startDate != null)
Expand All @@ -133,5 +147,9 @@ private async Task<NordigenApiResponse<AccountTransactions, AccountsError>> GetT
return new NordigenApiResponse<AccountTransactions, AccountsError>(response.StatusCode, response.IsSuccess, response.Result?.Transactions, response.Error);
}

#if NET6_0_OR_GREATER
private string DateToIso8601(DateOnly date) => date.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
#else
private string DateToIso8601(DateTime date) => date.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture);
#endif
}
28 changes: 27 additions & 1 deletion src/RobinTTY.NordigenApiClient/Models/Errors/AccountsError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,34 @@ public class AccountsError : BasicError
/// </summary>
[JsonPropertyName("type")]
public string Type { get; }
#if NET6_0_OR_GREATER
/// <summary>
/// An error that was returned related to the <see cref="AccountsEndpoint.GetTransactions(Guid, DateOnly?, DateOnly?, CancellationToken)"/> or
/// <see cref="AccountsEndpoint.GetTransactions(string, DateOnly?, DateOnly?, CancellationToken)"/> method because the start date value was not accepted.
/// </summary>
#else
/// <summary>
/// An error that was returned related to the <see cref="AccountsEndpoint.GetTransactions(Guid, DateTime?, DateTime?, CancellationToken)"/> or
/// <see cref="AccountsEndpoint.GetTransactions(string, DateTime?, DateTime?, CancellationToken)"/> method because the start date value was not accepted.
/// </summary>
#endif
[JsonPropertyName("date_from")]
public BasicError StartDateError { get; }
#if NET6_0_OR_GREATER
/// <summary>
/// An error that was returned related to the <see cref="AccountsEndpoint.GetTransactions(Guid, DateOnly?, DateOnly?, CancellationToken)"/> or
/// <see cref="AccountsEndpoint.GetTransactions(string, DateOnly?, DateOnly?, CancellationToken)"/> method because the end date value was not accepted.
/// </summary>
#else
/// <summary>
/// An error that was returned related to the <see cref="AccountsEndpoint.GetTransactions(Guid, DateTime?, DateTime?, CancellationToken)"/> or
/// <see cref="AccountsEndpoint.GetTransactions(string, DateTime?, DateTime?, CancellationToken)"/> method because the end date value was not accepted.
/// </summary>
#endif
[JsonPropertyName("date_to")]
public BasicError EndDateError { get; }


#if NET6_0_OR_GREATER
/// <summary>
/// Creates a new instance of <see cref="AccountsError"/>.
/// </summary>
Expand All @@ -37,6 +51,18 @@ public class AccountsError : BasicError
/// <see cref="AccountsEndpoint.GetTransactions(string, DateOnly?, DateOnly?, CancellationToken)"/> method because the start date value was not accepted.</param>
/// <param name="endDateError">An error that was returned related to the <see cref="AccountsEndpoint.GetTransactions(Guid, DateOnly?, DateOnly?, CancellationToken)"/> or
/// <see cref="AccountsEndpoint.GetTransactions(string, DateOnly?, DateOnly?, CancellationToken)"/> method because the end date value was not accepted.</param>
#else
/// <summary>
/// Creates a new instance of <see cref="AccountsError"/>.
/// </summary>
/// <param name="summary">The summary of the API error.</param>
/// <param name="detail">The detailed description of the API error.</param>
/// <param name="type">The type of the error.</param>
/// <param name="startDateError">An error that was returned related to the <see cref="AccountsEndpoint.GetTransactions(Guid, DateTime?, DateTime?, CancellationToken)"/> or
/// <see cref="AccountsEndpoint.GetTransactions(string, DateTime?, DateTime?, CancellationToken)"/> method because the start date value was not accepted.</param>
/// <param name="endDateError">An error that was returned related to the <see cref="AccountsEndpoint.GetTransactions(Guid, DateTime?, DateTime?, CancellationToken)"/> or
/// <see cref="AccountsEndpoint.GetTransactions(string, DateTime?, DateTime?, CancellationToken)"/> method because the end date value was not accepted.</param>
#endif
[JsonConstructor]
public AccountsError(string summary, string detail, string type, BasicError startDateError, BasicError endDateError) : base(summary, detail)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ public class Transaction
/// <param name="entryReference">The identification of the transaction as used for reference by the financial institution.</param>
/// <param name="internalTransactionId">Transaction identifier given by Nordigen.</param>
/// <param name="merchantCategoryCode">Merchant category code as defined by the card issuer.</param>
/// <param name="bookingDateTime">The date and time when the transaction was posted to the account.</param>
[JsonConstructor]
public Transaction(string? transactionId, string? debtorName, MinimalBankAccount? debtorAccount, string? ultimateDebtor, string? creditorName, MinimalBankAccount? creditorAccount, AmountCurrencyPair transactionAmount, string? bankTransactionCode, DateTime? bookingDate, DateTime? valueDate, string? remittanceInformationUnstructured, IEnumerable<string>? remittanceInformationUnstructuredArray, string? endToEndId, string? mandateId, string? proprietaryBankTransactionCode, string? purposeCode, string? debtorAgent, string? creditorAgent, string? ultimateCreditor, string? creditorId, DateTime? valueDateTime, string? remittanceInformationStructured, IEnumerable<string>? remittanceInformationStructuredArray, string? additionalInformation, string? additionalInformationStructured, Balance? balanceAfterTransaction, string? checkId, IEnumerable<string>? currencyExchange, string? entryReference, string? internalTransactionId, string? merchantCategoryCode)
public Transaction(string? transactionId, string? debtorName, MinimalBankAccount? debtorAccount, string? ultimateDebtor, string? creditorName, MinimalBankAccount? creditorAccount, AmountCurrencyPair transactionAmount, string? bankTransactionCode, DateTime? bookingDate, DateTime? valueDate, string? remittanceInformationUnstructured, IEnumerable<string>? remittanceInformationUnstructuredArray, string? endToEndId, string? mandateId, string? proprietaryBankTransactionCode, string? purposeCode, string? debtorAgent, string? creditorAgent, string? ultimateCreditor, string? creditorId, DateTime? valueDateTime, string? remittanceInformationStructured, IEnumerable<string>? remittanceInformationStructuredArray, string? additionalInformation, string? additionalInformationStructured, Balance? balanceAfterTransaction, string? checkId, IEnumerable<string>? currencyExchange, string? entryReference, string? internalTransactionId, string? merchantCategoryCode, DateTime? bookingDateTime)
{
TransactionId = transactionId;
DebtorName = debtorName;
Expand Down Expand Up @@ -268,6 +269,7 @@ public Transaction(string? transactionId, string? debtorName, MinimalBankAccount
EntryReference = entryReference;
InternalTransactionId = internalTransactionId;
MerchantCategoryCode = merchantCategoryCode;
BookingDateTime = bookingDateTime;
}
}

17 changes: 11 additions & 6 deletions src/RobinTTY.NordigenApiClient/RobinTTY.NordigenApiClient.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<PropertyGroup>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TargetFrameworks>net6.0;net7.0;netstandard2.0</TargetFrameworks>
<LangVersion>11.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Nullable>enable</Nullable><GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Authors>RobinTTY</Authors>
<PackageProjectUrl>https://github.com/RobinTTY/NordigenApiClient</PackageProjectUrl>
<RepositoryUrl>https://github.com/RobinTTY/NordigenApiClient</RepositoryUrl>
Expand All @@ -14,7 +14,7 @@
<PackageTags>Nordigen; API; client</PackageTags>
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/release-notes.txt"))</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Version>4.0.2</Version>
<Version>5.0.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -28,6 +28,11 @@
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="6.25.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' Or '$(TargetFramework)' == 'netstandard2.1' ">
<PackageReference Include="PolySharp" Version="1.10.0" />
<PackageReference Include="System.Net.Http.Json" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="release-notes.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
2 changes: 1 addition & 1 deletion src/RobinTTY.NordigenApiClient/release-notes.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Fixes possible null reference exception on expired access token use.
Added compatability with .NET Standard 2.0.

0 comments on commit ca4bc9f

Please sign in to comment.