2022-06-15 20:00:31 +03:00
|
|
|
// Copyright 2022 Valters Melnalksnis
|
|
|
|
|
// Licensed under the Apache License 2.0.
|
|
|
|
|
// See LICENSE file in the project root for full license information.
|
|
|
|
|
|
2022-12-06 15:17:44 +01:00
|
|
|
using System;
|
2022-06-15 20:00:31 +03:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
using VMelnalksnis.NordigenDotNet.Agreements;
|
|
|
|
|
|
2022-06-24 16:28:37 +03:00
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
2022-11-09 21:57:31 +02:00
|
|
|
#if NET6_0_OR_GREATER
|
|
|
|
|
using System.Net;
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-06-23 10:00:34 +03:00
|
|
|
using static VMelnalksnis.NordigenDotNet.Tests.Integration.ServiceProviderFixture;
|
|
|
|
|
|
2022-06-15 20:00:31 +03:00
|
|
|
namespace VMelnalksnis.NordigenDotNet.Tests.Integration.Agreements;
|
|
|
|
|
|
|
|
|
|
public sealed class AgreementClientTests : IClassFixture<ServiceProviderFixture>
|
|
|
|
|
{
|
2022-06-16 18:06:00 +03:00
|
|
|
private readonly INordigenClient _nordigenClient;
|
2022-06-15 20:00:31 +03:00
|
|
|
|
2022-06-24 16:28:37 +03:00
|
|
|
public AgreementClientTests(ITestOutputHelper testOutputHelper, ServiceProviderFixture serviceProviderFixture)
|
2022-06-15 20:00:31 +03:00
|
|
|
{
|
2022-06-24 16:28:37 +03:00
|
|
|
_nordigenClient = serviceProviderFixture.GetNordigenClient(testOutputHelper);
|
2022-06-15 20:00:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Get()
|
|
|
|
|
{
|
2022-06-23 10:00:34 +03:00
|
|
|
var creation = new EndUserAgreementCreation(IntegrationInstitutionId);
|
2022-06-15 20:00:31 +03:00
|
|
|
|
2022-06-16 18:06:00 +03:00
|
|
|
var createdAgreement = await _nordigenClient.Agreements.Post(creation);
|
|
|
|
|
(await _nordigenClient.Agreements.Get(createdAgreement.Id)).Should().BeEquivalentTo(createdAgreement);
|
|
|
|
|
|
|
|
|
|
using (new AssertionScope())
|
|
|
|
|
{
|
2022-12-06 15:17:44 +01:00
|
|
|
createdAgreement.Created.Should().BeAfter(DateTimeOffset.Now.AddSeconds(-5));
|
2022-06-16 18:06:00 +03:00
|
|
|
createdAgreement.Accepted.Should().BeNull();
|
|
|
|
|
createdAgreement.MaxHistoricalDays.Should().Be(90);
|
|
|
|
|
createdAgreement.AccessValidForDays.Should().Be(90);
|
|
|
|
|
createdAgreement.AccessScope.Should().BeEquivalentTo("balances", "details", "transactions");
|
|
|
|
|
createdAgreement.InstitutionId.Should().Be(creation.InstitutionId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var agreements = await _nordigenClient.Agreements.Get().ToListAsync();
|
2022-06-15 20:00:31 +03:00
|
|
|
|
|
|
|
|
agreements
|
|
|
|
|
.Should()
|
|
|
|
|
.ContainSingle(agreement => agreement.Id == createdAgreement.Id)
|
|
|
|
|
.Which.Should()
|
|
|
|
|
.BeEquivalentTo(createdAgreement);
|
|
|
|
|
|
|
|
|
|
var acceptance = new EndUserAgreementAcceptance("NordigenDotNet integration test", "127.0.0.1");
|
|
|
|
|
(await FluentActions
|
2022-06-16 18:06:00 +03:00
|
|
|
.Awaiting(() => _nordigenClient.Agreements.Put(createdAgreement.Id, acceptance))
|
2022-06-15 20:00:31 +03:00
|
|
|
.Should()
|
|
|
|
|
.ThrowExactlyAsync<HttpRequestException>())
|
2022-11-09 21:57:31 +02:00
|
|
|
#if NET6_0_OR_GREATER
|
2022-06-15 20:00:31 +03:00
|
|
|
.Which.StatusCode.Should()
|
|
|
|
|
.Be(HttpStatusCode.Forbidden, "test company cannot create agreements");
|
2022-11-09 21:57:31 +02:00
|
|
|
#else
|
|
|
|
|
.Which.Should().NotBeNull("test company cannot create agreements");
|
|
|
|
|
#endif
|
2022-06-15 20:00:31 +03:00
|
|
|
|
2022-06-16 18:06:00 +03:00
|
|
|
await _nordigenClient.Agreements.Delete(createdAgreement.Id);
|
2022-06-15 20:00:31 +03:00
|
|
|
|
|
|
|
|
(await FluentActions
|
2022-06-16 18:06:00 +03:00
|
|
|
.Awaiting(() => _nordigenClient.Agreements.Get(createdAgreement.Id))
|
2022-06-15 20:00:31 +03:00
|
|
|
.Should()
|
|
|
|
|
.ThrowExactlyAsync<HttpRequestException>())
|
2022-11-09 21:57:31 +02:00
|
|
|
#if NET6_0_OR_GREATER
|
2022-06-15 20:00:31 +03:00
|
|
|
.Which.StatusCode.Should()
|
|
|
|
|
.Be(HttpStatusCode.NotFound);
|
2022-11-09 21:57:31 +02:00
|
|
|
#else
|
|
|
|
|
.Which.Should().NotBeNull("test company cannot create agreements");
|
|
|
|
|
#endif
|
2022-06-15 20:00:31 +03:00
|
|
|
}
|
|
|
|
|
}
|