diff --git a/docs/business-processes/asynchronous-validations.md b/docs/business-processes/asynchronous-validations.md index 7668090205..5076ceffea 100644 --- a/docs/business-processes/asynchronous-validations.md +++ b/docs/business-processes/asynchronous-validations.md @@ -24,7 +24,7 @@ The following asynchronous validation rules are currently implemented in the cha |VR.505-2|Fee must have period type Month|D23|(✓) Fee only|(✓) Fee only|| |VR.505-3|Subscription must have period type Month|D23|(✓) Subscription only|(✓) Subscription only|| |VR.507-1|The Tariff to which the charge price applies must have 1 price for period type Day, 24 prices for period type Hour or 96 prices for period type Quarter of Hour|E87||(✓) Tariff only|| -|VR.508|Only System Operator role is allowed to submit requests concerning tax tariffs|E0I|(✓) Tariff only|(✓) Tariff only|| +|VR.508|Only System Operator role is allowed to submit requests concerning tax tariffs|E0I|(✓) Tariff only||| |VR.509|The charge price must be plausible (i.e. value less than 1.000.000)|E90||✓|| |VR.513|Charge owner must match sender of a message|E0I|✓|✓|| |VR.531|The occurrence of a charge is mandatory|E0H|✓|✓|| @@ -51,6 +51,7 @@ The following asynchronous validation rules are currently implemented in the cha |VR.924|Price series start interval and effective date must have the same value|E0H||✓|| |VR.925|Price series resolution must match the resolution from the charge|D14||✓|| |VR.926|Price series must include prices|E87||✓|| +|VR.927|Charge must be created before price series can be handled |D14||✓|| * VR.152 is not fully implemented. Right now we only validate that it is filled with something * VR.679 is not fully implemented. For now it verifies that the charge exist, not checking that the linked period is within the charge's validity period diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandler.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandler.cs index b5eae3804e..03fe634c7e 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandler.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandler.cs @@ -81,16 +81,16 @@ public async Task HandleAsync(ChargePriceCommandReceivedEvent chargePriceCommand break; } - var charge = await GetChargeAsync(operation).ConfigureAwait(false); - try { - if (charge is null) + var charge = await GetChargeAsync(operation).ConfigureAwait(false); + if (charge == null) { - throw new InvalidOperationException($"Charge ID '{operation.SenderProvidedChargeId}' does not exist."); + var failure = CreateFailure(new ChargeDoesNotExistRule(), operation); + throw new ChargeOperationFailedException(failure.InvalidRules); } - charge.UpdatePrices( + charge?.UpdatePrices( operation.Resolution, operation.PointsStartInterval, operation.PointsEndInterval, @@ -116,6 +116,21 @@ public async Task HandleAsync(ChargePriceCommandReceivedEvent chargePriceCommand HandleRejections(document, operationsToBeRejected, rejectionRules); } + private static ValidationResult CreateFailure( + IValidationRule chargeExist, + ChargePriceOperationDto operation) + { + var rules = new List + { + new OperationValidationRuleContainer( + chargeExist, + operation.OperationId), + }; + + var failure = ValidationResult.CreateFailure(rules); + return failure; + } + private void HandleConfirmations( DocumentDto document, IReadOnlyCollection operationsToBeConfirmed) diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactory.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactory.cs index 8cc1a123b3..80639d902f 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactory.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactory.cs @@ -71,7 +71,7 @@ private async Task> GetRulesForChargeLinkDtoAsync var charge = await _chargeRepository.SingleOrNullAsync(chargeIdentifier).ConfigureAwait(false); - rules.Add(new OperationValidationRuleContainer(new ChargeMustExistRule(charge), operation.OperationId)); + rules.Add(new OperationValidationRuleContainer(new ChargeMustExistOnLinkStartDateRule(charge), operation.OperationId)); if (charge == null) return rules; diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistRule.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistOnLinkStartDateRule.cs similarity index 83% rename from source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistRule.cs rename to source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistOnLinkStartDateRule.cs index c9c3035d17..792e41534f 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistRule.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistOnLinkStartDateRule.cs @@ -17,16 +17,16 @@ namespace GreenEnergyHub.Charges.Domain.Dtos.ChargeLinksCommands.Validation.BusinessValidation.ValidationRules { - public class ChargeMustExistRule : IValidationRule + public class ChargeMustExistOnLinkStartDateRule : IValidationRule { private readonly Charge? _existingCharge; - public ChargeMustExistRule(Charge? existingCharge) + public ChargeMustExistOnLinkStartDateRule(Charge? existingCharge) { _existingCharge = existingCharge; } - public ValidationRuleIdentifier ValidationRuleIdentifier => ValidationRuleIdentifier.ChargeDoesNotExist; + public ValidationRuleIdentifier ValidationRuleIdentifier => ValidationRuleIdentifier.ChargeDoesNotExistOnLinkStartDate; public bool IsValid => _existingCharge is not null; } diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/BusinessValidation/ValidationRules/ChargeDoesNotExistRule.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/BusinessValidation/ValidationRules/ChargeDoesNotExistRule.cs new file mode 100644 index 0000000000..450883ec06 --- /dev/null +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/BusinessValidation/ValidationRules/ChargeDoesNotExistRule.cs @@ -0,0 +1,25 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using GreenEnergyHub.Charges.Domain.Dtos.Validation; + +namespace GreenEnergyHub.Charges.Domain.Dtos.ChargePriceCommands.Validation.BusinessValidation.ValidationRules +{ + public class ChargeDoesNotExistRule : IValidationRule + { + public ValidationRuleIdentifier ValidationRuleIdentifier => ValidationRuleIdentifier.ChargeDoesNotExist; + + public bool IsValid => false; + } +} diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/BusinessValidation/ValidationRules/UpdateTaxTariffOnlyAllowedBySystemOperatorRule.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/BusinessValidation/ValidationRules/UpdateTaxTariffOnlyAllowedBySystemOperatorRule.cs deleted file mode 100644 index 456585f4c7..0000000000 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/ChargePriceCommands/Validation/BusinessValidation/ValidationRules/UpdateTaxTariffOnlyAllowedBySystemOperatorRule.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020 Energinet DataHub A/S -// -// Licensed under the Apache License, Version 2.0 (the "License2"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using GreenEnergyHub.Charges.Domain.Charges; -using GreenEnergyHub.Charges.Domain.Dtos.SharedDtos; -using GreenEnergyHub.Charges.Domain.Dtos.Validation; - -namespace GreenEnergyHub.Charges.Domain.Dtos.ChargePriceCommands.Validation.BusinessValidation.ValidationRules -{ - public class UpdateTaxTariffOnlyAllowedBySystemOperatorRule : IValidationRule - { - private readonly ChargeType _chargeType; - private readonly MarketParticipantRole _businessProcessRole; - private readonly bool _taxIndicator; - - public UpdateTaxTariffOnlyAllowedBySystemOperatorRule( - ChargeType chargeType, MarketParticipantRole businessProcessRole, bool taxIndicator) - { - _chargeType = chargeType; - _businessProcessRole = businessProcessRole; - _taxIndicator = taxIndicator; - } - - public bool IsValid => _chargeType is not ChargeType.Tariff || - !_taxIndicator || - _businessProcessRole is MarketParticipantRole.SystemOperator; - - public ValidationRuleIdentifier ValidationRuleIdentifier => - ValidationRuleIdentifier.UpdateTaxTariffOnlyAllowedBySystemOperator; - } -} diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/Validation/ValidationRuleIdentifier.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/Validation/ValidationRuleIdentifier.cs index 976ea6f8fc..5fc62356d4 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/Validation/ValidationRuleIdentifier.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Domain/Dtos/Validation/ValidationRuleIdentifier.cs @@ -39,7 +39,7 @@ public enum ValidationRuleIdentifier ChargePriceMaximumDigitsAndDecimals = 24, // VR457 / E86 CommandSenderMustBeAnExistingMarketParticipant = 27, // VR152 / D02 MeteringPointDoesNotExist = 29, // VR200 / E10 - ChargeDoesNotExist = 30, // VR679 / E0I + ChargeDoesNotExistOnLinkStartDate = 30, // VR679 / E0I ChargeLinkUpdateNotYetSupported = 31, // VR902 / D13 UpdateChargeMustHaveEffectiveDateBeforeOrOnStopDate = 32, // VR905 / D14 SubsequentBundleOperationsFail = 33, // VR906 / D14 @@ -60,10 +60,10 @@ public enum ValidationRuleIdentifier ChargeOperationIdLengthValidation = 49, // VR922 / E86 ChargeOwnerMustMatchSender = 50, // VR513 / E0I ChargeTypeTariffTaxIndicatorOnlyAllowedBySystemOperator = 51, // VR508 / E0I - UpdateTaxTariffOnlyAllowedBySystemOperator = 52, // VR508 / E0I MonthlyPriceSeriesEndDateMustBeFirstOfMonthOrEqualChargeStopDate = 53, // VR923 / D14 EffectiveDateMustMatchPriceSeriesStartInterval = 54, // VR924 / E0H PriceSeriesResolutionMustMatchChargeResolution = 55, // VR925 / D14 PointsRequired = 56, // VR926 / E87 + ChargeDoesNotExist = 57, // VR927 / D14 } } diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Infrastructure.Core/Cim/ValidationErrors/CimValidationErrorTextTemplateMessages.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Infrastructure.Core/Cim/ValidationErrors/CimValidationErrorTextTemplateMessages.cs index 0014015f38..d7cf4c8605 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Infrastructure.Core/Cim/ValidationErrors/CimValidationErrorTextTemplateMessages.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Infrastructure.Core/Cim/ValidationErrors/CimValidationErrorTextTemplateMessages.cs @@ -109,10 +109,6 @@ public static class CimValidationErrorTextTemplateMessages public const string ChargeTypeTariffTaxIndicatorOnlyAllowedBySystemOperatorErrorText = "The sender role used is not allowed to set tax indicator to {{ChargeTaxIndicator}} for charge ID {{DocumentSenderProvidedChargeId}} of type {{ChargeType}} owned by {{ChargeOwner}}"; - [ErrorMessageFor(ValidationRuleIdentifier.UpdateTaxTariffOnlyAllowedBySystemOperator)] - public const string UpdateTaxTariffOnlyAllowedBySystemOperatorErrorText = - "The sender role used is not allowed to submit a price series for charge ID {{DocumentSenderProvidedChargeId}} of type {{ChargeType}} owned by {{ChargeOwner}} as it is marked as a tax"; - [ErrorMessageFor(ValidationRuleIdentifier.MaximumPrice)] public const string MaximumPriceErrorText = "Price {{ChargePointPrice}} not allowed: The specified charge price for position {{ChargePointPosition}} is not plausible (too large) for charge with ID {{DocumentSenderProvidedChargeId}} of type {{ChargeType}} owned by {{ChargeOwner}}."; @@ -129,8 +125,8 @@ public static class CimValidationErrorTextTemplateMessages public const string MeteringPointDoesNotExistValidationErrorText = "Metering point ID {{MeteringPointId}} is unknown: The specified metering point has not been registered in the system on the charge link start date."; - [ErrorMessageFor(ValidationRuleIdentifier.ChargeDoesNotExist)] - public const string ChargeDoesNotExistValidationErrorText = + [ErrorMessageFor(ValidationRuleIdentifier.ChargeDoesNotExistOnLinkStartDate)] + public const string ChargeDoesNotExistOnLinkStartDateValidationErrorText = "Charge ID {{DocumentSenderProvidedChargeId}} not allowed: The charge is not an existing charge on date {{ChargeLinkStartDate}}."; [ErrorMessageFor(ValidationRuleIdentifier.ChargeLinkUpdateNotYetSupported)] @@ -221,6 +217,10 @@ public static class CimValidationErrorTextTemplateMessages public const string PointsIsRequiredErrorText = "Price series with transaction id {{ChargeOperationId}} does not contain any prices for charge with ID {{DocumentSenderProvidedChargeId}} of type {{ChargeType}} owned by {{ChargeOwner}}."; + [ErrorMessageFor(ValidationRuleIdentifier.ChargeDoesNotExist)] + public const string ChargeDoesNotExistErrorText = + "Charge ID {{DocumentSenderProvidedChargeId}} of type {{ChargeType}} owned by {{ChargeOwner}} does not exist."; + public const string Unknown = "unknown"; } } diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.MessageHub/Models/Shared/CimValidationErrorCodeFactory.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.MessageHub/Models/Shared/CimValidationErrorCodeFactory.cs index 9e5024731d..1c935640c6 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.MessageHub/Models/Shared/CimValidationErrorCodeFactory.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.MessageHub/Models/Shared/CimValidationErrorCodeFactory.cs @@ -47,7 +47,7 @@ public ReasonCode Create(ValidationRuleIdentifier validationRuleIdentifier) ValidationRuleIdentifier.ChargePriceMaximumDigitsAndDecimals => ReasonCode.E86, ValidationRuleIdentifier.CommandSenderMustBeAnExistingMarketParticipant => ReasonCode.D02, ValidationRuleIdentifier.MeteringPointDoesNotExist => ReasonCode.E10, - ValidationRuleIdentifier.ChargeDoesNotExist => ReasonCode.E0I, + ValidationRuleIdentifier.ChargeDoesNotExistOnLinkStartDate => ReasonCode.E0I, ValidationRuleIdentifier.ChargeLinkUpdateNotYetSupported => ReasonCode.D13, ValidationRuleIdentifier.UpdateChargeMustHaveEffectiveDateBeforeOrOnStopDate => ReasonCode.D14, ValidationRuleIdentifier.SubsequentBundleOperationsFail => ReasonCode.D14, @@ -68,11 +68,11 @@ public ReasonCode Create(ValidationRuleIdentifier validationRuleIdentifier) ValidationRuleIdentifier.ChargeOperationIdLengthValidation => ReasonCode.E86, ValidationRuleIdentifier.ChargeOwnerMustMatchSender => ReasonCode.E0I, ValidationRuleIdentifier.ChargeTypeTariffTaxIndicatorOnlyAllowedBySystemOperator => ReasonCode.E0I, - ValidationRuleIdentifier.UpdateTaxTariffOnlyAllowedBySystemOperator => ReasonCode.E0I, ValidationRuleIdentifier.MonthlyPriceSeriesEndDateMustBeFirstOfMonthOrEqualChargeStopDate => ReasonCode.D14, ValidationRuleIdentifier.EffectiveDateMustMatchPriceSeriesStartInterval => ReasonCode.E0H, ValidationRuleIdentifier.PriceSeriesResolutionMustMatchChargeResolution => ReasonCode.D14, ValidationRuleIdentifier.PointsRequired => ReasonCode.E87, + ValidationRuleIdentifier.ChargeDoesNotExist => ReasonCode.D14, _ => throw new NotImplementedException(), }; } diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandlerTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandlerTests.cs index 486a47c31e..0041ecd67e 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandlerTests.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Application/Charges/Handlers/ChargePrice/ChargePriceOperationsHandlerTests.cs @@ -145,6 +145,42 @@ public async Task HandleAsync_WhenValidationFails_ThenRejectedEventRaised( domainEventPublisher.VerifyNoOtherCalls(); } + [Theory] + [InlineAutoMoqData] + public async Task HandleAsync_WhenChargeDoesNotExist_ThenRejectedEventRaised( + [Frozen] Mock chargeIdentifierFactory, + [Frozen] Mock> inputValidator, + [Frozen] Mock chargeRepository, + [Frozen] Mock marketParticipantRepository, + [Frozen] Mock domainEventPublisher, + [Frozen] Mock chargePriceOperationsRejectedEventFactory, + TestMarketParticipant sender, + ChargePriceCommandReceivedEvent receivedEvent, + ChargePriceOperationsRejectedEvent chargePriceOperationsRejectedEvent, + ChargePriceOperationsHandler sut) + { + // Arrange + var validationResult = ValidationResult.CreateSuccess(); + inputValidator.Setup(v => v.Validate(It.IsAny(), It.IsAny())).Returns(validationResult); + chargePriceOperationsRejectedEventFactory + .Setup(c => c.Create( + It.IsAny(), + It.IsAny>(), + It.IsAny())) + .Returns(chargePriceOperationsRejectedEvent); + SetupChargeRepository(chargeRepository, null); + SetupMarketParticipantRepository(marketParticipantRepository, sender); + SetupChargeIdentifierFactoryMock(chargeIdentifierFactory); + + // Act + await sut.HandleAsync(receivedEvent); + + // Assert + domainEventPublisher.Verify( + x => x.Publish(It.IsAny()), Times.Once); + domainEventPublisher.VerifyNoOtherCalls(); + } + [Theory] [InlineAutoMoqData] public async Task HandleAsync_WhenValidationFails_ThenValidationErrorsAreLogged( @@ -228,7 +264,7 @@ private static void SetupChargeIdentifierFactoryMock(Mock chargeRepository, - Charge charge) + Charge? charge) { chargeRepository .Setup(r => r.SingleOrNullAsync(It.IsAny()))! diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactoryTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactoryTests.cs index 810ca814aa..f7980e9940 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactoryTests.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/Factories/ChargeLinksCommandBusinessValidationRulesFactoryTests.cs @@ -56,7 +56,7 @@ public async Task CreateRulesForChargeCommandAsync_WhenMeteringPointDoesNotExist } [Theory] - [InlineAutoMoqData(typeof(ChargeMustExistRule))] + [InlineAutoMoqData(typeof(ChargeMustExistOnLinkStartDateRule))] public async Task CreateRulesForChargeCommandAsync_WhenChargeDoesNotExistForLinks_ReturnsExpectedMandatoryRules( Type expectedRule, [Frozen] Mock meteringPointRepository, @@ -83,7 +83,7 @@ public async Task CreateRulesForChargeCommandAsync_WhenChargeDoesNotExistForLink } [Theory] - [InlineAutoMoqData(typeof(ChargeMustExistRule))] + [InlineAutoMoqData(typeof(ChargeMustExistOnLinkStartDateRule))] [InlineAutoMoqData(typeof(ChargeLinksUpdateNotYetSupportedRule))] public async Task CreateRulesForChargeCommandAsync_WhenChargeDoesExist_ReturnsExpectedMandatoryRulesForSingleChargeLinks( Type expectedRule, diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistRuleTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistRuleTests.cs index 46c2c1b152..91392f5a5d 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistRuleTests.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargeLinksCommands/Validation/BusinessValidation/ValidationRules/ChargeMustExistRuleTests.cs @@ -29,14 +29,14 @@ public class ChargeMustExistRuleTests public void IsValid_WhenCalledWithCharge_ReturnsTrue(ChargeBuilder chargeBuilder) { var charge = chargeBuilder.Build(); - var sut = new ChargeMustExistRule(charge); + var sut = new ChargeMustExistOnLinkStartDateRule(charge); sut.IsValid.Should().BeTrue(); } [Fact] public void IsValid_WhenCalledWithNull_ReturnsFalse() { - var sut = new ChargeMustExistRule(null); + var sut = new ChargeMustExistOnLinkStartDateRule(null); sut.IsValid.Should().BeFalse(); } } diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/BusinessRules/ValidationRules/ChargeDoesNotExistRuleTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/BusinessRules/ValidationRules/ChargeDoesNotExistRuleTests.cs new file mode 100644 index 0000000000..b5bb33d4b6 --- /dev/null +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/BusinessRules/ValidationRules/ChargeDoesNotExistRuleTests.cs @@ -0,0 +1,38 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using FluentAssertions; +using GreenEnergyHub.Charges.Domain.Dtos.ChargePriceCommands.Validation.BusinessValidation.ValidationRules; +using Xunit; +using Xunit.Categories; + +namespace GreenEnergyHub.Charges.Tests.Domain.Dtos.ChargePriceCommands.Validation.BusinessRules.ValidationRules +{ + [UnitTest] + public class ChargeDoesNotExistRuleTests + { + [Fact] + public void IsValid_ShouldAlwaysBeFalse() + { + // Arrange + var sut = new ChargeDoesNotExistRule(); + + // Act + var actual = sut.IsValid; + + // Assert + actual.Should().BeFalse(); + } + } +} diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/BusinessRules/ValidationRules/UpdateTaxTariffOnlyAllowedBySystemOperatorRuleTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/BusinessRules/ValidationRules/UpdateTaxTariffOnlyAllowedBySystemOperatorRuleTests.cs deleted file mode 100644 index 81e099a81d..0000000000 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/Domain/Dtos/ChargePriceCommands/Validation/BusinessRules/ValidationRules/UpdateTaxTariffOnlyAllowedBySystemOperatorRuleTests.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2020 Energinet DataHub A/S -// -// Licensed under the Apache License, Version 2.0 (the "License2"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -using System; -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using GreenEnergyHub.Charges.Domain.Charges; -using GreenEnergyHub.Charges.Domain.Dtos.ChargePriceCommands.Validation.BusinessValidation.ValidationRules; -using GreenEnergyHub.Charges.Domain.Dtos.SharedDtos; -using GreenEnergyHub.Charges.Domain.Dtos.Validation; -using Xunit; -using Xunit.Categories; - -namespace GreenEnergyHub.Charges.Tests.Domain.Dtos.ChargePriceCommands.Validation.BusinessRules.ValidationRules -{ - [UnitTest] - public class UpdateTaxTariffOnlyAllowedBySystemOperatorRuleTests - { - [Fact] - public void IsValid_WhenChargeTypeNotTariff_IsTrue() - { - // Arrange - var chargeTypes = Enum.GetValues() - .Except(new List { ChargeType.Tariff }); - - foreach (var chargeType in chargeTypes) - { - // Act - var sut = new UpdateTaxTariffOnlyAllowedBySystemOperatorRule( - chargeType, MarketParticipantRole.GridAccessProvider, true); - - // Assert - sut.IsValid.Should().Be(true); - } - } - - [Fact] - public void IsValid_WhenNotSystemOperator_IsFalse() - { - foreach (var senderRole in Enum.GetValues()) - { - // Arrange - var expectedResult = senderRole == MarketParticipantRole.SystemOperator; - - // Act - var sut = new UpdateTaxTariffOnlyAllowedBySystemOperatorRule(ChargeType.Tariff, senderRole, true); - - // Assert - sut.IsValid.Should().Be(expectedResult); - } - } - - [Fact] - public void IsValid_WhenTaxIndicatorIsFalse_IsTrue() - { - // Arrange - // Act - var sut = new UpdateTaxTariffOnlyAllowedBySystemOperatorRule( - ChargeType.Tariff, - MarketParticipantRole.GridAccessProvider, - false); - - // Assert - sut.IsValid.Should().Be(true); - } - - [Fact] - public void ValidationRuleIdentifier_ShouldBeUpdateTaxTariffOnlyAllowedBySystemOperator() - { - // Arrange - // Act - var sut = new UpdateTaxTariffOnlyAllowedBySystemOperatorRule( - ChargeType.Tariff, MarketParticipantRole.SystemOperator, true); - - // Assert - sut.ValidationRuleIdentifier.Should() - .Be(ValidationRuleIdentifier.UpdateTaxTariffOnlyAllowedBySystemOperator); - } - } -} diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/CimValidationErrorCodeFactoryTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/CimValidationErrorCodeFactoryTests.cs index 7e77cd5363..131ed18b39 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/CimValidationErrorCodeFactoryTests.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/CimValidationErrorCodeFactoryTests.cs @@ -48,7 +48,7 @@ public class CimValidationErrorCodeFactoryTests [InlineAutoMoqData(ValidationRuleIdentifier.CommandSenderMustBeAnExistingMarketParticipant, ReasonCode.D02)] [InlineAutoMoqData(ValidationRuleIdentifier.DocumentTypeMustBeRequestChangeOfPriceList, ReasonCode.D02)] [InlineAutoMoqData(ValidationRuleIdentifier.MeteringPointDoesNotExist, ReasonCode.E10)] - [InlineAutoMoqData(ValidationRuleIdentifier.ChargeDoesNotExist, ReasonCode.E0I)] + [InlineAutoMoqData(ValidationRuleIdentifier.ChargeDoesNotExistOnLinkStartDate, ReasonCode.E0I)] [InlineAutoMoqData(ValidationRuleIdentifier.ChargeLinkUpdateNotYetSupported, ReasonCode.D13)] [InlineAutoMoqData(ValidationRuleIdentifier.SubsequentBundleOperationsFail, ReasonCode.D14)] [InlineAutoMoqData(ValidationRuleIdentifier.TransparentInvoicingIsNotAllowedForFee, ReasonCode.D67)] @@ -64,8 +64,9 @@ public class CimValidationErrorCodeFactoryTests [InlineAutoMoqData(ValidationRuleIdentifier.TaxIndicatorMustBeFalseForFee, ReasonCode.D14)] [InlineAutoMoqData(ValidationRuleIdentifier.TaxIndicatorMustBeFalseForSubscription, ReasonCode.D14)] [InlineAutoMoqData(ValidationRuleIdentifier.ChargeTypeTariffTaxIndicatorOnlyAllowedBySystemOperator, ReasonCode.E0I)] - [InlineAutoMoqData(ValidationRuleIdentifier.UpdateTaxTariffOnlyAllowedBySystemOperator, ReasonCode.E0I)] [InlineAutoMoqData(ValidationRuleIdentifier.PriceSeriesResolutionMustMatchChargeResolution, ReasonCode.D14)] + [InlineAutoMoqData(ValidationRuleIdentifier.PointsRequired, ReasonCode.E87)] + [InlineAutoMoqData(ValidationRuleIdentifier.ChargeDoesNotExist, ReasonCode.D14)] public void Create_ReturnsExpectedCode( ValidationRuleIdentifier identifier, ReasonCode expected, diff --git a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/ValidationErrorLogMessageBuilderTests.cs b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/ValidationErrorLogMessageBuilderTests.cs index 5b3fdc0126..943b6be069 100644 --- a/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/ValidationErrorLogMessageBuilderTests.cs +++ b/source/GreenEnergyHub.Charges/source/GreenEnergyHub.Charges.Tests/MessageHub/Models/Shared/ValidationErrorLogMessageBuilderTests.cs @@ -42,7 +42,7 @@ public void BuildErrorMessage_WhenCalled_ShouldReturnErrorMessage( var violatedRules = new List() { new OperationValidationRuleContainer( - new ChargeMustExistRule(null), "operationId1"), + new ChargeMustExistOnLinkStartDateRule(null), "operationId1"), new OperationValidationRuleContainer( new PreviousOperationsMustBeValidRule(chargeInformationOperationDto), "operationId2"), };