From 3d22e57b276b755fa1496fbca006ed8716e22417 Mon Sep 17 00:00:00 2001 From: Chris Brohus Date: Wed, 8 Mar 2023 14:23:49 +0100 Subject: [PATCH 01/25] Refactor --- .../functionapphost.settings.json | 16 ++++++++++ .../integrationtest.local.settings.json | 3 ++ .../RemoteBusinessService.cs | 6 ++-- .../JsonMessageParser.cs | 27 ++++++----------- .../Response/JsonResponseFactory.cs | 22 +++++++------- source/Infrastructure/Infrastructure.csproj | 1 - .../Common/Json/JsonHeaderWriter.cs | 30 +++++++++---------- ...onfirmChangeOfSupplierJsonMessageWriter.cs | 23 +++++++------- ...equestChangeOfSupplierJsonMessageWriter.cs | 26 ++++++++-------- 9 files changed, 80 insertions(+), 74 deletions(-) create mode 100644 source/AcceptanceTests/functionapphost.settings.json create mode 100644 source/AcceptanceTests/integrationtest.local.settings.json diff --git a/source/AcceptanceTests/functionapphost.settings.json b/source/AcceptanceTests/functionapphost.settings.json new file mode 100644 index 0000000000..e1a0829808 --- /dev/null +++ b/source/AcceptanceTests/functionapphost.settings.json @@ -0,0 +1,16 @@ +{ + // + // See class FunctionAppHostSettings for a description of settings in this file. + // + + // We previously used %ProgramFiles% but experienced problems as it sometimes resolved to "...\Program Files (x86)\" + "DotnetExecutablePath": "C:\\Program Files\\dotnet\\dotnet.exe", + + // We must ensure this tool is installed at the same location on all developer machines. + // Be sure to use 'nvm' to manage Node.js + npm and node modules. + "FunctionAppHostPath": "C:\\Program Files\\nodejs\\node_modules\\azure-functions-core-tools\\bin\\func.dll", + + "UseShellExecute": "false", + "Port": "7001", + "MaxWaitSeconds": "120" +} diff --git a/source/AcceptanceTests/integrationtest.local.settings.json b/source/AcceptanceTests/integrationtest.local.settings.json new file mode 100644 index 0000000000..29bbcf5193 --- /dev/null +++ b/source/AcceptanceTests/integrationtest.local.settings.json @@ -0,0 +1,3 @@ +{ + "AZURE_KEYVAULT_URL": "https://kv-integrationtest-u-002.vault.azure.net/" +} \ No newline at end of file diff --git a/source/Infrastructure/Configuration/MessageBus/RemoteBusinessServices/RemoteBusinessService.cs b/source/Infrastructure/Configuration/MessageBus/RemoteBusinessServices/RemoteBusinessService.cs index 76144a5eee..32f31cd000 100644 --- a/source/Infrastructure/Configuration/MessageBus/RemoteBusinessServices/RemoteBusinessService.cs +++ b/source/Infrastructure/Configuration/MessageBus/RemoteBusinessServices/RemoteBusinessService.cs @@ -13,9 +13,9 @@ // limitations under the License. using System; +using System.Text.Json; using System.Threading.Tasks; using Azure.Messaging.ServiceBus; -using Newtonsoft.Json; namespace Infrastructure.Configuration.MessageBus.RemoteBusinessServices; @@ -35,13 +35,13 @@ public RemoteBusinessService(IRemoteBusinessServiceRequestSenderAdapter(_errors.ToArray()); } - var streamReader = new StreamReader(message, leaveOpen: true); try { - using (var jsonTextReader = new JsonTextReader(streamReader)) + using (var jsonTextReader = new Utf8JsonReader(message)) { try { @@ -100,7 +96,6 @@ public async Task(message, options); + if (deserialized is null) throw new InvalidOperationException("Unable to read first node"); + var path = deserialized.First().Value?.ToString(); + split = path.Split('_'); return split; } @@ -130,11 +122,10 @@ private static string GetBusinessProcessType(Stream message) return processType; } - private static MessageParserResult ParseJsonData(JsonTextReader jsonTextReader) + private static MessageParserResult ParseJsonData(Utf8JsonReader jsonTextReader) { var marketActivityRecords = new List(); - var serializer = new JsonSerializer(); - var jsonRequest = serializer.Deserialize(jsonTextReader); + var jsonRequest = JsonSerializer.Deserialize(jsonTextReader, JsonObject, new JsonSerializerOptions()); var headerToken = jsonRequest.SelectToken(HeaderElementName); var messageHeader = MessageHeaderFrom(headerToken); marketActivityRecords.AddRange(headerToken[MarketActivityRecordElementName].Select(MarketActivityRecordFrom)); diff --git a/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs b/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs index 205fbdd807..cabbd3b21e 100644 --- a/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs +++ b/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs @@ -16,10 +16,10 @@ using System.IO; using System.Linq; using System.Text; +using System.Text.Json; using CimMessageAdapter.Messages; using CimMessageAdapter.Response; using Domain.OutgoingMessages; -using Newtonsoft.Json; namespace Infrastructure.IncomingMessages.Response; @@ -36,18 +36,17 @@ public ResponseMessage From(Result result) private static string CreateMessageBodyFrom(Result result) { if (result == null) throw new ArgumentNullException(nameof(result)); - var messageBody = new StringBuilder(); - var stringWriter = new StringWriter(messageBody); - - using var writer = new JsonTextWriter(stringWriter); + var messageBody = new MemoryStream(); + var options = new JsonWriterOptions() { Indented = true }; + using var writer = new Utf8JsonWriter(messageBody, options); writer.WriteStartObject(); writer.WritePropertyName("Error"); writer.WriteStartObject(); writer.WritePropertyName("Code"); - writer.WriteValue(result.Errors.Count == 1 ? result.Errors.First().Code : "BadRequest"); + writer.WriteStringValue(result.Errors.Count == 1 ? result.Errors.First().Code : "BadRequest"); writer.WritePropertyName("Message"); - writer.WriteValue(result.Errors.Count == 1 ? result.Errors.First().Message : "Multiple errors in message"); + writer.WriteStringValue(result.Errors.Count == 1 ? result.Errors.First().Message : "Multiple errors in message"); if (result.Errors.Count > 1) { @@ -59,20 +58,19 @@ private static string CreateMessageBodyFrom(Result result) { writer.WriteStartObject(); writer.WritePropertyName("Code"); - writer.WriteValue(validationError.Code); + writer.WriteStringValue(validationError.Code); writer.WritePropertyName("Message"); - writer.WriteValue(validationError.Message); + writer.WriteStringValue(validationError.Message); writer.WriteEndObject(); } - writer.WriteEnd(); + writer.WriteEndObject(); writer.WriteEndObject(); } writer.WriteEndObject(); writer.WriteEndObject(); - writer.Close(); - return messageBody.ToString(); + return Encoding.UTF8.GetString(messageBody.ToArray()); } } diff --git a/source/Infrastructure/Infrastructure.csproj b/source/Infrastructure/Infrastructure.csproj index d6c9f1d3c5..2467cf48eb 100644 --- a/source/Infrastructure/Infrastructure.csproj +++ b/source/Infrastructure/Infrastructure.csproj @@ -33,7 +33,6 @@ limitations under the License. - diff --git a/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs b/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs index 848b95cfe8..2f77c1bd35 100644 --- a/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs +++ b/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs @@ -13,79 +13,79 @@ // limitations under the License. using System; +using System.Text.Json; +using System.Xml; using Domain.OutgoingMessages; -using Newtonsoft.Json; namespace Infrastructure.OutgoingMessages.Common.Json; internal static class JsonHeaderWriter { - internal static void Write(MessageHeader messageHeader, string documentType, string typeCode, string? reasonCode, JsonTextWriter writer) + internal static void Write(MessageHeader messageHeader, string documentType, string typeCode, string? reasonCode, Utf8JsonWriter writer) { if (messageHeader == null) throw new ArgumentNullException(nameof(messageHeader)); if (documentType == null) throw new ArgumentNullException(nameof(documentType)); if (writer == null) throw new ArgumentNullException(nameof(writer)); - writer.Formatting = Formatting.Indented; writer.WriteStartObject(); writer.WritePropertyName(documentType); writer.WriteStartObject(); writer.WritePropertyName("mRID"); - writer.WriteValue(messageHeader.MessageId); + writer.WriteStringValue(messageHeader.MessageId); writer.WritePropertyName("businessSector.type"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue("23"); + writer.WriteStringValue("23"); writer.WriteEndObject(); writer.WritePropertyName("createdDateTime"); - writer.WriteValue(messageHeader.TimeStamp.ToString()); + writer.WriteStringValue(messageHeader.TimeStamp.ToString()); writer.WritePropertyName("process.processType"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.ProcessType); + writer.WriteStringValue(messageHeader.ProcessType); writer.WriteEndObject(); writer.WritePropertyName("reason.code"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(reasonCode); + writer.WriteStringValue(reasonCode); writer.WriteEndObject(); writer.WritePropertyName("receiver_MarketParticipant.mRID"); writer.WriteStartObject(); writer.WritePropertyName("codingScheme"); - writer.WriteValue("A10"); + writer.WriteStringValue("A10"); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.ReceiverId); + writer.WriteStringValue(messageHeader.ReceiverId); writer.WriteEndObject(); writer.WritePropertyName("receiver_MarketParticipant.marketRole.type"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.ReceiverRole); + writer.WriteStringValue(messageHeader.ReceiverRole); writer.WriteEndObject(); writer.WritePropertyName("sender_MarketParticipant.mRID"); writer.WriteStartObject(); writer.WritePropertyName("codingScheme"); - writer.WriteValue("A10"); + writer.WriteStringValue("A10"); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.SenderId); + writer.WriteStringValue(messageHeader.SenderId); writer.WriteEndObject(); writer.WritePropertyName("sender_MarketParticipant.marketRole.type"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.SenderRole); + writer.WriteStringValue(messageHeader.SenderRole); writer.WriteEndObject(); writer.WritePropertyName("type"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(typeCode); + writer.WriteStringValue(typeCode); writer.WriteEndObject(); } } diff --git a/source/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmChangeOfSupplierJsonMessageWriter.cs b/source/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmChangeOfSupplierJsonMessageWriter.cs index fca14adf1d..7efe8bf0d5 100644 --- a/source/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmChangeOfSupplierJsonMessageWriter.cs +++ b/source/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmChangeOfSupplierJsonMessageWriter.cs @@ -15,12 +15,12 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.Json; using System.Threading.Tasks; using Application.OutgoingMessages.Common; using Domain.OutgoingMessages; using Domain.OutgoingMessages.ConfirmRequestChangeOfSupplier; using Infrastructure.OutgoingMessages.Common.Json; -using Newtonsoft.Json; namespace Infrastructure.OutgoingMessages.ConfirmRequestChangeOfSupplier; @@ -49,29 +49,28 @@ public bool HandlesType(MessageType messageType) public async Task WriteAsync(MessageHeader header, IReadOnlyCollection marketActivityRecords) { var stream = new MemoryStream(); - var streamWriter = new StreamWriter(stream, leaveOpen: true); - using var writer = new JsonTextWriter(streamWriter); + var options = new JsonWriterOptions() { Indented = true }; + using var writer = new Utf8JsonWriter(stream, options); WriteHeader(header, writer); WriteMarketActivityRecords(marketActivityRecords, writer); WriteEnd(writer); - writer.Flush(); - await streamWriter.FlushAsync().ConfigureAwait(false); + await writer.FlushAsync().ConfigureAwait(false); stream.Position = 0; return stream; } - private static void WriteEnd(JsonTextWriter writer) + private static void WriteEnd(Utf8JsonWriter writer) { writer.WriteEndObject(); } - private static void WriteHeader(MessageHeader header, JsonTextWriter writer) + private static void WriteHeader(MessageHeader header, Utf8JsonWriter writer) { JsonHeaderWriter.Write(header, DocumentType, TypeCode, "A01", writer); } - private void WriteMarketActivityRecords(IReadOnlyCollection marketActivityRecords, JsonTextWriter writer) + private void WriteMarketActivityRecords(IReadOnlyCollection marketActivityRecords, Utf8JsonWriter writer) { if (marketActivityRecords == null) throw new ArgumentNullException(nameof(marketActivityRecords)); if (writer == null) throw new ArgumentNullException(nameof(writer)); @@ -83,16 +82,16 @@ private void WriteMarketActivityRecords(IReadOnlyCollection marketActivi { writer.WriteStartObject(); writer.WritePropertyName("mRID"); - writer.WriteValue(marketActivityRecord.Id); + writer.WriteStringValue(marketActivityRecord.Id); writer.WritePropertyName("marketEvaluationPoint.mRID"); writer.WriteStartObject(); writer.WritePropertyName("codingScheme"); - writer.WriteValue("A10"); + writer.WriteStringValue("A10"); writer.WritePropertyName("value"); - writer.WriteValue(marketActivityRecord.MarketEvaluationPointId); + writer.WriteStringValue(marketActivityRecord.MarketEvaluationPointId); writer.WriteEndObject(); writer.WritePropertyName("originalTransactionIDReference_MktActivityRecord.mRID"); - writer.WriteValue(marketActivityRecord.OriginalTransactionId); + writer.WriteStringValue(marketActivityRecord.OriginalTransactionId); writer.WriteEndObject(); } diff --git a/source/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierJsonMessageWriter.cs b/source/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierJsonMessageWriter.cs index 4903ca349b..468e9703f1 100644 --- a/source/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierJsonMessageWriter.cs +++ b/source/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierJsonMessageWriter.cs @@ -15,12 +15,12 @@ using System; using System.Collections.Generic; using System.IO; +using System.Text.Json; using System.Threading.Tasks; using Application.OutgoingMessages.Common; using Domain.OutgoingMessages; using Domain.OutgoingMessages.RejectRequestChangeOfSupplier; using Infrastructure.OutgoingMessages.Common.Json; -using Newtonsoft.Json; namespace Infrastructure.OutgoingMessages.RejectRequestChangeOfSupplier; @@ -49,28 +49,28 @@ public bool HandlesType(MessageType messageType) public async Task WriteAsync(MessageHeader header, IReadOnlyCollection marketActivityRecords) { var stream = new MemoryStream(); - var streamWriter = new StreamWriter(stream, leaveOpen: true); - using var writer = new JsonTextWriter(streamWriter); + var options = new JsonWriterOptions() { Indented = true }; + using var writer = new Utf8JsonWriter(stream, options); WriteHeader(header, writer); WriteMarketActitivyRecords(marketActivityRecords, writer); WriteEnd(writer); - await streamWriter.FlushAsync().ConfigureAwait(false); + await writer.FlushAsync().ConfigureAwait(false); stream.Position = 0; return stream; } - private static void WriteHeader(MessageHeader header, JsonTextWriter writer) + private static void WriteHeader(MessageHeader header, Utf8JsonWriter writer) { JsonHeaderWriter.Write(header, DocumentType, TypeCode, "A02", writer); } - private static void WriteEnd(JsonTextWriter writer) + private static void WriteEnd(Utf8JsonWriter writer) { writer.WriteEndObject(); } - private void WriteMarketActitivyRecords(IReadOnlyCollection marketActivityRecords, JsonTextWriter writer) + private void WriteMarketActitivyRecords(IReadOnlyCollection marketActivityRecords, Utf8JsonWriter writer) { if (marketActivityRecords == null) throw new ArgumentNullException(nameof(marketActivityRecords)); if (writer == null) throw new ArgumentNullException(nameof(writer)); @@ -82,18 +82,18 @@ private void WriteMarketActitivyRecords(IReadOnlyCollection marketActivi { writer.WriteStartObject(); writer.WritePropertyName("mRID"); - writer.WriteValue(marketActivityRecord.Id); + writer.WriteStringValue(marketActivityRecord.Id); writer.WritePropertyName("marketEvaluationPoint.mRID"); writer.WriteStartObject(); writer.WritePropertyName("codingScheme"); - writer.WriteValue("A10"); + writer.WriteStringValue("A10"); writer.WritePropertyName("value"); - writer.WriteValue(marketActivityRecord.MarketEvaluationPointId); + writer.WriteStringValue(marketActivityRecord.MarketEvaluationPointId); writer.WriteEndObject(); writer.WritePropertyName("originalTransactionIDReference_MktActivityRecord.mRID"); - writer.WriteValue(marketActivityRecord.OriginalTransactionId); + writer.WriteStringValue(marketActivityRecord.OriginalTransactionId); writer.WritePropertyName("Reason"); writer.WriteStartArray(); @@ -104,10 +104,10 @@ private void WriteMarketActitivyRecords(IReadOnlyCollection marketActivi writer.WritePropertyName("code"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(reason.Code); + writer.WriteStringValue(reason.Code); writer.WriteEndObject(); writer.WritePropertyName("text"); - writer.WriteValue(reason.Text); + writer.WriteStringValue(reason.Text); writer.WriteEndObject(); } From e1aab98edd3226ba4475fa31423e0150fd960221 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:06:36 +0100 Subject: [PATCH 02/25] Extract method --- ...ntingPointCharacteristicsDocumentWriterTests.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs index eab755a47d..ea1f5d4682 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs @@ -54,7 +54,7 @@ public AccountingPointCharacteristicsDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader(ProcessType.MoveIn.Name, "SenderId", MarketRole.MeteringPointAdministrator.Name, "ReceiverId", MarketRole.EnergySupplier.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); + var header = CreateHeader(); var marketActivityRecord = _sampleData.CreateMarketActivityRecord(); var marketActivityRecords = new List() { @@ -95,4 +95,16 @@ private async Task AssertConformsToSchema(Stream message) .ConfigureAwait(false); await AssertXmlMessage.AssertConformsToSchemaAsync(message, schema!).ConfigureAwait(false); } + + private MessageHeader CreateHeader(ProcessType? processType = null) + { + return new MessageHeader( + processType is null ? ProcessType.MoveIn.Name : processType.Name, + "SenderId", + MarketRole.MeteringPointAdministrator.Name, + "ReceiverId", + MarketRole.EnergySupplier.Name, + Guid.NewGuid().ToString(), + _systemDateTimeProvider.Now()); + } } From 6d74d6c22cead00c94df92714c6b4fa5743520f9 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:08:52 +0100 Subject: [PATCH 03/25] Introduce parameter --- .../AccountingPointCharacteristicsDocumentWriterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs index ea1f5d4682..3728c083d4 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs @@ -96,12 +96,12 @@ private async Task AssertConformsToSchema(Stream message) await AssertXmlMessage.AssertConformsToSchemaAsync(message, schema!).ConfigureAwait(false); } - private MessageHeader CreateHeader(ProcessType? processType = null) + private MessageHeader CreateHeader(ProcessType? processType = null, MarketRole? senderRole = null) { return new MessageHeader( processType is null ? ProcessType.MoveIn.Name : processType.Name, "SenderId", - MarketRole.MeteringPointAdministrator.Name, + senderRole is null ? MarketRole.MeteringPointAdministrator.Name : senderRole.Name, "ReceiverId", MarketRole.EnergySupplier.Name, Guid.NewGuid().ToString(), From 312747d14cb347de210848ab73537e66502c848b Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:09:59 +0100 Subject: [PATCH 04/25] Introduce parameter --- .../AccountingPointCharacteristicsDocumentWriterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs index 3728c083d4..ba4a3bc707 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs @@ -96,14 +96,14 @@ private async Task AssertConformsToSchema(Stream message) await AssertXmlMessage.AssertConformsToSchemaAsync(message, schema!).ConfigureAwait(false); } - private MessageHeader CreateHeader(ProcessType? processType = null, MarketRole? senderRole = null) + private MessageHeader CreateHeader(ProcessType? processType = null, MarketRole? senderRole = null, MarketRole? receiverRole = null) { return new MessageHeader( processType is null ? ProcessType.MoveIn.Name : processType.Name, "SenderId", senderRole is null ? MarketRole.MeteringPointAdministrator.Name : senderRole.Name, "ReceiverId", - MarketRole.EnergySupplier.Name, + receiverRole is null ? MarketRole.EnergySupplier.Name : receiverRole.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); } From 8842c6629c9356b3907b68076dfdd3574a6e89a9 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:10:53 +0100 Subject: [PATCH 05/25] Remove dependency --- ...PointCharacteristicsDocumentWriterTests.cs | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs index ba4a3bc707..7faacda708 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs @@ -29,6 +29,7 @@ using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.AccountingPointCharacteristics; using Infrastructure.OutgoingMessages.Common; +using NodaTime; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; using MarketActivityRecord = Domain.OutgoingMessages.AccountingPointCharacteristics.MarketActivityRecord; @@ -38,14 +39,12 @@ namespace Tests.Infrastructure.OutgoingMessages.AccountingPointCharacteristics; public class AccountingPointCharacteristicsDocumentWriterTests { private readonly AccountingPointCharacteristicsMessageWriter _messageWriter; - private readonly ISystemDateTimeProvider _systemDateTimeProvider; private readonly IMessageRecordParser _messageRecordParser; private readonly SampleData _sampleData; private ISchemaProvider? _schemaProvider; public AccountingPointCharacteristicsDocumentWriterTests() { - _systemDateTimeProvider = new SystemDateTimeProvider(); _messageRecordParser = new MessageRecordParser(new Serializer()); _messageWriter = new AccountingPointCharacteristicsMessageWriter(_messageRecordParser); _sampleData = new SampleData(); @@ -64,6 +63,18 @@ public async Task Document_is_valid() await AssertMessage(message, header, marketActivityRecords).ConfigureAwait(false); } + private static MessageHeader CreateHeader(ProcessType? processType = null, MarketRole? senderRole = null, MarketRole? receiverRole = null) + { + return new MessageHeader( + processType is null ? ProcessType.MoveIn.Name : processType.Name, + "SenderId", + senderRole is null ? MarketRole.MeteringPointAdministrator.Name : senderRole.Name, + "ReceiverId", + receiverRole is null ? MarketRole.EnergySupplier.Name : receiverRole.Name, + Guid.NewGuid().ToString(), + SystemClock.Instance.GetCurrentInstant()); + } + private static void AssertMarketActivityRecords(List marketActivityRecords, XDocument document) { AssertXmlMessage.AssertMarketActivityRecordCount(document, 1); @@ -95,16 +106,4 @@ private async Task AssertConformsToSchema(Stream message) .ConfigureAwait(false); await AssertXmlMessage.AssertConformsToSchemaAsync(message, schema!).ConfigureAwait(false); } - - private MessageHeader CreateHeader(ProcessType? processType = null, MarketRole? senderRole = null, MarketRole? receiverRole = null) - { - return new MessageHeader( - processType is null ? ProcessType.MoveIn.Name : processType.Name, - "SenderId", - senderRole is null ? MarketRole.MeteringPointAdministrator.Name : senderRole.Name, - "ReceiverId", - receiverRole is null ? MarketRole.EnergySupplier.Name : receiverRole.Name, - Guid.NewGuid().ToString(), - _systemDateTimeProvider.Now()); - } } From f8b93819d9243951834bf8b39c03b50e9489d9d2 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:13:49 +0100 Subject: [PATCH 06/25] Extract factory --- .../Tests/Factories/MessageHeaderFactory.cs | 35 +++++++++++++++++++ ...PointCharacteristicsDocumentWriterTests.cs | 10 ++---- 2 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 source/Tests/Factories/MessageHeaderFactory.cs diff --git a/source/Tests/Factories/MessageHeaderFactory.cs b/source/Tests/Factories/MessageHeaderFactory.cs new file mode 100644 index 0000000000..19f89fa692 --- /dev/null +++ b/source/Tests/Factories/MessageHeaderFactory.cs @@ -0,0 +1,35 @@ +// 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 Domain.Actors; +using Domain.OutgoingMessages; +using NodaTime; + +namespace Tests.Factories; + +public static class MessageHeaderFactory +{ + public static MessageHeader Create(ProcessType? processType = null, MarketRole? senderRole = null, MarketRole? receiverRole = null) + { + return new MessageHeader( + processType is null ? ProcessType.MoveIn.Name : processType.Name, + "SenderId", + senderRole is null ? MarketRole.MeteringPointAdministrator.Name : senderRole.Name, + "ReceiverId", + receiverRole is null ? MarketRole.EnergySupplier.Name : receiverRole.Name, + Guid.NewGuid().ToString(), + SystemClock.Instance.GetCurrentInstant()); + } +} diff --git a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs index 7faacda708..40198d51ac 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs @@ -30,6 +30,7 @@ using Infrastructure.OutgoingMessages.AccountingPointCharacteristics; using Infrastructure.OutgoingMessages.Common; using NodaTime; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; using MarketActivityRecord = Domain.OutgoingMessages.AccountingPointCharacteristics.MarketActivityRecord; @@ -65,14 +66,7 @@ public async Task Document_is_valid() private static MessageHeader CreateHeader(ProcessType? processType = null, MarketRole? senderRole = null, MarketRole? receiverRole = null) { - return new MessageHeader( - processType is null ? ProcessType.MoveIn.Name : processType.Name, - "SenderId", - senderRole is null ? MarketRole.MeteringPointAdministrator.Name : senderRole.Name, - "ReceiverId", - receiverRole is null ? MarketRole.EnergySupplier.Name : receiverRole.Name, - Guid.NewGuid().ToString(), - SystemClock.Instance.GetCurrentInstant()); + return MessageHeaderFactory.Create(processType, senderRole, receiverRole); } private static void AssertMarketActivityRecords(List marketActivityRecords, XDocument document) From 344189368ce50aed84deb7a41e1d9472f50a2e46 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:14:58 +0100 Subject: [PATCH 07/25] Use factory directly --- .../AccountingPointCharacteristicsDocumentWriterTests.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs index 40198d51ac..1483a6820a 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs @@ -54,7 +54,7 @@ public AccountingPointCharacteristicsDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = CreateHeader(); + var header = MessageHeaderFactory.Create(); var marketActivityRecord = _sampleData.CreateMarketActivityRecord(); var marketActivityRecords = new List() { @@ -64,11 +64,6 @@ public async Task Document_is_valid() await AssertMessage(message, header, marketActivityRecords).ConfigureAwait(false); } - private static MessageHeader CreateHeader(ProcessType? processType = null, MarketRole? senderRole = null, MarketRole? receiverRole = null) - { - return MessageHeaderFactory.Create(processType, senderRole, receiverRole); - } - private static void AssertMarketActivityRecords(List marketActivityRecords, XDocument document) { AssertXmlMessage.AssertMarketActivityRecordCount(document, 1); From 48bbead720b56cb7be1054aeabb05c36edac09df Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:15:13 +0100 Subject: [PATCH 08/25] Clean up --- .../AccountingPointCharacteristicsDocumentWriterTests.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs index 1483a6820a..31d0bfda4c 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/AccountingPointCharacteristics/AccountingPointCharacteristicsDocumentWriterTests.cs @@ -12,24 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; using System.Xml.Linq; using System.Xml.Schema; -using Application.Configuration; using Application.OutgoingMessages.Common; using DocumentValidation; using DocumentValidation.CimXml; -using Domain.Actors; using Domain.OutgoingMessages; -using Infrastructure.Configuration; using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.AccountingPointCharacteristics; using Infrastructure.OutgoingMessages.Common; -using NodaTime; using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; From 5f3675411ab4d71211c3067cb6fe3f0ea39d5324 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:19:35 +0100 Subject: [PATCH 09/25] Use factory --- source/Tests/Factories/MessageHeaderFactory.cs | 2 +- ...isticsOfACustomerAtAnApDocumentWriterTests.cs | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/source/Tests/Factories/MessageHeaderFactory.cs b/source/Tests/Factories/MessageHeaderFactory.cs index 19f89fa692..02a11e1d2a 100644 --- a/source/Tests/Factories/MessageHeaderFactory.cs +++ b/source/Tests/Factories/MessageHeaderFactory.cs @@ -21,7 +21,7 @@ namespace Tests.Factories; public static class MessageHeaderFactory { - public static MessageHeader Create(ProcessType? processType = null, MarketRole? senderRole = null, MarketRole? receiverRole = null) + public static MessageHeader Create(ProcessType? processType = null, MarketRole? receiverRole = null, MarketRole? senderRole = null) { return new MessageHeader( processType is null ? ProcessType.MoveIn.Name : processType.Name, diff --git a/source/Tests/Infrastructure/OutgoingMessages/CharacteristicsOfACustomerAtAnAP/CharacteristicsOfACustomerAtAnApDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/CharacteristicsOfACustomerAtAnAP/CharacteristicsOfACustomerAtAnApDocumentWriterTests.cs index 93477deb7e..12714ad782 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/CharacteristicsOfACustomerAtAnAP/CharacteristicsOfACustomerAtAnApDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/CharacteristicsOfACustomerAtAnAP/CharacteristicsOfACustomerAtAnApDocumentWriterTests.cs @@ -30,6 +30,7 @@ using Infrastructure.OutgoingMessages.CharacteristicsOfACustomerAtAnAp; using Infrastructure.OutgoingMessages.Common; using NodaTime; +using Tests.Factories; using Tests.Fixtures; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; @@ -61,7 +62,7 @@ public async Task Document_is_valid() CreateMarketActivityRecord(null, null, _systemDateTimeProvider.Now()), }; - var header = CreateHeader(MarketRole.EnergySupplier); + var header = MessageHeaderFactory.Create(ProcessType.MoveIn); var message = await WriteDocumentAsync(header, marketActivityRecords.ToArray()).ConfigureAwait(false); var assertDocument = await AssertXmlDocument @@ -81,7 +82,7 @@ public async Task Document_is_valid() [Fact] public async Task Eletrical_heating_date_is_excluded_when_no_date_is_specified() { - var document = await WriteDocumentAsync(CreateHeader(MarketRole.GridOperator), CreateMarketActivityRecord(null, null, null)).ConfigureAwait(false); + var document = await WriteDocumentAsync(MessageHeaderFactory.Create(ProcessType.MoveIn, MarketRole.GridOperator), CreateMarketActivityRecord(null, null, null)).ConfigureAwait(false); AssertXmlDocument.Document(document, NamespacePrefix) .IsNotPresent("MktActivityRecord[1]/MarketEvaluationPoint/eletricalHeating_DateAndOrTime.dateTime"); @@ -90,7 +91,7 @@ public async Task Eletrical_heating_date_is_excluded_when_no_date_is_specified() [Fact] public async Task Second_customer_id_is_not_allowed_when_receiver_is_a_grid_operator() { - var message = await WriteDocumentAsync(CreateHeader(MarketRole.GridOperator), CreateMarketActivityRecord()) + var message = await WriteDocumentAsync(MessageHeaderFactory.Create(ProcessType.MoveIn, MarketRole.GridOperator), CreateMarketActivityRecord()) .ConfigureAwait(false); AssertXmlDocument @@ -101,7 +102,7 @@ public async Task Second_customer_id_is_not_allowed_when_receiver_is_a_grid_oper [Fact] public async Task Supply_start_is_not_allowed_when_receiver_is_a_grid_operator() { - var message = await WriteDocumentAsync(CreateHeader(MarketRole.GridOperator), CreateMarketActivityRecord()).ConfigureAwait(false); + var message = await WriteDocumentAsync(MessageHeaderFactory.Create(ProcessType.MoveIn, MarketRole.GridOperator), CreateMarketActivityRecord()).ConfigureAwait(false); AssertXmlDocument .Document(message, NamespacePrefix) @@ -112,7 +113,7 @@ public async Task Supply_start_is_not_allowed_when_receiver_is_a_grid_operator() public async Task Customer_mrid_is_not_allowed_when_type_is_social_security_number() { var document = - await WriteDocumentAsync(CreateHeader(MarketRole.EnergySupplier), CreateMarketActivityRecord(new MrId("1", "AAR"), new MrId("1", "AAR"))) + await WriteDocumentAsync(MessageHeaderFactory.Create(ProcessType.MoveIn, MarketRole.EnergySupplier), CreateMarketActivityRecord(new MrId("1", "AAR"), new MrId("1", "AAR"))) .ConfigureAwait(false); AssertXmlDocument.Document(document, NamespacePrefix) @@ -194,11 +195,6 @@ private MarketActivityRecord CreateMarketActivityRecord(MrId? firstCustomerId = })); } - private MessageHeader CreateHeader(MarketRole messageReceiverRole) - { - return new MessageHeader(ProcessType.MoveIn.Name, "SenderId", MarketRole.MeteringPointAdministrator.Name, "ReceiverId", messageReceiverRole.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); - } - private Task WriteDocumentAsync(MessageHeader header, params MarketActivityRecord[] marketActivityRecords) { return _messageWriter.WriteAsync(header, marketActivityRecords.Select(record => _messageRecordParser.From(record)).ToList()); From ecef2dcf6af3bc6476b361910b66081f50f580f2 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:20:18 +0100 Subject: [PATCH 10/25] Use factory --- ...tChangeAccountingPointCharacteristicsDocumentWriterTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs index 6b3ca07ce4..038b94be66 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs @@ -29,6 +29,7 @@ using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.ConfirmRequestChangeAccountingPointCharacteristics; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; using MarketActivityRecord = Domain.OutgoingMessages.ConfirmRequestChangeAccountingPointCharacteristics.MarketActivityRecord; @@ -52,7 +53,7 @@ public ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader(ProcessType.MoveIn.Name, "SenderId", MarketRole.MeteringPointAdministrator.Name, "ReceiverId", MarketRole.EnergySupplier.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); + var header = MessageHeaderFactory.Create(); var marketActivityRecords = new List() { new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "FakeMarketEvaluationPointId"), From 3aa327f2394e113ea111c6ac5ac0bba99a16ffd8 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:20:51 +0100 Subject: [PATCH 11/25] Remove unused fields --- ...hangeAccountingPointCharacteristicsDocumentWriterTests.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs index 038b94be66..4401a69f33 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeAccountingPointCharacteristics/ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs @@ -19,13 +19,10 @@ using System.Threading.Tasks; using System.Xml.Linq; using System.Xml.Schema; -using Application.Configuration; using Application.OutgoingMessages.Common; using DocumentValidation; using DocumentValidation.CimXml; -using Domain.Actors; using Domain.OutgoingMessages; -using Infrastructure.Configuration; using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.ConfirmRequestChangeAccountingPointCharacteristics; @@ -39,13 +36,11 @@ namespace Tests.Infrastructure.OutgoingMessages.ConfirmRequestChangeAccountingPo public class ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests { private readonly ConfirmRequestChangeAccountingPointCharacteristicsMessageWriter _messageWriter; - private readonly ISystemDateTimeProvider _systemDateTimeProvider; private readonly IMessageRecordParser _messageRecordParser; private ISchemaProvider? _schemaProvider; public ConfirmRequestChangeAccountingPointCharacteristicsDocumentWriterTests() { - _systemDateTimeProvider = new SystemDateTimeProvider(); _messageRecordParser = new MessageRecordParser(new Serializer()); _messageWriter = new ConfirmRequestChangeAccountingPointCharacteristicsMessageWriter(_messageRecordParser); } From 5413c1441f0e7d4b453198f132ca6a334b438cdb Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:21:36 +0100 Subject: [PATCH 12/25] Use factory --- .../ConfirmRequestChangeOfSupplierDocumentWriterTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierDocumentWriterTests.cs index b5d94e8891..c5cd7f1f8e 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierDocumentWriterTests.cs @@ -30,6 +30,7 @@ using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.ConfirmRequestChangeOfSupplier; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; @@ -38,13 +39,11 @@ namespace Tests.Infrastructure.OutgoingMessages.ConfirmRequestChangeOfSupplier public class ConfirmRequestChangeOfSupplierDocumentWriterTests { private readonly ConfirmChangeOfSupplierXmlMessageWriter _xmlMessageWriter; - private readonly ISystemDateTimeProvider _systemDateTimeProvider; private readonly IMessageRecordParser _messageRecordParser; private ISchemaProvider? _schemaProvider; public ConfirmRequestChangeOfSupplierDocumentWriterTests() { - _systemDateTimeProvider = new SystemDateTimeProvider(); _messageRecordParser = new MessageRecordParser(new Serializer()); _xmlMessageWriter = new ConfirmChangeOfSupplierXmlMessageWriter(_messageRecordParser); } @@ -52,7 +51,7 @@ public ConfirmRequestChangeOfSupplierDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader(ProcessType.MoveIn.Name, "SenderId", MarketRole.MeteringPointAdministrator.Name, "ReceiverId", MarketRole.EnergySupplier.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); + var header = MessageHeaderFactory.Create(); var marketActivityRecords = new List() { new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "FakeMarketEvaluationPointId"), From 66a6bf4faeb99b00ad0933e8842db2810ddab0ab Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:56:58 +0100 Subject: [PATCH 13/25] Parse EDI code --- .../OutgoingMessages/Common/Json/JsonHeaderWriter.cs | 8 +++++--- .../OutgoingMessages/Asserts/AssertJsonMessage.cs | 9 ++++++--- ...firmRequestChangeOfSupplierJsonDocumentWriterTests.cs | 3 ++- .../JsonDocumentWriterTests.cs | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs b/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs index 848b95cfe8..5ff9922fb1 100644 --- a/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs +++ b/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs @@ -13,7 +13,9 @@ // limitations under the License. using System; +using Domain.Actors; using Domain.OutgoingMessages; +using Domain.SeedWork; using Newtonsoft.Json; namespace Infrastructure.OutgoingMessages.Common.Json; @@ -45,7 +47,7 @@ internal static void Write(MessageHeader messageHeader, string documentType, str writer.WritePropertyName("process.processType"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.ProcessType); + writer.WriteValue(CimCode.Of(ProcessType.From(messageHeader.ProcessType))); writer.WriteEndObject(); writer.WritePropertyName("reason.code"); @@ -65,7 +67,7 @@ internal static void Write(MessageHeader messageHeader, string documentType, str writer.WritePropertyName("receiver_MarketParticipant.marketRole.type"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.ReceiverRole); + writer.WriteValue(CimCode.Of(EnumerationType.FromName(messageHeader.ReceiverRole))); writer.WriteEndObject(); writer.WritePropertyName("sender_MarketParticipant.mRID"); @@ -79,7 +81,7 @@ internal static void Write(MessageHeader messageHeader, string documentType, str writer.WritePropertyName("sender_MarketParticipant.marketRole.type"); writer.WriteStartObject(); writer.WritePropertyName("value"); - writer.WriteValue(messageHeader.SenderRole); + writer.WriteValue(CimCode.Of(EnumerationType.FromName(messageHeader.SenderRole))); writer.WriteEndObject(); writer.WritePropertyName("type"); diff --git a/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs b/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs index cdb1b9ab20..0db82a9923 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs @@ -14,7 +14,10 @@ using System; using System.Text.Json; +using Domain.Actors; using Domain.OutgoingMessages; +using Domain.SeedWork; +using Infrastructure.OutgoingMessages.Common; using Json.Schema; using Xunit; @@ -42,12 +45,12 @@ public static void AssertHeader(MessageHeader header, JsonDocument document, str if (header == null) throw new ArgumentNullException(nameof(header)); var root = document.RootElement.GetProperty(documentType); Assert.Equal(header.MessageId, root.GetProperty("mRID").ToString()); - Assert.Equal(header.ProcessType, root.GetProperty("process.processType").GetProperty("value").ToString()); + Assert.Equal(CimCode.Of(ProcessType.From(header.ProcessType)), root.GetProperty("process.processType").GetProperty("value").ToString()); Assert.Equal("23", root.GetProperty("businessSector.type").GetProperty("value").ToString()); Assert.Equal(header.SenderId, root.GetProperty("sender_MarketParticipant.mRID").GetProperty("value").ToString()); - Assert.Equal(header.SenderRole, root.GetProperty("sender_MarketParticipant.marketRole.type").GetProperty("value").ToString()); + Assert.Equal(CimCode.Of(EnumerationType.FromName(header.SenderRole)), root.GetProperty("sender_MarketParticipant.marketRole.type").GetProperty("value").ToString()); Assert.Equal(header.ReceiverId, root.GetProperty("receiver_MarketParticipant.mRID").GetProperty("value").ToString()); - Assert.Equal(header.ReceiverRole, root.GetProperty("receiver_MarketParticipant.marketRole.type").GetProperty("value").ToString()); + Assert.Equal(CimCode.Of(EnumerationType.FromName(header.ReceiverRole)), root.GetProperty("receiver_MarketParticipant.marketRole.type").GetProperty("value").ToString()); } public static void HasReasonCode(JsonDocument document, string documentType, string expectedReasonCode) diff --git a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierJsonDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierJsonDocumentWriterTests.cs index 9b5ad50d6d..1dc1c1d594 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierJsonDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/ConfirmRequestChangeOfSupplier/ConfirmRequestChangeOfSupplierJsonDocumentWriterTests.cs @@ -28,6 +28,7 @@ using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.ConfirmRequestChangeOfSupplier; using Json.Schema; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; @@ -52,7 +53,7 @@ public ConfirmRequestChangeOfSupplierJsonDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader("E03", "SenderId", "DDZ", "ReceiverId", "DDQ", Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); + var header = MessageHeaderFactory.Create(); var marketActivityRecords = new List() { new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "FakeMarketEvaluationPointId"), diff --git a/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/JsonDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/JsonDocumentWriterTests.cs index de5675a645..fe2e9d0c81 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/JsonDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/JsonDocumentWriterTests.cs @@ -28,6 +28,7 @@ using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.RejectRequestChangeOfSupplier; using Json.Schema; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; @@ -52,7 +53,7 @@ public JsonDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader("E03", "SenderId", "DDZ", "ReceiverId", "DDQ", "messageID", _systemDateTimeProvider.Now()); + var header = MessageHeaderFactory.Create(); var marketActivityRecords = new List() { new("mrid1", "OriginalTransactionId", "FakeMarketEvaluationPointId", new List() From d1c66420f7a033616422f8701dacee91999eb158 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:57:36 +0100 Subject: [PATCH 14/25] Use factory --- .../GenericNotificationDocumentWriterTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/GenericNotification/GenericNotificationDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/GenericNotification/GenericNotificationDocumentWriterTests.cs index 362ed18b1e..813aaae758 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/GenericNotification/GenericNotificationDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/GenericNotification/GenericNotificationDocumentWriterTests.cs @@ -30,6 +30,7 @@ using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.GenericNotification; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; @@ -52,7 +53,7 @@ public GenericNotificationDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader(ProcessType.MoveIn.Name, "SenderId", MarketRole.MeteringPointAdministrator.Name, "ReceiverId", MarketRole.EnergySupplier.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); + var header = MessageHeaderFactory.Create(); var marketActivityRecords = new List() { new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "FakeMarketEvaluationPointId", _systemDateTimeProvider.Now()), From 66c8c3b981d2b77154a66fa14908b1db95229ae7 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:59:00 +0100 Subject: [PATCH 15/25] Use factory --- .../NotifyAggregatedMeasureDataDocumentWriterTests.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/NotifyAggreagtedMeasureData/NotifyAggregatedMeasureDataDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/NotifyAggreagtedMeasureData/NotifyAggregatedMeasureDataDocumentWriterTests.cs index 1379182193..037ca7dc5f 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/NotifyAggreagtedMeasureData/NotifyAggregatedMeasureDataDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/NotifyAggreagtedMeasureData/NotifyAggregatedMeasureDataDocumentWriterTests.cs @@ -234,14 +234,7 @@ await AssertXmlDocument private static MessageHeader CreateHeader() { - return new MessageHeader( - ProcessType.BalanceFixing.Name, - "1234567890123", - MarketRole.MeteredDataResponsible.Name, - "1234567890321", - MarketRole.GridOperator.Name, - Guid.NewGuid().ToString(), - SystemClock.Instance.GetCurrentInstant()); + return MessageHeaderFactory.Create(ProcessType.BalanceFixing, MarketRole.MeteredDataResponsible); } private static List CreateSeriesFor(MeteringPointType meteringPointType) From 59f158829d8610fc8a8b283e16b47e522d01ad1d Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 11:59:58 +0100 Subject: [PATCH 16/25] Use factory --- ...hangeAccountingPointCharacteristicsDocumentWriterTests.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeAccountingPointCharacteristics/RejectRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeAccountingPointCharacteristics/RejectRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs index be26ceb490..74a60b3a19 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeAccountingPointCharacteristics/RejectRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeAccountingPointCharacteristics/RejectRequestChangeAccountingPointCharacteristicsDocumentWriterTests.cs @@ -30,6 +30,7 @@ using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.RejectRequestChangeAccountingPointCharacteristics; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; using MarketActivityRecord = Domain.OutgoingMessages.RejectRequestChangeAccountingPointCharacteristics.MarketActivityRecord; @@ -39,13 +40,11 @@ namespace Tests.Infrastructure.OutgoingMessages.RejectRequestChangeAccountingPoi public class RejectRequestChangeAccountingPointCharacteristicsDocumentWriterTests { private readonly RejectRequestChangeAccountingPointCharacteristicsMessageWriter _xmlMessageWriter; - private readonly ISystemDateTimeProvider _systemDateTimeProvider; private readonly IMessageRecordParser _messageRecordParser; private ISchemaProvider? _schemaProvider; public RejectRequestChangeAccountingPointCharacteristicsDocumentWriterTests() { - _systemDateTimeProvider = new SystemDateTimeProvider(); _messageRecordParser = new MessageRecordParser(new Serializer()); _xmlMessageWriter = new RejectRequestChangeAccountingPointCharacteristicsMessageWriter(_messageRecordParser); } @@ -53,7 +52,7 @@ public RejectRequestChangeAccountingPointCharacteristicsDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader(ProcessType.MoveIn.Name, "SenderId", MarketRole.MeteringPointAdministrator.Name, "ReceiverId", MarketRole.EnergySupplier.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); + var header = MessageHeaderFactory.Create(); var marketActivityRecords = new List() { new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "FakeMarketEvaluationPointId", new List() From a8719ecfccae0486cf27d00db30de3b77165a823 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 12:00:45 +0100 Subject: [PATCH 17/25] Use factory --- .../RejectRequestChangeOfSupplierDocumentWriterTests.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierDocumentWriterTests.cs b/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierDocumentWriterTests.cs index 815e78940b..2d996cdf71 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierDocumentWriterTests.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/RejectRequestChangeOfSupplier/RejectRequestChangeOfSupplierDocumentWriterTests.cs @@ -19,17 +19,15 @@ using System.Threading.Tasks; using System.Xml.Linq; using System.Xml.Schema; -using Application.Configuration; using Application.OutgoingMessages.Common; using DocumentValidation; using DocumentValidation.CimXml; -using Domain.Actors; using Domain.OutgoingMessages; using Domain.OutgoingMessages.RejectRequestChangeOfSupplier; -using Infrastructure.Configuration; using Infrastructure.Configuration.Serialization; using Infrastructure.OutgoingMessages.Common; using Infrastructure.OutgoingMessages.RejectRequestChangeOfSupplier; +using Tests.Factories; using Tests.Infrastructure.OutgoingMessages.Asserts; using Xunit; @@ -38,13 +36,11 @@ namespace Tests.Infrastructure.OutgoingMessages.RejectRequestChangeOfSupplier; public class RejectRequestChangeOfSupplierDocumentWriterTests { private readonly RejectRequestChangeOfSupplierXmlMessageWriter _xmlMessageWriter; - private readonly ISystemDateTimeProvider _systemDateTimeProvider; private readonly IMessageRecordParser _messageRecordParser; private ISchemaProvider? _schemaProvider; public RejectRequestChangeOfSupplierDocumentWriterTests() { - _systemDateTimeProvider = new SystemDateTimeProvider(); _messageRecordParser = new MessageRecordParser(new Serializer()); _xmlMessageWriter = new RejectRequestChangeOfSupplierXmlMessageWriter(_messageRecordParser); } @@ -52,7 +48,7 @@ public RejectRequestChangeOfSupplierDocumentWriterTests() [Fact] public async Task Document_is_valid() { - var header = new MessageHeader(ProcessType.MoveIn.Name, "SenderId", MarketRole.MeteringPointAdministrator.Name, "ReceiverId", MarketRole.EnergySupplier.Name, Guid.NewGuid().ToString(), _systemDateTimeProvider.Now()); + var header = MessageHeaderFactory.Create(); var marketActivityRecords = new List() { new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "FakeMarketEvaluationPointId", new List() From ec1191d746a94948dc0414c91a1408b7218bbb59 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 12:26:15 +0100 Subject: [PATCH 18/25] Change type to enable prevalidation --- source/Api/OutgoingMessages/DequeueRequestListener.cs | 2 +- .../OutgoingMessages/Dequeue/DequeueRequestHandler.cs | 4 ++-- .../OutgoingMessages/WhenADequeueIsRequestedTests.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/Api/OutgoingMessages/DequeueRequestListener.cs b/source/Api/OutgoingMessages/DequeueRequestListener.cs index 352df65b68..120eafade7 100644 --- a/source/Api/OutgoingMessages/DequeueRequestListener.cs +++ b/source/Api/OutgoingMessages/DequeueRequestListener.cs @@ -38,7 +38,7 @@ public async Task RunAsync( FunctionContext executionContext, string messageId) { - var result = await _mediator.Send(new DequeueRequest(Guid.Parse(messageId))).ConfigureAwait(false); + var result = await _mediator.Send(new DequeueRequest(messageId)).ConfigureAwait(false); return result.Success ? request.CreateResponse(HttpStatusCode.OK) : request.CreateResponse(HttpStatusCode.BadRequest); diff --git a/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs b/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs index 03cb5bbe98..3b8fd7d986 100644 --- a/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs +++ b/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs @@ -34,10 +34,10 @@ public Task Handle(DequeueRequest request, CancellationToken canc { ArgumentNullException.ThrowIfNull(request); - return _bundledMessages.DequeueAsync(request.MessageId); + return _bundledMessages.DequeueAsync(Guid.Parse(request.MessageId)); } } -public record DequeueRequest(Guid MessageId) : ICommand; +public record DequeueRequest(string MessageId) : ICommand; public record DequeueResult(bool Success); diff --git a/source/IntegrationTests/Application/OutgoingMessages/WhenADequeueIsRequestedTests.cs b/source/IntegrationTests/Application/OutgoingMessages/WhenADequeueIsRequestedTests.cs index bf23564788..4baf6af158 100644 --- a/source/IntegrationTests/Application/OutgoingMessages/WhenADequeueIsRequestedTests.cs +++ b/source/IntegrationTests/Application/OutgoingMessages/WhenADequeueIsRequestedTests.cs @@ -37,7 +37,7 @@ public WhenADequeueIsRequestedTests(DatabaseFixture databaseFixture) [Fact] public async Task Dequeue_is_unsuccessful_when_bundle_does_not_exist() { - var dequeueResult = await InvokeCommandAsync(new DequeueRequest(Guid.NewGuid())).ConfigureAwait(false); + var dequeueResult = await InvokeCommandAsync(new DequeueRequest(Guid.NewGuid().ToString())).ConfigureAwait(false); Assert.False(dequeueResult.Success); } @@ -50,7 +50,7 @@ public async Task Dequeue_is_Successful() ActorNumber.Create(SampleData.NewEnergySupplierNumber), MessageCategory.MasterData)).ConfigureAwait(false); - var dequeueResult = await InvokeCommandAsync(new DequeueRequest(peekResult.MessageId.GetValueOrDefault())).ConfigureAwait(false); + var dequeueResult = await InvokeCommandAsync(new DequeueRequest(peekResult.MessageId.GetValueOrDefault().ToString())).ConfigureAwait(false); using var connection = await GetService().GetConnectionAndOpenAsync().ConfigureAwait(false); var found = await connection From 4542c5dfb3e53d348b7f767ba0a3469be1d8dd2d Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 12:28:35 +0100 Subject: [PATCH 19/25] Parse message id --- .../OutgoingMessages/Dequeue/DequeueRequestHandler.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs b/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs index 3b8fd7d986..53101cde95 100644 --- a/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs +++ b/source/Application/OutgoingMessages/Dequeue/DequeueRequestHandler.cs @@ -34,7 +34,12 @@ public Task Handle(DequeueRequest request, CancellationToken canc { ArgumentNullException.ThrowIfNull(request); - return _bundledMessages.DequeueAsync(Guid.Parse(request.MessageId)); + if (Guid.TryParse(request.MessageId, out var messageId) == false) + { + return Task.FromResult(new DequeueResult(false)); + } + + return _bundledMessages.DequeueAsync(messageId); } } From db4418ced94fd42356c2c4b24ebda7f6d9ec3e5d Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 13:09:20 +0100 Subject: [PATCH 20/25] Enable dependabot --- .github/dependabot.yml | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ccb748590c..97f6a69ef0 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,53 +7,44 @@ updates: - package-ecosystem: "nuget" directory: "/source/ApplyDBMigrationsApp" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/Api" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/Application" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/ArchitectureTests" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/CimMessageAdapter" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/CimMessageAdapter.Tests" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/Infrastructure" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/IntegrationTests" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" - package-ecosystem: "nuget" directory: "/source/Tests" schedule: - interval: "weekly" - open-pull-requests-limit: 0 + interval: "monthly" From 8aea36411bf40c1b9f567753fa6fa0d4e5aa6a76 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Mon, 20 Mar 2023 13:37:51 +0100 Subject: [PATCH 21/25] Upgrade packages --- source/Api/Api.csproj | 6 +++--- source/Application/Application.csproj | 4 ++-- source/CimMessageAdapter/CimMessageAdapter.csproj | 4 ++-- source/Infrastructure/Infrastructure.csproj | 8 ++++---- source/IntegrationTests/IntegrationTests.csproj | 4 ++-- .../source/RequestResponse/RequestResponse.csproj | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/Api/Api.csproj b/source/Api/Api.csproj index 0c5b7138be..6d0266f16d 100644 --- a/source/Api/Api.csproj +++ b/source/Api/Api.csproj @@ -22,15 +22,15 @@ limitations under the License. <_FunctionsSkipCleanOutput>true - - + + - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/source/Application/Application.csproj b/source/Application/Application.csproj index 0e87a2ce56..6a938e10f4 100644 --- a/source/Application/Application.csproj +++ b/source/Application/Application.csproj @@ -23,8 +23,8 @@ limitations under the License. - - + + all diff --git a/source/CimMessageAdapter/CimMessageAdapter.csproj b/source/CimMessageAdapter/CimMessageAdapter.csproj index 1bc478b852..be68c4d6bd 100644 --- a/source/CimMessageAdapter/CimMessageAdapter.csproj +++ b/source/CimMessageAdapter/CimMessageAdapter.csproj @@ -20,8 +20,8 @@ limitations under the License. - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/source/Infrastructure/Infrastructure.csproj b/source/Infrastructure/Infrastructure.csproj index ea26bfe0af..c1eb135247 100644 --- a/source/Infrastructure/Infrastructure.csproj +++ b/source/Infrastructure/Infrastructure.csproj @@ -22,16 +22,16 @@ limitations under the License. - - + + - + - + diff --git a/source/IntegrationTests/IntegrationTests.csproj b/source/IntegrationTests/IntegrationTests.csproj index 1950f3d6d6..1a3fae54d8 100644 --- a/source/IntegrationTests/IntegrationTests.csproj +++ b/source/IntegrationTests/IntegrationTests.csproj @@ -22,8 +22,8 @@ limitations under the License. - - + + diff --git a/source/RequestResponse/source/RequestResponse/RequestResponse.csproj b/source/RequestResponse/source/RequestResponse/RequestResponse.csproj index 60860b26ba..b77d7a742c 100644 --- a/source/RequestResponse/source/RequestResponse/RequestResponse.csproj +++ b/source/RequestResponse/source/RequestResponse/RequestResponse.csproj @@ -51,8 +51,8 @@ limitations under the License. - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive From 2cff5e273f0789713f940d4d0f5461c4ea882b21 Mon Sep 17 00:00:00 2001 From: "Kristian F. Thomsen" Date: Tue, 21 Mar 2023 13:00:24 +0100 Subject: [PATCH 22/25] Upgrade package version --- .../DocumentValidation.csproj | 2 +- .../JsonMessageParser.cs | 36 ++++++++++--------- .../Asserts/AssertJsonMessage.cs | 6 ++-- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/source/DocumentValidation/DocumentValidation.csproj b/source/DocumentValidation/DocumentValidation.csproj index 383c6c06f5..4fecdcd752 100644 --- a/source/DocumentValidation/DocumentValidation.csproj +++ b/source/DocumentValidation/DocumentValidation.csproj @@ -7,7 +7,7 @@ - + diff --git a/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs b/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs index 2b6b27d14f..9e97b99179 100644 --- a/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs +++ b/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs @@ -185,35 +185,39 @@ private static string GetJsonDateStringWithoutQuotes(JToken token) return token.ToString(Formatting.None).Trim('"'); } + private static bool IsValid(JsonDocument document, JsonSchema schema) + { + return schema.Evaluate(document, new EvaluationOptions() { OutputFormat = OutputFormat.Flag, }).IsValid; + } + private async Task ValidateMessageAsync(JsonSchema schema, Stream message) { var jsonDocument = await JsonDocument.ParseAsync(message).ConfigureAwait(false); - var validationOptions = new ValidationOptions() + if (IsValid(jsonDocument, schema) == false) { - OutputFormat = OutputFormat.Detailed, - }; - - var validationResult = schema.Validate(jsonDocument, validationOptions); - - if (!validationResult.IsValid) - { - AddValidationErrors(validationResult); + ExtractValidationErrors(jsonDocument, schema); } ResetMessagePosition(message); } - private void AddValidationErrors(ValidationResults validationResult) + private void ExtractValidationErrors(JsonDocument jsonDocument, JsonSchema schema) { - AddValidationError(validationResult.Message); + var result = schema.Evaluate(jsonDocument, new EvaluationOptions() { OutputFormat = OutputFormat.List, }); + result + .Details + .Where(detail => detail.HasErrors) + .ToList().ForEach(AddValidationErrors); + } - if (validationResult.HasNestedResults) + private void AddValidationErrors(EvaluationResults validationResult) + { + var propertyName = validationResult.InstanceLocation.ToString(); + var errorsValues = validationResult.Errors ?? new Dictionary(); + foreach (var error in errorsValues) { - foreach (var result in validationResult.NestedResults) - { - AddValidationError(result.Message); - } + AddValidationError($"{propertyName}: {error}"); } } diff --git a/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs b/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs index 0db82a9923..77cbfcee51 100644 --- a/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs +++ b/source/Tests/Infrastructure/OutgoingMessages/Asserts/AssertJsonMessage.cs @@ -29,12 +29,12 @@ public static void AssertConformsToSchema(JsonDocument document, JsonSchema sche { if (schema == null) throw new InvalidOperationException($"Schema not found for business process type {documentType}"); - var validationOptions = new ValidationOptions() + var validationOptions = new EvaluationOptions() { - OutputFormat = OutputFormat.Detailed, + OutputFormat = OutputFormat.List, }; - var validationResult = schema.Validate(document, validationOptions); + var validationResult = schema.Evaluate(document, validationOptions); Assert.True(validationResult.IsValid); } From f55e42c0bd4187d909e044dfa124a68ea7b2f40b Mon Sep 17 00:00:00 2001 From: Chris Brohus Date: Tue, 21 Mar 2023 15:08:37 +0100 Subject: [PATCH 23/25] Replace Newtonsoft.json with system.text.json --- .../JsonMessageParser.cs | 77 +++++++++++-------- .../Response/JsonResponseFactory.cs | 3 +- .../Common/Json/JsonHeaderWriter.cs | 3 +- 3 files changed, 47 insertions(+), 36 deletions(-) diff --git a/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs b/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs index 0d6c9fa52e..c7f1cf6421 100644 --- a/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs +++ b/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs @@ -14,11 +14,13 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Text.Json; using System.Text.Json.Nodes; using System.Threading.Tasks; +using System.Xml; using Application.IncomingMessages.RequestChangeOfSupplier; using CimMessageAdapter.Errors; using CimMessageAdapter.Messages; @@ -47,17 +49,20 @@ public async Task(processType, "0").ConfigureAwait(false); + var schema = await _schemaProvider.GetSchemaAsync(processType.ToUpper(CultureInfo.InvariantCulture), "0").ConfigureAwait(false); if (schema is null) { return new MessageParserResult(new UnknownBusinessProcessTypeOrVersion(processType, "0")); @@ -74,11 +79,11 @@ public async Task(message, options); if (deserialized is null) throw new InvalidOperationException("Unable to read first node"); var path = deserialized.First().Value?.ToString(); + if (path is null) throw new InvalidOperationException("Unable to read path"); split = path.Split('_'); return split; } - private static string GetBusinessProcessType(Stream message) + /* + private static string GetBusinessProcessType(JsonDocument document) { - if (message == null) throw new ArgumentNullException(nameof(message)); - var split = SplitNamespace(message); - var processType = split[0]; + //if (message == null) throw new ArgumentNullException(nameof(message)); + //var split = SplitNamespace(message); + var processType = document.RootElement.GetProperty() return processType; } + */ - private static MessageParserResult ParseJsonData(Utf8JsonReader jsonTextReader) + private static MessageParserResult ParseJsonData(JsonDocument document) { var marketActivityRecords = new List(); - var jsonRequest = JsonSerializer.Deserialize(jsonTextReader, JsonObject, new JsonSerializerOptions()); - var headerToken = jsonRequest.SelectToken(HeaderElementName); - var messageHeader = MessageHeaderFrom(headerToken); - marketActivityRecords.AddRange(headerToken[MarketActivityRecordElementName].Select(MarketActivityRecordFrom)); + var messageHeader = MessageHeaderFrom(document.RootElement.GetProperty(HeaderElementName)); + var marketActivityRecord = document.RootElement.GetProperty(HeaderElementName).GetProperty(MarketActivityRecordElementName); + var records = marketActivityRecord.EnumerateArray(); + foreach (var jsonElement in records) + { + marketActivityRecords.Add(MarketActivityRecordFrom(jsonElement)); + } return new MessageParserResult(new RequestChangeOfSupplierIncomingMarketDocument(messageHeader, marketActivityRecords)); } @@ -144,36 +155,36 @@ private static MessageParserResult(InvalidMessageStructure.From(exception)); } - private static MessageHeader MessageHeaderFrom(JToken token) + private static MessageHeader MessageHeaderFrom(JsonElement element) { return new MessageHeader( - token["mRID"].ToString(), - token["process.processType"]["value"].ToString(), - token["sender_MarketParticipant.mRID"]["value"].ToString(), - token["sender_MarketParticipant.marketRole.type"]["value"].ToString(), - token["receiver_MarketParticipant.mRID"]["value"].ToString(), - token["receiver_MarketParticipant.marketRole.type"]["value"].ToString(), - GetJsonDateStringWithoutQuotes(token["createdDateTime"])); + element.GetProperty("mRID").ToString(), + element.GetProperty("process.processType").GetProperty("value").ToString(), + element.GetProperty("sender_MarketParticipant.mRID").GetProperty("value").ToString(), + element.GetProperty("sender_MarketParticipant.marketRole.type").GetProperty("value").ToString(), + element.GetProperty("receiver_MarketParticipant.mRID").GetProperty("value").ToString(), + element.GetProperty("receiver_MarketParticipant.marketRole.type").GetProperty("value").ToString(), + GetJsonDateStringWithoutQuotes(element.GetProperty("createdDateTime"))); } - private static MarketActivityRecord MarketActivityRecordFrom(JToken token) + private static MarketActivityRecord MarketActivityRecordFrom(JsonElement element) { return new MarketActivityRecord() { - Id = token["mRID"].ToString(), - ConsumerId = token["marketEvaluationPoint.customer_MarketParticipant.mRID"]["value"].ToString(), - ConsumerIdType = token["marketEvaluationPoint.customer_MarketParticipant.mRID"]["codingScheme"].ToString(), - BalanceResponsibleId = token["marketEvaluationPoint.balanceResponsibleParty_MarketParticipant.mRID"]["value"].ToString(), - EnergySupplierId = token["marketEvaluationPoint.energySupplier_MarketParticipant.mRID"]["value"].ToString(), - MarketEvaluationPointId = token["marketEvaluationPoint.mRID"]["value"].ToString(), - ConsumerName = token["marketEvaluationPoint.customer_MarketParticipant.name"].ToString(), - EffectiveDate = GetJsonDateStringWithoutQuotes(token["start_DateAndOrTime.dateTime"]), + Id = element.GetProperty("mRID").ToString(), + ConsumerId = element.GetProperty("marketEvaluationPoint.customer_MarketParticipant.mRID").GetProperty("value").ToString(), + ConsumerIdType = element.GetProperty("marketEvaluationPoint.customer_MarketParticipant.mRID").GetProperty("codingScheme").ToString(), + BalanceResponsibleId = element.GetProperty("marketEvaluationPoint.balanceResponsibleParty_MarketParticipant.mRID").GetProperty("value").ToString(), + EnergySupplierId = element.GetProperty("marketEvaluationPoint.energySupplier_MarketParticipant.mRID").GetProperty("value").ToString(), + MarketEvaluationPointId = element.GetProperty("marketEvaluationPoint.mRID").GetProperty("value").ToString(), + ConsumerName = element.GetProperty("marketEvaluationPoint.customer_MarketParticipant.name").ToString(), + EffectiveDate = GetJsonDateStringWithoutQuotes(element.GetProperty("start_DateAndOrTime.dateTime")), }; } - private static string GetJsonDateStringWithoutQuotes(JToken token) + private static string GetJsonDateStringWithoutQuotes(JsonElement element) { - return token.ToString(Formatting.None).Trim('"'); + return element.ToString().Trim('"'); } private static bool IsValid(JsonDocument document, JsonSchema schema) diff --git a/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs b/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs index cabbd3b21e..12e3fa3845 100644 --- a/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs +++ b/source/Infrastructure/IncomingMessages/Response/JsonResponseFactory.cs @@ -64,12 +64,13 @@ private static string CreateMessageBodyFrom(Result result) writer.WriteEndObject(); } - writer.WriteEndObject(); + writer.WriteEndArray(); writer.WriteEndObject(); } writer.WriteEndObject(); writer.WriteEndObject(); + writer.Flush(); return Encoding.UTF8.GetString(messageBody.ToArray()); } diff --git a/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs b/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs index 407db2dfaf..b6a6fc46a3 100644 --- a/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs +++ b/source/Infrastructure/OutgoingMessages/Common/Json/JsonHeaderWriter.cs @@ -13,9 +13,8 @@ // limitations under the License. using System; -using Domain.Actors; using System.Text.Json; -using System.Xml; +using Domain.Actors; using Domain.OutgoingMessages; using Domain.SeedWork; From e3100f993fb8749858e28067be579b4917d4155f Mon Sep 17 00:00:00 2001 From: Chris Brohus Date: Tue, 21 Mar 2023 15:12:11 +0100 Subject: [PATCH 24/25] Cleanup unused code --- .../JsonMessageParser.cs | 44 ++----------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs b/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs index c7f1cf6421..64e5858610 100644 --- a/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs +++ b/source/Infrastructure/IncomingMessages/RequestChangeOfSupplier/JsonMessageParser.cs @@ -35,6 +35,7 @@ public class JsonMessageParser : IMessageParser _errors = new(); @@ -49,23 +50,10 @@ public async Task(processType.ToUpper(CultureInfo.InvariantCulture), "0").ConfigureAwait(false); + var schema = await _schemaProvider.GetSchemaAsync(DocumentName.ToUpper(CultureInfo.InvariantCulture), "0").ConfigureAwait(false); if (schema is null) { - return new MessageParserResult(new UnknownBusinessProcessTypeOrVersion(processType, "0")); + return new MessageParserResult(new UnknownBusinessProcessTypeOrVersion(DocumentName, "0")); } ResetMessagePosition(message); @@ -104,32 +92,6 @@ public async Task(message, options); - if (deserialized is null) throw new InvalidOperationException("Unable to read first node"); - var path = deserialized.First().Value?.ToString(); - if (path is null) throw new InvalidOperationException("Unable to read path"); - split = path.Split('_'); - - return split; - } - - /* - private static string GetBusinessProcessType(JsonDocument document) - { - //if (message == null) throw new ArgumentNullException(nameof(message)); - //var split = SplitNamespace(message); - var processType = document.RootElement.GetProperty() - return processType; - } - */ - private static MessageParserResult ParseJsonData(JsonDocument document) { var marketActivityRecords = new List(); From a6c7eae6c027d848ebb7e1f454ed7d46c8956799 Mon Sep 17 00:00:00 2001 From: Chris Brohus Date: Tue, 21 Mar 2023 15:19:34 +0100 Subject: [PATCH 25/25] Delete unused files --- .../functionapphost.settings.json | 16 ---------------- .../integrationtest.local.settings.json | 3 --- 2 files changed, 19 deletions(-) delete mode 100644 source/AcceptanceTests/functionapphost.settings.json delete mode 100644 source/AcceptanceTests/integrationtest.local.settings.json diff --git a/source/AcceptanceTests/functionapphost.settings.json b/source/AcceptanceTests/functionapphost.settings.json deleted file mode 100644 index e1a0829808..0000000000 --- a/source/AcceptanceTests/functionapphost.settings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - // - // See class FunctionAppHostSettings for a description of settings in this file. - // - - // We previously used %ProgramFiles% but experienced problems as it sometimes resolved to "...\Program Files (x86)\" - "DotnetExecutablePath": "C:\\Program Files\\dotnet\\dotnet.exe", - - // We must ensure this tool is installed at the same location on all developer machines. - // Be sure to use 'nvm' to manage Node.js + npm and node modules. - "FunctionAppHostPath": "C:\\Program Files\\nodejs\\node_modules\\azure-functions-core-tools\\bin\\func.dll", - - "UseShellExecute": "false", - "Port": "7001", - "MaxWaitSeconds": "120" -} diff --git a/source/AcceptanceTests/integrationtest.local.settings.json b/source/AcceptanceTests/integrationtest.local.settings.json deleted file mode 100644 index 29bbcf5193..0000000000 --- a/source/AcceptanceTests/integrationtest.local.settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "AZURE_KEYVAULT_URL": "https://kv-integrationtest-u-002.vault.azure.net/" -} \ No newline at end of file