diff --git a/source/B2BApi/IncomingMessages/EbixIncomingMessageReceiver.cs b/source/B2BApi/IncomingMessages/EbixIncomingMessageReceiver.cs index cec4ef17cf..6dfd59550e 100644 --- a/source/B2BApi/IncomingMessages/EbixIncomingMessageReceiver.cs +++ b/source/B2BApi/IncomingMessages/EbixIncomingMessageReceiver.cs @@ -62,7 +62,7 @@ public async Task RunAsync( .ReceiveIncomingMarketMessageAsync( incomingMarketMessageStream, incomingDocumentFormat: DocumentFormat.Ebix, - IncomingDocumentType.MeteredDataForMeasurementPoint, + IncomingDocumentType.NotifyValidatedMeasureData, responseDocumentFormat: DocumentFormat.Ebix, cancellationToken) .ConfigureAwait(false); diff --git a/source/B2BApi/IncomingMessages/IncomingMessageReceiver.cs b/source/B2BApi/IncomingMessages/IncomingMessageReceiver.cs index ec318d81c8..87ffc8477e 100644 --- a/source/B2BApi/IncomingMessages/IncomingMessageReceiver.cs +++ b/source/B2BApi/IncomingMessages/IncomingMessageReceiver.cs @@ -137,7 +137,7 @@ private static async Task CreateResponseAsync( { { IncomingDocumentType.RequestAggregatedMeasureData, AuditLogEntityType.RequestAggregatedMeasureData }, { IncomingDocumentType.RequestWholesaleSettlement, AuditLogEntityType.RequestWholesaleServices }, - { IncomingDocumentType.MeteredDataForMeasurementPoint, AuditLogEntityType.MeteredDataForMeasurementPointReceived }, + { IncomingDocumentType.NotifyValidatedMeasureData, AuditLogEntityType.MeteredDataForMeasurementPointReceived }, }; entityTypeMapping.TryGetValue(incomingDocumentType, out var affectedEntityType); diff --git a/source/BuildingBlocks.Domain/Models/DocumentType.cs b/source/BuildingBlocks.Domain/Models/DocumentType.cs index 16343e88a0..106b4ec379 100644 --- a/source/BuildingBlocks.Domain/Models/DocumentType.cs +++ b/source/BuildingBlocks.Domain/Models/DocumentType.cs @@ -20,7 +20,7 @@ public class DocumentType : EnumerationType public static readonly DocumentType RejectRequestAggregatedMeasureData = new(nameof(RejectRequestAggregatedMeasureData), MessageCategory.Aggregations); public static readonly DocumentType NotifyWholesaleServices = new(nameof(NotifyWholesaleServices), MessageCategory.Aggregations); public static readonly DocumentType RejectRequestWholesaleSettlement = new(nameof(RejectRequestWholesaleSettlement), MessageCategory.Aggregations); - public static readonly DocumentType MeteredDataForMeasurementPoint = new(nameof(MeteredDataForMeasurementPoint), MessageCategory.TimeSeries); + public static readonly DocumentType NotifyValidatedMeasureData = new(nameof(NotifyValidatedMeasureData), MessageCategory.TimeSeries); private DocumentType(string name, MessageCategory category) : base(name) diff --git a/source/BuildingBlocks.Domain/Models/IncomingDocumentType.cs b/source/BuildingBlocks.Domain/Models/IncomingDocumentType.cs index 033da05b71..af9376fe0a 100644 --- a/source/BuildingBlocks.Domain/Models/IncomingDocumentType.cs +++ b/source/BuildingBlocks.Domain/Models/IncomingDocumentType.cs @@ -20,7 +20,7 @@ public class IncomingDocumentType : EnumerationType public static readonly IncomingDocumentType B2CRequestAggregatedMeasureData = new(nameof(B2CRequestAggregatedMeasureData)); public static readonly IncomingDocumentType RequestWholesaleSettlement = new(nameof(RequestWholesaleSettlement)); public static readonly IncomingDocumentType B2CRequestWholesaleSettlement = new(nameof(B2CRequestWholesaleSettlement)); - public static readonly IncomingDocumentType MeteredDataForMeasurementPoint = new(nameof(MeteredDataForMeasurementPoint)); + public static readonly IncomingDocumentType NotifyValidatedMeasureData = new(nameof(NotifyValidatedMeasureData)); private IncomingDocumentType(string name) : base(name) diff --git a/source/Edi.UnitTests/Validators/WholesaleServicesRequest/WholesaleServicesRequestValidatorTests.cs b/source/Edi.UnitTests/Validators/WholesaleServicesRequest/WholesaleServicesRequestValidatorTests.cs index a33cd88835..fa9643bb8d 100644 --- a/source/Edi.UnitTests/Validators/WholesaleServicesRequest/WholesaleServicesRequestValidatorTests.cs +++ b/source/Edi.UnitTests/Validators/WholesaleServicesRequest/WholesaleServicesRequestValidatorTests.cs @@ -83,14 +83,16 @@ public async Task Validate_WhenPeriodStartAndPeriodEndAreInvalidFormat_ReturnsUn // Arrange var now = SystemClock.Instance.GetCurrentInstant().ToDateTimeOffset(); + var startToYearsAgo = now.AddYears(-2); + var endToYearsAgo = now.AddYears(-2).AddMonths(1); var request = new WholesaleServicesRequestBuilder() .WithPeriodStart( - new LocalDateTime(now.Year - 2, now.Month, 1, 17, 45, 12) + new LocalDateTime(startToYearsAgo.Year, startToYearsAgo.Month, 1, 17, 45, 12) .InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Copenhagen")!) .ToInstant() .ToString()) .WithPeriodEnd( - new LocalDateTime(now.Year - 2, now.Month + 1, 1, 8, 13, 56) + new LocalDateTime(endToYearsAgo.Year, endToYearsAgo.Month, 1, 8, 13, 56) .InZoneStrictly(DateTimeZoneProviders.Tzdb.GetZoneOrNull("Europe/Copenhagen")!) .ToInstant() .ToString()) @@ -100,8 +102,7 @@ public async Task Validate_WhenPeriodStartAndPeriodEndAreInvalidFormat_ReturnsUn var validationErrors = await _sut.ValidateAsync(request); // Assert - validationErrors.Should().HaveCount(2); - validationErrors.Select(e => e.ErrorCode).Should().BeEquivalentTo(["D66", "D66"]); + validationErrors.Where(x => x.ErrorCode == "D66").Should().HaveCount(2); } [Fact] diff --git a/source/IncomingMessages.Application/DelegateIncomingMessage.cs b/source/IncomingMessages.Application/DelegateIncomingMessage.cs index 0f978d5af1..d22d0a8db1 100644 --- a/source/IncomingMessages.Application/DelegateIncomingMessage.cs +++ b/source/IncomingMessages.Application/DelegateIncomingMessage.cs @@ -156,7 +156,7 @@ private ProcessType MapToProcessType(IncomingDocumentType incomingDocumentType) { IncomingDocumentType.B2CRequestAggregatedMeasureData, ProcessType.RequestEnergyResults }, { IncomingDocumentType.RequestWholesaleSettlement, ProcessType.RequestWholesaleResults }, { IncomingDocumentType.B2CRequestWholesaleSettlement, ProcessType.RequestWholesaleResults }, - { IncomingDocumentType.MeteredDataForMeasurementPoint, ProcessType.IncomingMeteredDataForMeasurementPoint }, + { IncomingDocumentType.NotifyValidatedMeasureData, ProcessType.IncomingMeteredDataForMeasurementPoint }, }; if (documentTypeToProcessTypeMap.TryGetValue(incomingDocumentType, out var processType)) diff --git a/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs b/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs index 48953ae255..bcfe9b9006 100644 --- a/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs +++ b/source/IncomingMessages.Application/UseCases/ReceiveIncomingMarketMessage.cs @@ -144,7 +144,7 @@ await _delegateIncomingMessage private static bool ShouldArchive(IncomingDocumentType documentType) { - return documentType != IncomingDocumentType.MeteredDataForMeasurementPoint; + return documentType != IncomingDocumentType.NotifyValidatedMeasureData; } private async Task ParseIncomingMessageAsync( diff --git a/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointEbixMessageParser.cs b/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointEbixMessageParser.cs index ba5dc7c7b7..8877ebbc73 100644 --- a/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointEbixMessageParser.cs +++ b/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointEbixMessageParser.cs @@ -37,7 +37,7 @@ public class MeteredDateForMeasurementPointEbixMessageParser(EbixSchemaProvider private const string QuantityQuality = "QuantityQuality"; private const string IntervalEnergyObservation = "IntervalEnergyObservation"; - public override IncomingDocumentType DocumentType => IncomingDocumentType.MeteredDataForMeasurementPoint; + public override IncomingDocumentType DocumentType => IncomingDocumentType.NotifyValidatedMeasureData; public override DocumentFormat DocumentFormat => DocumentFormat.Ebix; diff --git a/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointJsonMessageParser.cs b/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointJsonMessageParser.cs index 53aed69ab9..fdde2b3336 100644 --- a/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointJsonMessageParser.cs +++ b/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointJsonMessageParser.cs @@ -38,7 +38,7 @@ public class MeteredDateForMeasurementPointJsonMessageParser(JsonSchemaProvider private const string QuantityElementName = "quantity"; private const string RegistrationDateAndOrTimeElementName = "registration_DateAndOrTime.dateTime"; - public override IncomingDocumentType DocumentType => IncomingDocumentType.MeteredDataForMeasurementPoint; + public override IncomingDocumentType DocumentType => IncomingDocumentType.NotifyValidatedMeasureData; public override DocumentFormat DocumentFormat => DocumentFormat.Json; diff --git a/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointXmlMessageParser.cs b/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointXmlMessageParser.cs index 6ffa82d2c4..6b1026a0ae 100644 --- a/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointXmlMessageParser.cs +++ b/source/IncomingMessages.Domain/MessageParsers/RSM012/MeteredDateForMeasurementPointXmlMessageParser.cs @@ -39,7 +39,7 @@ public class MeteredDateForMeasurementPointXmlMessageParser(CimXmlSchemaProvider private const string QualityElementName = "quality"; private const string RegistrationDateAndOrTimeElementName = "registration_DateAndOrTime.dateTime"; - public override IncomingDocumentType DocumentType => IncomingDocumentType.MeteredDataForMeasurementPoint; + public override IncomingDocumentType DocumentType => IncomingDocumentType.NotifyValidatedMeasureData; protected override string RootPayloadElementName => "NotifyValidatedMeasureData_MarketDocument"; diff --git a/source/IncomingMessages.IntegrationTests/IncomingMessages/GivenIncomingMessagesTests.cs b/source/IncomingMessages.IntegrationTests/IncomingMessages/GivenIncomingMessagesTests.cs index c925d35d15..c4e77590e8 100644 --- a/source/IncomingMessages.IntegrationTests/IncomingMessages/GivenIncomingMessagesTests.cs +++ b/source/IncomingMessages.IntegrationTests/IncomingMessages/GivenIncomingMessagesTests.cs @@ -68,9 +68,9 @@ public static TheoryData GivenReceivedMeteredDataForMeasurementPoin incomingMessageClient.ReceiveIncomingMarketMessageAsync( incomingMessageStream, documentFormat, - IncomingDocumentType.MeteredDataForMeasurementPoint, + IncomingDocumentType.NotifyValidatedMeasureData, documentFormat, CancellationToken.None); @@ -67,7 +67,7 @@ protected async Task GivenReceivedMeteredDataForMeasurementPoin using var scope = new AssertionScope(); response.IsErrorResponse .Should() - .BeFalse("because the response should not have an error. Actual response: {0}", response.MessageBody); + .BeFalse("the response should not have an error. Actual response: {0}", response.MessageBody); response.MessageBody.Should().BeEmpty(); diff --git a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs index 0a7498e305..154447b9a6 100644 --- a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs +++ b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimJsonDocumentWriter.cs @@ -38,7 +38,7 @@ public bool HandlesFormat(DocumentFormat format) public bool HandlesType(DocumentType documentType) { - return documentType == DocumentType.MeteredDataForMeasurementPoint; + return documentType == DocumentType.NotifyValidatedMeasureData; } public async Task WriteAsync( diff --git a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimXmlDocumentWriter.cs b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimXmlDocumentWriter.cs index 2aab3916cc..12a0cc6c3d 100644 --- a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimXmlDocumentWriter.cs +++ b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointCimXmlDocumentWriter.cs @@ -12,29 +12,77 @@ // See the License for the specific language governing permissions and // limitations under the License. -using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; -using Energinet.DataHub.EDI.OutgoingMessages.Domain.Models.MarketDocuments; -using Energinet.DataHub.EDI.OutgoingMessages.Domain.Models.OutgoingMessages; +using System.Globalization; +using System.Xml; +using System.Xml.Linq; +using Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.Formats; +using Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.Formats.CIM.Xml; namespace Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.RSM012; -public class MeteredDateForMeasurementPointCimXmlDocumentWriter : IDocumentWriter +public class MeteredDateForMeasurementPointCimXmlDocumentWriter( + IMessageRecordParser parser) + : CimXmlDocumentWriter( + new DocumentDetails( + "NotifyValidatedMeasureData_MarketDocument", + "urn:ediel.org:measure:notifyvalidatedmeasuredata:0:1 urn-ediel-org-measure-notifyvalidatedmeasuredata-0-1.xsd", + "urn:ediel.org:measure:notifyvalidatedmeasuredata:0:1", + "cim", + "E66"), + parser) { - public bool HandlesFormat(DocumentFormat format) + protected override async Task WriteMarketActivityRecordsAsync( + IReadOnlyCollection marketActivityPayloads, + XmlWriter writer) { - return format == DocumentFormat.Xml; - } + ArgumentNullException.ThrowIfNull(marketActivityPayloads); + ArgumentNullException.ThrowIfNull(writer); + XNamespace @namespace = "urn:ediel.org:measure:notifyvalidatedmeasuredata:0:1"; + foreach (var activityRecord in ParseFrom(marketActivityPayloads)) + { + var seriesElement = new XElement( + @namespace + "Series", + new XElement(@namespace + "mRID", activityRecord.TransactionId), + new XElement( + @namespace + "originalTransactionIDReference_Series.mRID", + activityRecord.OriginalTransactionIdReferenceId), + new XElement( + @namespace + "marketEvaluationPoint.mRID", + new XAttribute("codingScheme", "A10"), + activityRecord.MarketEvaluationPointNumber), + new XElement(@namespace + "marketEvaluationPoint.type", activityRecord.MarketEvaluationPointType), + new XElement(@namespace + "registration_DateAndOrTime.dateTime", activityRecord.RegistrationDateTime), + new XElement(@namespace + "product", activityRecord.Product), + new XElement(@namespace + "quantity_Measure_Unit.name", activityRecord.QuantityMeasureUnit), + new XElement( + @namespace + "Period", + new XElement(@namespace + "resolution", activityRecord.Resolution), + new XElement( + @namespace + "timeInterval", + new XElement(@namespace + "start", activityRecord.StartedDateTime), + new XElement(@namespace + "end", activityRecord.EndedDateTime)), + activityRecord.EnergyObservations.Select(x => CreatePointElement(x, @namespace)))); - public bool HandlesType(DocumentType documentType) - { - return documentType == DocumentType.MeteredDataForMeasurementPoint; + await seriesElement.WriteToAsync(writer, CancellationToken.None).ConfigureAwait(false); + } } - public Task WriteAsync( - OutgoingMessageHeader header, - IReadOnlyCollection marketActivityRecords, - CancellationToken cancellationToken) + private XElement CreatePointElement(PointActivityRecord point, XNamespace @namespace) { - throw new NotImplementedException(); + var pointElement = new XElement( + @namespace + "Point", + new XElement(@namespace + "position", point.Position.ToString(NumberFormatInfo.InvariantInfo))); + + if (point.Quantity != null) + { + pointElement.Add(new XElement(@namespace + "quantity", point.Quantity?.ToString(NumberFormatInfo.InvariantInfo))); + } + + if (point.Quality != null) + { + pointElement.Add(new XElement(@namespace + "quality", point.Quality?.ToString(NumberFormatInfo.InvariantInfo))); + } + + return pointElement; } } diff --git a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointMarketActivityRecord.cs b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointMarketActivityRecord.cs index a3e0012d89..748b28c655 100644 --- a/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointMarketActivityRecord.cs +++ b/source/OutgoingMessages.Domain/DocumentWriters/RSM012/MeteredDateForMeasurementPointMarketActivityRecord.cs @@ -16,7 +16,7 @@ namespace Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.RSM012; -public record MeteredDateForMeasurementPointMarketActivityRecord( +public sealed record MeteredDateForMeasurementPointMarketActivityRecord( string TransactionId, string MarketEvaluationPointNumber, string MarketEvaluationPointType, @@ -29,4 +29,4 @@ public record MeteredDateForMeasurementPointMarketActivityRecord( string EndedDateTime, IReadOnlyList EnergyObservations); -public record PointActivityRecord(int Position, string? Quality, decimal? Quantity); +public sealed record PointActivityRecord(int Position, string? Quality, decimal? Quantity); diff --git a/source/OutgoingMessages.IntegrationTests/OutgoingMessages/DocumentFactory/DocumentFactoryTests.cs b/source/OutgoingMessages.IntegrationTests/OutgoingMessages/DocumentFactory/DocumentFactoryTests.cs index ceddbf08ea..412766d811 100644 --- a/source/OutgoingMessages.IntegrationTests/OutgoingMessages/DocumentFactory/DocumentFactoryTests.cs +++ b/source/OutgoingMessages.IntegrationTests/OutgoingMessages/DocumentFactory/DocumentFactoryTests.cs @@ -64,7 +64,7 @@ public void Ensure_that_all_document_support_ebix(DocumentType documentType) var writer = _documentWriters.FirstOrDefault(writer => writer.HandlesType(documentType) && writer.HandlesFormat(DocumentFormat.Ebix)); - if (documentType == DocumentType.MeteredDataForMeasurementPoint) + if (documentType == DocumentType.NotifyValidatedMeasureData) { writer.Should().BeNull($"{documentType} does not support ebix"); } diff --git a/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs b/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs index 700c927c57..97827a51ce 100644 --- a/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs +++ b/source/OutgoingMessages.Interfaces/Models/MeteredDataForMeasurementPoint/MeteredDataForMeasurementPointMessageProcessDto.cs @@ -22,7 +22,7 @@ public sealed class MeteredDataForMeasurementPointMessageProcessDto( BusinessReason businessReason, MeteredDataForMeasurementPointMessageSeriesDto series) : OutgoingMessageDto( - DocumentType.MeteredDataForMeasurementPoint, + DocumentType.NotifyValidatedMeasureData, receiver.ActorNumber, null, eventId, diff --git a/source/Tests/Application/OutgoingMessages/MetricNameGenerationTests.cs b/source/Tests/Application/OutgoingMessages/MetricNameGenerationTests.cs index 671c649045..b637ccf812 100644 --- a/source/Tests/Application/OutgoingMessages/MetricNameGenerationTests.cs +++ b/source/Tests/Application/OutgoingMessages/MetricNameGenerationTests.cs @@ -21,7 +21,22 @@ namespace Energinet.DataHub.EDI.Tests.Application.OutgoingMessages; public class MetricNameGenerationTests { - // The following values has to be hardcoded, since they are hardcoded in the terraform defining the dashboard + // The following values have to be hardcoded, since they are hardcoded in the terraform defining the dashboard. + // When a new document type is introduced, the following needs to be inserted into to the terraform script: + // { + // "resourceMetadata": { + // "id": "${appi_sharedres_id}" + // }, + // "name": "MeteredDataForMeasurementPoint{format}", + // "aggregationType": 7, + // "namespace": "azure.applicationinsights", + // "metricVisualization": { + // "displayName": "MeteredDataForMeasurementPoint{format}" + // } + // } + // replace {format} with the supported formats for the new document type. + // and include this link to the file: https://github.com/Energinet-DataHub/dh3-infrastructure/blob/main/edi/terraform/main/dashboard-templates/edi_monitor.tpl + // Look for RejectRequestWholesaleSettlement in the script for an example. private static readonly string[] _formats = ["Json", "Xml", "Ebix" ]; private static readonly string[] _documentMetrics = [ @@ -31,7 +46,14 @@ public class MetricNameGenerationTests "NotifyWholesaleServices", "NotifyWholesaleServicesResponse", "RejectRequestWholesaleSettlement", - "MeteredDataForMeasurementPoint", + "NotifyValidatedMeasureData", + "NotifyValidatedMeasureDataResponse", + ]; + + private static readonly DocumentType[] _isOnlyTriggeredByIncomingMessage = + [ + DocumentType.RejectRequestWholesaleSettlement, + DocumentType.RejectRequestAggregatedMeasureData ]; private readonly string[] _loggedMessageGenerationMetric = _formats.Select( @@ -63,13 +85,15 @@ private static List AllMessageGenerationsMetricsNames() { foreach (var documentType in documentTypes) { + // Most documents are logged as an outgoing message and as a response to a corresponding incoming message names.Add(MetricNameMapper.MessageGenerationMetricName( documentType, documentFormat, false)); - if (documentType.Name.Contains("Notify")) + + // Some documents are only logged as an outgoing message + if (!_isOnlyTriggeredByIncomingMessage.Contains(documentType)) { - // We're logging a response of a request as a separate message generation, even though it's the same document names.Add(MetricNameMapper.MessageGenerationMetricName( documentType, documentFormat, diff --git a/source/Tests/B2CWebApi/Mappers/DocumentTypeMapperTests.cs b/source/Tests/B2CWebApi/Mappers/DocumentTypeMapperTests.cs index f0f049a525..05bfbadc27 100644 --- a/source/Tests/B2CWebApi/Mappers/DocumentTypeMapperTests.cs +++ b/source/Tests/B2CWebApi/Mappers/DocumentTypeMapperTests.cs @@ -67,7 +67,7 @@ public void Ensure_all_DocumentTypes_are_supported() // TODO - Remove this line when all DocumentTypes are supported in B2C supportedDocumentTypes = supportedDocumentTypes - .Where(x => x != IncomingDocumentType.MeteredDataForMeasurementPoint.Name); + .Where(x => x != IncomingDocumentType.NotifyValidatedMeasureData.Name); // Act & Assert documentTypes.Should().BeEquivalentTo(supportedDocumentTypes.ToList()); diff --git a/source/Tests/Domain/OutgoingMessages/Queueing/OutgoingMessageTests.cs b/source/Tests/Domain/OutgoingMessages/Queueing/OutgoingMessageTests.cs index 605d2f364b..5a607f7e45 100644 --- a/source/Tests/Domain/OutgoingMessages/Queueing/OutgoingMessageTests.cs +++ b/source/Tests/Domain/OutgoingMessages/Queueing/OutgoingMessageTests.cs @@ -55,7 +55,7 @@ public class OutgoingMessageTests new RejectRequestWholesaleSettlementCimXmlDocumentWriter(new MessageRecordParser(new Serializer())), new MeteredDateForMeasurementPointCimJsonDocumentWriter(new MessageRecordParser(new Serializer()), _serviceProvider.GetRequiredService()), - new MeteredDateForMeasurementPointCimXmlDocumentWriter(), + new MeteredDateForMeasurementPointCimXmlDocumentWriter(new MessageRecordParser(new Serializer())), ]; /// @@ -90,6 +90,7 @@ public async Task Ensure_we_can_write_all_enqueued_messages(DocumentType documen GetHeader(), new List { serializedContent }, CancellationToken.None); + // Assert await act.Should().NotThrowAsync(); } diff --git a/source/Tests/Infrastructure/OutgoingMessages/RSM012/AssertMeteredDateForMeasurementPointJsonDocument.cs b/source/Tests/Infrastructure/OutgoingMessages/RSM012/AssertMeteredDateForMeasurementPointJsonDocument.cs index 682a9711a7..cb57cd7cba 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/RSM012/AssertMeteredDateForMeasurementPointJsonDocument.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/RSM012/AssertMeteredDateForMeasurementPointJsonDocument.cs @@ -30,8 +30,9 @@ public class AssertMeteredDateForMeasurementPointJsonDocument : IAssertMeteredDa public AssertMeteredDateForMeasurementPointJsonDocument(Stream documentStream) { _document = JsonDocument.Parse(documentStream); - var temp = _document.RootElement.GetRawText(); _root = _document.RootElement.GetProperty("NotifyValidatedMeasureData_MarketDocument"); + + Assert.Equal("E66", _root.GetProperty("type").GetProperty("value").ToString()); } public IAssertMeteredDateForMeasurementPointDocumentDocument HasMessageId(string expectedMessageId) diff --git a/source/Tests/Infrastructure/OutgoingMessages/RSM012/AssertMeteredDateForMeasurementPointXmlDocument.cs b/source/Tests/Infrastructure/OutgoingMessages/RSM012/AssertMeteredDateForMeasurementPointXmlDocument.cs new file mode 100644 index 0000000000..eb2f320a97 --- /dev/null +++ b/source/Tests/Infrastructure/OutgoingMessages/RSM012/AssertMeteredDateForMeasurementPointXmlDocument.cs @@ -0,0 +1,186 @@ +// 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 Energinet.DataHub.EDI.BuildingBlocks.Domain.Models; +using Energinet.DataHub.EDI.OutgoingMessages.Domain.DocumentWriters.RSM012; +using Energinet.DataHub.EDI.Tests.Infrastructure.OutgoingMessages.Asserts; +using FluentAssertions; + +namespace Energinet.DataHub.EDI.Tests.Infrastructure.OutgoingMessages.RSM012; + +public class AssertMeteredDateForMeasurementPointXmlDocument : IAssertMeteredDateForMeasurementPointDocumentDocument +{ + private readonly AssertXmlDocument _documentAsserter; + + public AssertMeteredDateForMeasurementPointXmlDocument(AssertXmlDocument documentAsserter) + { + _documentAsserter = documentAsserter; + _documentAsserter.HasValue("type", "E66"); + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasMessageId(string expectedMessageId) + { + _documentAsserter.ElementExists("mRID"); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasBusinessReason(string expectedBusinessReasonCode) + { + _documentAsserter.HasValue("process.processType", expectedBusinessReasonCode); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasSenderId(string expectedSenderId, string expectedSchemeCode) + { + _documentAsserter.HasValue("sender_MarketParticipant.mRID", expectedSenderId); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasSenderRole(string expectedSenderRole) + { + _documentAsserter.HasValue("sender_MarketParticipant.marketRole.type", expectedSenderRole); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasReceiverId( + string expectedReceiverId, + string expectedSchemeCode) + { + _documentAsserter.HasValue("receiver_MarketParticipant.mRID", expectedReceiverId); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasReceiverRole(string expectedReceiverRole) + { + _documentAsserter.HasValue("receiver_MarketParticipant.marketRole.type", expectedReceiverRole); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasTimestamp(string expectedTimestamp) + { + _documentAsserter.HasValue("createdDateTime", expectedTimestamp); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasTransactionId(TransactionId expectedTransactionId) + { + _documentAsserter.HasValue("Series[1]/mRID", expectedTransactionId.Value); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasMeteringPointNumber( + string expectedMeteringPointNumber, + string expectedSchemeCode) + { + _documentAsserter.HasValue("Series[1]/marketEvaluationPoint.mRID", expectedMeteringPointNumber); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasMeteringPointType(string expectedMeteringPointType) + { + _documentAsserter.HasValue("Series[1]/marketEvaluationPoint.type", expectedMeteringPointType); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasOriginalTransactionIdReferenceId( + string? expectedOriginalTransactionIdReferenceId) + { + if (expectedOriginalTransactionIdReferenceId == null) + { + _documentAsserter.IsNotPresent("Series[1]/originalTransactionIDReference_Series.mRID"); + } + else + { + _documentAsserter.HasValue( + "Series[1]/originalTransactionIDReference_Series.mRID", + expectedOriginalTransactionIdReferenceId); + } + + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasProduct(string expectedProduct) + { + _documentAsserter.HasValue("Series[1]/product", expectedProduct); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasQuantityMeasureUnit(string expectedQuantityMeasureUnit) + { + _documentAsserter.HasValue("Series[1]/quantity_Measure_Unit.name", expectedQuantityMeasureUnit); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasRegistrationDateTime(string expectedRegistrationDateTime) + { + _documentAsserter.HasValue("Series[1]/registration_DateAndOrTime.dateTime", expectedRegistrationDateTime); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasResolution(string expectedResolution) + { + _documentAsserter.HasValue("Series[1]/Period/resolution", expectedResolution); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasStartedDateTime(string expectedStartedDateTime) + { + _documentAsserter + .HasValue("Series[1]/Period/timeInterval/start", expectedStartedDateTime); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasEndedDateTime(string expectedEndedDateTime) + { + _documentAsserter + .HasValue("Series[1]/Period/timeInterval/end", expectedEndedDateTime); + return this; + } + + public IAssertMeteredDateForMeasurementPointDocumentDocument HasPoints(IReadOnlyList expectedPoints) + { + var pointsInDocument = _documentAsserter + .GetElements("Series[1]/Period/Point")!; + + pointsInDocument.Should().HaveSameCount(expectedPoints); + + for (var i = 0; i < expectedPoints.Count; i++) + { + var expectedPoint = expectedPoints[i]; + + _documentAsserter + .HasValue($"Series[1]/Period/Point[{i + 1}]/position", expectedPoint.Position.ToString()); + + if (expectedPoint.Quantity != null) + { + _documentAsserter + .HasValue($"Series[1]/Period/Point[{i + 1}]/quantity", expectedPoint.Quantity!.ToString()!); + } + + if (expectedPoint.Quality != null) + { + _documentAsserter + .HasValue($"Series[1]/Period/Point[{i + 1}]/quality", expectedPoint.Quality); + } + } + + return this; + } + + public async Task DocumentIsValidAsync() + { + await _documentAsserter.HasValidStructureAsync(DocumentType.NotifyValidatedMeasureData).ConfigureAwait(false); + return this; + } +} diff --git a/source/Tests/Infrastructure/OutgoingMessages/RSM012/MeteredDateForMeasurementPointDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/RSM012/MeteredDateForMeasurementPointDocumentWriterTests.cs index a4659a7e85..5bf10f110b 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/RSM012/MeteredDateForMeasurementPointDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/RSM012/MeteredDateForMeasurementPointDocumentWriterTests.cs @@ -22,20 +22,22 @@ using Energinet.DataHub.EDI.OutgoingMessages.Domain.Models.OutgoingMessages; using Energinet.DataHub.EDI.Tests.Factories; using Energinet.DataHub.EDI.Tests.Fixtures; +using Energinet.DataHub.EDI.Tests.Infrastructure.OutgoingMessages.Asserts; using FluentAssertions.Execution; using Microsoft.Extensions.DependencyInjection; using Xunit; namespace Energinet.DataHub.EDI.Tests.Infrastructure.OutgoingMessages.RSM012; -public class MeteredDateForMeasurementPointDocumentWriterTests() +public class MeteredDateForMeasurementPointDocumentWriterTests(DocumentValidationFixture documentValidation) : IClassFixture { private readonly MessageRecordParser _parser = new(new Serializer()); private readonly MeteredDateForMeasurementPointBuilder _meteredDateForMeasurementPointBuilder = new(); + private readonly DocumentValidationFixture _documentValidation = documentValidation; [Theory] - //[InlineData(nameof(DocumentFormat.Xml))] + [InlineData(nameof(DocumentFormat.Xml))] [InlineData(nameof(DocumentFormat.Json))] public async Task Can_create_notifyWholesaleServices_document(string documentFormat) { @@ -79,10 +81,10 @@ private Task WriteDocument( { var records = _parser.From(meteredDateForMeasurementPointMarketActivityRecord); - // if (documentFormat == DocumentFormat.Xml) - // { - // return new MeteredDateForMeasurementPointCimXmlDocumentWriter(_parser).WriteAsync(header, new[] { records }); - // } + if (documentFormat == DocumentFormat.Xml) + { + return new MeteredDateForMeasurementPointCimXmlDocumentWriter(_parser).WriteAsync(header, new[] { records }); + } var serviceProvider = new ServiceCollection().AddJavaScriptEncoder().BuildServiceProvider(); return new MeteredDateForMeasurementPointCimJsonDocumentWriter( @@ -95,10 +97,12 @@ private IAssertMeteredDateForMeasurementPointDocumentDocument AssertDocument( MarketDocumentStream document, DocumentFormat documentFormat) { - // if (documentFormat == DocumentFormat.Xml) - // { - // return new AssertMeteredDateForMeasurementPointXmlDocument(document.Stream); - // } + if (documentFormat == DocumentFormat.Xml) + { + var assertXmlDocument = AssertXmlDocument.Document(document.Stream, "cim", _documentValidation.Validator); + return new AssertMeteredDateForMeasurementPointXmlDocument(assertXmlDocument); + } + return new AssertMeteredDateForMeasurementPointJsonDocument(document.Stream); } }