Skip to content

Commit

Permalink
Merge branch 'main' into nuget
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein authored Feb 1, 2024
2 parents b4dcdf5 + 11e8efe commit f4df8c0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions TransformerBeeClient/TransformerBeeClient/Model/BOneyComb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public class BOneyComb
/// </summary>
[JsonPropertyName("stammdaten")] // we want to support both System.Text and Newtonsoft as long as BO4E.net does so
[JsonProperty(PropertyName = "stammdaten")]
public List<BusinessObject> Stammdaten { get; set; }
public List<BusinessObject>? Stammdaten { get; set; }

/// <summary>
/// Transaktionsdaten are metadata related to the Marktprozess and are not related to a specific Business object.
/// </summary>
[JsonPropertyName("transaktionsdaten")] // we want to support both System.Text and Newtonsoft as long as BO4E.net does so
[JsonProperty(PropertyName = "transaktionsdaten")]
public Dictionary<string, string> Transaktionsdaten { get; set; }
public Dictionary<string, string>? Transaktionsdaten { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class Bo4eTransactionToEdifactRequest
/// the BOneyComb as json string
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("BO4E")]
public string Bo4eJsonString { get; set; }
public string? Bo4eJsonString { get; set; }

/// <summary>
/// the format version to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ internal class Bo4eTransactionToEdifactResponse
/// the edifact as plain string
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("EDI")]
public string Edifact { get; set; }
public string? Edifact { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class EdifactToBo4eRequest
/// the edifact as plain string
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("EDI")]
public string Edifact { get; set; }
public string? Edifact { get; set; }

/// <summary>
/// the format version to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class EdifactToBo4eResponse
/// the bo4e as plain json string
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("BO4E")]
public string Bo4eJsonString { get; set; }
public string? Bo4eJsonString { get; set; }

/// <summary>
/// the format version that was used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class Marktnachricht
/// </summary>
[JsonPropertyName("transaktionen")]// we want to support both System.Text and Newtonsoft as long as BO4E.net does so
[JsonProperty(PropertyName = "transaktionen")]
public List<BOneyComb> Transaktionen { get; set; }
public List<BOneyComb>? Transaktionen { get; set; }

/// <summary>
/// Nachrichtendaten are similar to <see cref="BOneyComb.Transaktionsdaten"/> but are not 100% identical.
/// </summary>
[JsonPropertyName("nachrichtendaten")] // we want to support both System.Text and Newtonsoft as long as BO4E.net does so
[JsonProperty(PropertyName = "nachrichtendaten")]
public Dictionary<string, string> Nachrichtendaten { get; set; }
public Dictionary<string, string>? Nachrichtendaten { get; set; }
}
18 changes: 10 additions & 8 deletions TransformerBeeClient/TransformerBeeClient/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public TransformerBeeRestClient(IHttpClientFactory httpClientFactory, string cli
/// </returns>
public async Task<bool> IsAvailable()
{
var uriBuilder = new UriBuilder(_httpClient!.BaseAddress)
var uriBuilder = new UriBuilder(_httpClient.BaseAddress!)
{
Path = "/version"
};
Expand All @@ -69,7 +69,7 @@ public async Task<List<Marktnachricht>> 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"
};
Expand All @@ -90,10 +90,10 @@ public async Task<List<Marktnachricht>> ConvertToBo4e(string edifact, EdifactFor
var responseContent = await httpResponse.Content.ReadAsStringAsync();
var bo4eResponse = JsonSerializer.Deserialize<EdifactToBo4eResponse>(responseContent, _jsonSerializerOptions);
// todo: handle the case that the deserialization fails and bo4eResponse is null
var unescapedJson = bo4eResponse!.Bo4eJsonString.Unescape();
var result = JsonSerializer.Deserialize<List<Marktnachricht>>(unescapedJson, _jsonSerializerOptions);
var unescapedJson = bo4eResponse!.Bo4eJsonString!.Unescape();
var result = JsonSerializer.Deserialize<List<Marktnachricht>>(unescapedJson!, _jsonSerializerOptions);
// todo: handle the case that the deserialization fails and result is null
return result;
return result!;
}

public async Task<string> ConvertToEdifact(BOneyComb boneyComb, EdifactFormatVersion formatVersion)
Expand All @@ -102,7 +102,7 @@ public async Task<string> 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"
};
Expand All @@ -122,7 +122,9 @@ public async Task<string> 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<Bo4eTransactionToEdifactResponse>(responseContent, _jsonSerializerOptions);
return responseBody.Edifact;
// todo: ensure that the deserialization does not fail and the response is not empty
var responseBody = JsonSerializer.Deserialize<Bo4eTransactionToEdifactResponse>(responseContent!, _jsonSerializerOptions);
// todo: handle case that deserialization fails and responseBody is null
return responseBody!.Edifact!;
}
}
4 changes: 2 additions & 2 deletions TransformerBeeClient/TransformerBeeClient/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ internal static class Utils
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
internal static string Unescape(this string s)
internal static string? Unescape(this string? s)
{
return s.Replace("\\n", "\n");
return s?.Replace("\\n", "\n");
}
}

0 comments on commit f4df8c0

Please sign in to comment.