From 0ec3bd6d74dba16e6b92d6f9c277f94415ede461 Mon Sep 17 00:00:00 2001 From: Jan Duelund Date: Fri, 4 Nov 2022 14:24:42 +0100 Subject: [PATCH] fix: unknown resolution in validation do not throw an exception (#1852) * fixed resolution rule * removed reference --- ...ointsMatchTimeIntervalAndResolutionRule.cs | 2 +- ...MatchTimeIntervalAndResolutionRuleTests.cs | 25 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRule.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRule.cs index abc4c4afc0..2df67f8484 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRule.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRule.cs @@ -40,7 +40,7 @@ private void SetExpectedPointCount(Resolution resolution) _expectedPointCount = resolution switch { - Resolution.Unknown => throw new ArgumentException("Resolution may not be unknown"), + Resolution.Unknown => 0, Resolution.PT15M => interval.Duration.TotalMinutes / 15, Resolution.PT1H => interval.Duration.TotalHours, Resolution.P1D => interval.Duration.TotalDays, diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRuleTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRuleTests.cs index 3098ddebf2..501b75af67 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRuleTests.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/InputValidation/ValidationRules/NumberOfPointsMatchTimeIntervalAndResolutionRuleTests.cs @@ -13,9 +13,11 @@ // limitations under the License. using System; +using System.Collections.Generic; using Energinet.DataHub.Core.TestCommon.AutoFixture.Attributes; using FluentAssertions; using GreenEnergyHub.Charges.Domain.Charges; +using GreenEnergyHub.Charges.Domain.Dtos.ChargePriceCommands; using GreenEnergyHub.Charges.Domain.Dtos.ChargePriceCommands.Validation.InputValidation.ValidationRules; using GreenEnergyHub.Charges.TestCore.Builders.Command; using NodaTime; @@ -80,19 +82,28 @@ public void IsValid_WhenCalledWithCorrectNumberOfPrices_ShouldParse( } [Fact] - public void IsValid_WhenCalledWithUnknownPriceResolution_ShouldThrowArgumentException() + public void IsValid_WhenCalledWithUnknownPriceResolution_ShouldParse() { // Arrange - var dto = new ChargePriceOperationDtoBuilder().WithPriceResolution(Resolution.Unknown).Build(); + var dto = new ChargePriceOperationDto( + "operationId", + ChargeType.Tariff, + "chargeId", + "owner", + Instant.MinValue, + Instant.MinValue, + Instant.MinValue, + Instant.MinValue, + Resolution.Unknown, + new List()); + + var sut = new NumberOfPointsMatchTimeIntervalAndResolutionRule(dto); // Act - Action act = () => - { - _ = new NumberOfPointsMatchTimeIntervalAndResolutionRule(dto); - }; + var actual = sut.IsValid; // Assert - act.Should().Throw(); + actual.Should().BeTrue("To avoid throwing an exception, instead it parses with 0 points expected"); } [Fact]