From 11e8efe57ca9e389a0564effda4809e0a13c6d1c Mon Sep 17 00:00:00 2001 From: konstantin Date: Thu, 1 Feb 2024 17:09:42 +0000 Subject: [PATCH] ci: use strict build (treats all warnings as errors) (#10) --- .github/workflows/unittests.yml | 2 +- .../TransformerBeeClient/Model/BOneyComb.cs | 4 ++-- .../Model/Bo4eTransactionToEdifactRequest.cs | 2 +- .../Model/Bo4eTransactionToEdifactResponse.cs | 2 +- .../Model/EdifactToBo4eRequest.cs | 2 +- .../Model/EdifactToBo4eResponse.cs | 2 +- .../Model/Marktnachricht.cs | 4 ++-- .../TransformerBeeClient/RestClient.cs | 18 ++++++++++-------- .../TransformerBeeClient/Utils.cs | 4 ++-- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.github/workflows/unittests.yml b/.github/workflows/unittests.yml index 4be88f9..0eee283 100644 --- a/.github/workflows/unittests.yml +++ b/.github/workflows/unittests.yml @@ -27,7 +27,7 @@ jobs: - name: Build working-directory: TransformerBeeClient - run: dotnet build --no-restore + run: dotnet build --no-restore --configuration Release - name: Run Unit Tests working-directory: TransformerBeeClient/TransformerBeeClient.UnitTest diff --git a/TransformerBeeClient/TransformerBeeClient/Model/BOneyComb.cs b/TransformerBeeClient/TransformerBeeClient/Model/BOneyComb.cs index 2c8e2ca..19f2269 100644 --- a/TransformerBeeClient/TransformerBeeClient/Model/BOneyComb.cs +++ b/TransformerBeeClient/TransformerBeeClient/Model/BOneyComb.cs @@ -15,12 +15,12 @@ public class BOneyComb /// [JsonPropertyName("stammdaten")] // we want to support both System.Text and Newtonsoft as long as BO4E.net does so [JsonProperty(PropertyName = "stammdaten")] - public List Stammdaten { get; set; } + public List? Stammdaten { get; set; } /// /// Transaktionsdaten are metadata related to the Marktprozess and are not related to a specific Business object. /// [JsonPropertyName("transaktionsdaten")] // we want to support both System.Text and Newtonsoft as long as BO4E.net does so [JsonProperty(PropertyName = "transaktionsdaten")] - public Dictionary Transaktionsdaten { get; set; } + public Dictionary? Transaktionsdaten { get; set; } } diff --git a/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactRequest.cs b/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactRequest.cs index 9a1a5f3..ade7c34 100644 --- a/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactRequest.cs +++ b/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactRequest.cs @@ -13,7 +13,7 @@ internal class Bo4eTransactionToEdifactRequest /// the BOneyComb as json string /// [System.Text.Json.Serialization.JsonPropertyName("BO4E")] - public string Bo4eJsonString { get; set; } + public string? Bo4eJsonString { get; set; } /// /// the format version to use diff --git a/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactResponse.cs b/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactResponse.cs index 6d54b43..e113286 100644 --- a/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactResponse.cs +++ b/TransformerBeeClient/TransformerBeeClient/Model/Bo4eTransactionToEdifactResponse.cs @@ -11,5 +11,5 @@ internal class Bo4eTransactionToEdifactResponse /// the edifact as plain string /// [System.Text.Json.Serialization.JsonPropertyName("EDI")] - public string Edifact { get; set; } + public string? Edifact { get; set; } } diff --git a/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eRequest.cs b/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eRequest.cs index c7d8dcd..9364f1e 100644 --- a/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eRequest.cs +++ b/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eRequest.cs @@ -13,7 +13,7 @@ internal class EdifactToBo4eRequest /// the edifact as plain string /// [System.Text.Json.Serialization.JsonPropertyName("EDI")] - public string Edifact { get; set; } + public string? Edifact { get; set; } /// /// the format version to use diff --git a/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eResponse.cs b/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eResponse.cs index e7c8b0f..dc191af 100644 --- a/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eResponse.cs +++ b/TransformerBeeClient/TransformerBeeClient/Model/EdifactToBo4eResponse.cs @@ -13,7 +13,7 @@ internal class EdifactToBo4eResponse /// the bo4e as plain json string /// [System.Text.Json.Serialization.JsonPropertyName("BO4E")] - public string Bo4eJsonString { get; set; } + public string? Bo4eJsonString { get; set; } /// /// the format version that was used diff --git a/TransformerBeeClient/TransformerBeeClient/Model/Marktnachricht.cs b/TransformerBeeClient/TransformerBeeClient/Model/Marktnachricht.cs index 6a5e948..fb288df 100644 --- a/TransformerBeeClient/TransformerBeeClient/Model/Marktnachricht.cs +++ b/TransformerBeeClient/TransformerBeeClient/Model/Marktnachricht.cs @@ -21,12 +21,12 @@ public class Marktnachricht /// [JsonPropertyName("transaktionen")]// we want to support both System.Text and Newtonsoft as long as BO4E.net does so [JsonProperty(PropertyName = "transaktionen")] - public List Transaktionen { get; set; } + public List? Transaktionen { get; set; } /// /// Nachrichtendaten are similar to but are not 100% identical. /// [JsonPropertyName("nachrichtendaten")] // we want to support both System.Text and Newtonsoft as long as BO4E.net does so [JsonProperty(PropertyName = "nachrichtendaten")] - public Dictionary Nachrichtendaten { get; set; } + public Dictionary? Nachrichtendaten { get; set; } } diff --git a/TransformerBeeClient/TransformerBeeClient/RestClient.cs b/TransformerBeeClient/TransformerBeeClient/RestClient.cs index e140f6a..024558d 100644 --- a/TransformerBeeClient/TransformerBeeClient/RestClient.cs +++ b/TransformerBeeClient/TransformerBeeClient/RestClient.cs @@ -46,7 +46,7 @@ public TransformerBeeRestClient(IHttpClientFactory httpClientFactory, string cli /// public async Task IsAvailable() { - var uriBuilder = new UriBuilder(_httpClient!.BaseAddress) + var uriBuilder = new UriBuilder(_httpClient.BaseAddress!) { Path = "/version" }; @@ -69,7 +69,7 @@ public async Task> ConvertToBo4e(string edifact, EdifactFor { throw new ArgumentNullException(nameof(edifact)); } - var uriBuilder = new UriBuilder(_httpClient!.BaseAddress) + var uriBuilder = new UriBuilder(_httpClient!.BaseAddress!) { Path = "/v1/transformer/EdiToBo4E" }; @@ -90,10 +90,10 @@ public async Task> ConvertToBo4e(string edifact, EdifactFor var responseContent = await httpResponse.Content.ReadAsStringAsync(); var bo4eResponse = JsonSerializer.Deserialize(responseContent, _jsonSerializerOptions); // todo: handle the case that the deserialization fails and bo4eResponse is null - var unescapedJson = bo4eResponse!.Bo4eJsonString.Unescape(); - var result = JsonSerializer.Deserialize>(unescapedJson, _jsonSerializerOptions); + var unescapedJson = bo4eResponse!.Bo4eJsonString!.Unescape(); + var result = JsonSerializer.Deserialize>(unescapedJson!, _jsonSerializerOptions); // todo: handle the case that the deserialization fails and result is null - return result; + return result!; } public async Task ConvertToEdifact(BOneyComb boneyComb, EdifactFormatVersion formatVersion) @@ -102,7 +102,7 @@ public async Task ConvertToEdifact(BOneyComb boneyComb, EdifactFormatVer { throw new ArgumentNullException(nameof(boneyComb)); } - var uriBuilder = new UriBuilder(_httpClient!.BaseAddress) + var uriBuilder = new UriBuilder(_httpClient!.BaseAddress!) { Path = "/v1/transformer/Bo4ETransactionToEdi" }; @@ -122,7 +122,9 @@ public async Task ConvertToEdifact(BOneyComb boneyComb, EdifactFormatVer throw new HttpRequestException($"Could not convert to EDIFACT; Status code: {httpResponse.StatusCode}"); } var responseContent = await httpResponse.Content.ReadAsStringAsync(); - var responseBody = JsonSerializer.Deserialize(responseContent, _jsonSerializerOptions); - return responseBody.Edifact; + // todo: ensure that the deserialization does not fail and the response is not empty + var responseBody = JsonSerializer.Deserialize(responseContent!, _jsonSerializerOptions); + // todo: handle case that deserialization fails and responseBody is null + return responseBody!.Edifact!; } } diff --git a/TransformerBeeClient/TransformerBeeClient/Utils.cs b/TransformerBeeClient/TransformerBeeClient/Utils.cs index 06651f8..7376746 100644 --- a/TransformerBeeClient/TransformerBeeClient/Utils.cs +++ b/TransformerBeeClient/TransformerBeeClient/Utils.cs @@ -10,8 +10,8 @@ internal static class Utils /// /// /// - internal static string Unescape(this string s) + internal static string? Unescape(this string? s) { - return s.Replace("\\n", "\n"); + return s?.Replace("\\n", "\n"); } }