Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
fix: unknown resolution in validation do not throw an exception (#1852)
Browse files Browse the repository at this point in the history
* fixed resolution rule

* removed reference
  • Loading branch information
x-platformcoder authored Nov 4, 2022
1 parent 8ab13cc commit 0ec3bd6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Point>());

var sut = new NumberOfPointsMatchTimeIntervalAndResolutionRule(dto);

// Act
Action act = () =>
{
_ = new NumberOfPointsMatchTimeIntervalAndResolutionRule(dto);
};
var actual = sut.IsValid;

// Assert
act.Should().Throw<ArgumentException>();
actual.Should().BeTrue("To avoid throwing an exception, instead it parses with 0 points expected");
}

[Fact]
Expand Down

0 comments on commit 0ec3bd6

Please sign in to comment.