Skip to content

Commit

Permalink
Merge branch 'main' into madu/introduce-new-incoming-message-parser-p…
Browse files Browse the repository at this point in the history
…attern
  • Loading branch information
MadsDue authored Nov 7, 2024
2 parents 9e40066 + 1eeada4 commit 77df95e
Show file tree
Hide file tree
Showing 74 changed files with 2,692 additions and 721 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/processmanager-client-bundle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ on:
env:
# Conditions
PUSH_PACKAGES: ${{ github.event_name != 'pull_request' }}
# Necessary to manage Azure resources from automated tests
AZURE_KEYVAULT_URL: ${{ vars.integration_test_azure_keyvault_url }}
# Set value used by 'AzuriteManager'
# Use 'AzuriteBlobFolderPath' for TestCommon version 4.2.0 and lower
AzuriteBlobFolderPath: ${{ github.workspace }}\node_modules\.bin\
# Use 'AzuriteFolderPath' for TestCommon version 4.3.0 and higher
AzuriteFolderPath: ${{ github.workspace }}\node_modules\.bin\
# Overrides settings in 'functionhost.settings.json'
FunctionAppHostPath: ${{ github.workspace }}\node_modules\azure-functions-core-tools\bin\func.dll

jobs:
build_and_publish:
runs-on: windows-2022
name: Publish bundle to NuGet.org

environment: AzureAuth

# We need to have permissions here to be able to support manually triggering this workflow for releasing a pre-release.
permissions:
id-token: write # Needed by 'dotnet-solution-build-and-test' to login to Azure
Expand All @@ -53,11 +64,17 @@ jobs:

- name: Setup dotnet and tools
uses: Energinet-DataHub/.github/.github/actions/dotnet-setup-and-tools@v13
with:
use_azure_functions_tools: "true"
azure_functions_core_tools_version: 4.0.5455

- name: Build and test solution
uses: Energinet-DataHub/.github/.github/actions/dotnet-solution-build-and-test@v13
with:
solution_file_path: ./source/ProcessManager.Client.Filtered.slnf
azure_tenant_id: ${{ vars.integration_test_azure_tenant_id }}
azure_subscription_id: ${{ vars.integration_test_azure_subscription_id }}
azure_spn_id: ${{ vars.integration_test_azure_spn_id_oidc }}
publish_test_report: "true"

- name: Pack ProcessManager.Client project
Expand Down
4 changes: 4 additions & 0 deletions docs/ProcessManager.Client/ReleaseNotes/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ProcessManager.Client Release Notes

## Version 0.9.0

- Walking skeleton for working with BRS_023_027.

## Version 0.0.1

- Empty release.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Energinet.DataHub.Wholesale.Edi.Validation.Helpers;
using FluentAssertions;
using NodaTime;
using NodaTime.Extensions;
using Xunit;

namespace Energinet.DataHub.Wholesale.Edi.UnitTests.Validators.AggregatedTimeSeriesRequest;
Expand All @@ -27,11 +28,24 @@ public class PeriodValidatorTests
private static readonly ValidationError _invalidDateFormat = new("Forkert dato format for {PropertyName}, skal være YYYY-MM-DDT22:00:00Z eller YYYY-MM-DDT23:00:00Z / Wrong date format for {PropertyName}, must be YYYY-MM-DDT22:00:00Z or YYYY-MM-DDT23:00:00Z", "D66");
private static readonly ValidationError _invalidWinterMidnightFormat = new("Forkert dato format for {PropertyName}, skal være YYYY-MM-DDT23:00:00Z / Wrong date format for {PropertyName}, must be YYYY-MM-DDT23:00:00Z", "D66");
private static readonly ValidationError _invalidSummerMidnightFormat = new("Forkert dato format for {PropertyName}, skal være YYYY-MM-DDT22:00:00Z / Wrong date format for {PropertyName}, must be YYYY-MM-DDT22:00:00Z", "D66");
private static readonly ValidationError _startDateMustBeLessThen3Years = new("Dato må max være 3 år tilbage i tid / Can maximum be 3 years back in time", "E17");

private static readonly ValidationError _startDateMustBeLessThen3Years = new(
"Dato må max være 3 år og 6 måneder tilbage i tid / Can maximum be 3 years and 6 months back in time",
"E17");

private static readonly ValidationError _periodIsGreaterThenAllowedPeriodSize = new("Dato må kun være for 1 måned af gangen / Can maximum be for a 1 month period", "E17");
private static readonly ValidationError _missingStartOrAndEndDate = new("Start og slut dato skal udfyldes / Start and end date must be present in request", "E50");

private readonly PeriodValidationRule _sut = new(new PeriodValidationHelper(DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Copenhagen")!, SystemClock.Instance));
private readonly PeriodValidationRule _sut;
private readonly DateTimeZone? _dateTimeZone = DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Copenhagen");

private Instant _now;

public PeriodValidatorTests()
{
_now = Instant.FromUtc(2024, 5, 31, 22, 0, 0);
_sut = new PeriodValidationRule(new PeriodValidationHelper(_dateTimeZone!, new MockClock(() => _now)));
}

[Fact]
public async Task Validate_WhenRequestIsValid_ReturnsNoValidationErrors()
Expand Down Expand Up @@ -71,8 +85,8 @@ public async Task Validate_WhenEndDateIsUnspecified_ReturnsExpectedValidationErr
public async Task Validate_WhenStartHourIsWrong_ReturnsExpectedValidationError()
{
// Arrange
var now = SystemClock.Instance.GetCurrentInstant();
var notWinterTimeMidnight = Instant.FromUtc(now.InUtc().Year, 1, 1, 22, 0, 0).ToString();
var notWinterTimeMidnight = Instant.FromUtc(_now.InUtc().Year, 1, 1, 22, 0, 0).ToString();

var message = AggregatedTimeSeriesRequestBuilder
.AggregatedTimeSeriesRequest()
.WithStartDate(notWinterTimeMidnight)
Expand All @@ -92,12 +106,11 @@ public async Task Validate_WhenStartHourIsWrong_ReturnsExpectedValidationError()
public async Task Validate_WhenEndHourIsWrong_ReturnsExpectedValidationError()
{
// Arrange
var now = SystemClock.Instance.GetCurrentInstant();
var notSummerTimeMidnight = Instant.FromUtc(now.InUtc().Year, 7, 1, 23, 0, 0).ToString();
var notSummerTimeMidnight = Instant.FromUtc(_now.InUtc().Year, 7, 1, 23, 0, 0).ToString();
var message = AggregatedTimeSeriesRequestBuilder
.AggregatedTimeSeriesRequest()
.WithEndDate(notSummerTimeMidnight)
.WithStartDate(Instant.FromUtc(now.InUtc().Year, 7, 2, 22, 0, 0).ToString())
.WithStartDate(Instant.FromUtc(_now.InUtc().Year, 7, 2, 22, 0, 0).ToString())
.Build();

// Act
Expand Down Expand Up @@ -154,8 +167,8 @@ public async Task Validate_WhenStartAndEndDateAreInvalid_ReturnsExpectedValidati
public async Task Validate_WhenPeriodSizeIsGreaterThenAllowed_ReturnsExpectedValidationError()
{
// Arrange
var now = SystemClock.Instance.GetCurrentInstant();
var winterTimeMidnight = Instant.FromUtc(now.InUtc().Year, 1, 1, 23, 0, 0);
var winterTimeMidnight = Instant.FromUtc(_now.InUtc().Year, 1, 1, 23, 0, 0);

var message = AggregatedTimeSeriesRequestBuilder
.AggregatedTimeSeriesRequest()
.WithStartDate(winterTimeMidnight.ToString())
Expand Down Expand Up @@ -215,9 +228,8 @@ public async Task Validate_WhenPeriodOverlapSummerDaylightSavingTime_ReturnsNoVa
public async Task Validate_WhenPeriodOverlapWinterDaylightSavingTime_ReturnsNoValidationErrors()
{
// Arrange
var now = SystemClock.Instance.GetCurrentInstant();
var summerTime = Instant.FromUtc(now.InUtc().Year, 9, 29, 22, 0, 0).ToString();
var winterTime = Instant.FromUtc(now.InUtc().Year, 10, 29, 23, 0, 0).ToString();
var summerTime = Instant.FromUtc(_now.InUtc().Year, 9, 29, 22, 0, 0).ToString();
var winterTime = Instant.FromUtc(_now.InUtc().Year, 10, 29, 23, 0, 0).ToString();
var message = AggregatedTimeSeriesRequestBuilder
.AggregatedTimeSeriesRequest()
.WithStartDate(summerTime)
Expand All @@ -230,4 +242,94 @@ public async Task Validate_WhenPeriodOverlapWinterDaylightSavingTime_ReturnsNoVa
// Assert
errors.Should().BeEmpty();
}

[Fact]
public async Task
Validate_WhenPeriodStartIsMoreThan3YearsAnd6MonthsOldAndPeriodNotPartOfCutOffMonth_ReturnsExpectedValidationError()
{
// Arrange
var dateTimeOffset = _now.ToDateTimeOffset().AddYears(-5);

var message = AggregatedTimeSeriesRequestBuilder
.AggregatedTimeSeriesRequest()
.WithStartDate(dateTimeOffset.ToInstant().ToString())
.WithEndDate(dateTimeOffset.AddMonths(1).ToInstant().ToString())
.Build();

// Act
var errors = await _sut.ValidateAsync(message);

// Assert
errors.Should().ContainSingle().Subject.Should().Be(_startDateMustBeLessThen3Years);
}

[Fact]
public async Task Validate_WhenPeriodStartIsLessThan3YearsAnd6MonthsOld_ReturnNoValidationError()
{
// Arrange
_now = new LocalDateTime(2024, 6, 1, 0, 0, 0)
.InZoneStrictly(_dateTimeZone!)
.ToInstant();

// Using a start date 2 years, 8 months, 14 days, 13 hours, 25 minutes and 37 seconds back in time
var start = new LocalDateTime(2022, 4, 1, 0, 0, 0)
.InZoneStrictly(_dateTimeZone!)
.ToInstant();

// Using an end date 2 years, 7 months, 14 days, 13 hours, 25 minutes and 37 seconds back in time
var end = new LocalDateTime(2022, 5, 1, 0, 0, 0)
.InZoneStrictly(_dateTimeZone!)
.ToInstant();

var message = AggregatedTimeSeriesRequestBuilder
.AggregatedTimeSeriesRequest()
.WithStartDate(start.ToString())
.WithEndDate(end.ToString())
.Build();

// Act
var errors = await _sut.ValidateAsync(message);

// Assert
errors.Should().BeEmpty();
}

[Fact]
public async Task
Validate_WhenPeriodStartIsMoreThan3And6MonthsBackInTimeButPartOfCutOffMonth_ReturnsNoValidationError()
{
// Arrange
_now = new LocalDateTime(2024, 12, 15, 13, 25, 37)
.InZoneStrictly(_dateTimeZone!)
.ToInstant();

// Using a start date 3 years, 6 months, 14 days, 13 hours, 25 minutes and 37 seconds back in time
var periodStartDate = new LocalDateTime(2021, 6, 1, 0, 0, 0)
.InZoneStrictly(_dateTimeZone!)
.ToInstant();

// Using an end date 3 years, 5 months, 14 days, 13 hours, 25 minutes and 37 seconds back in time
var periodEndDate = new LocalDateTime(2021, 7, 1, 0, 0, 0)
.InZoneStrictly(_dateTimeZone!)
.ToInstant();

var message = AggregatedTimeSeriesRequestBuilder
.AggregatedTimeSeriesRequest()
.WithStartDate(periodStartDate.ToString())
.WithEndDate(periodEndDate.ToString())
.Build();

// Act
var errors = await _sut.ValidateAsync(message);

// Assert
errors.Should().BeEmpty();
}

private sealed class MockClock(Func<Instant> getInstant) : IClock
{
private readonly Func<Instant> _getInstant = getInstant;

public Instant GetCurrentInstant() => _getInstant.Invoke();
}
}
Loading

0 comments on commit 77df95e

Please sign in to comment.