Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.11.6 + Geraetemerkmal Fixes #661

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/feature_branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: 6.0.201
dotnet-version: 8
- name: Build/Check for compile errors (dotnet build)
run: dotnet build --configuration Release --version-suffix "${{github.sha}}"
- name: Run Unit Tests (dotnet test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace BO4E.meta.LenientConverters;
public class LenientGeraetemerkmalGasConverter : JsonConverter
{
/// <inheritdoc cref="JsonConverter.CanWrite" />
public override bool CanWrite => false;
public override bool CanWrite => true;

/// <inheritdoc cref="JsonConverter.CanConvert(Type)" />
public override bool CanConvert(Type objectType)
Expand Down Expand Up @@ -41,7 +41,10 @@ JsonSerializer serializer
rawValue = reader.Value?.ToString();
break;
}

if (string.IsNullOrEmpty(rawValue))
{
return null;
}
try
{
return Enums.Parse<Geraetemerkmal>(rawValue);
Expand All @@ -59,6 +62,6 @@ JsonSerializer serializer
/// <inheritdoc cref="JsonConverter.WriteJson(JsonWriter, object, JsonSerializer)" />
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
writer.WriteRawValue("\"" + value.ToString() + "\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ JsonSerializerOptions options
)
{
var stringValue = value.ToString();
var match = GasPrefixRegex.Match(stringValue);
if (!match.Success)
{
writer.WriteStringValue(stringValue);
return;
}
var rest = match.Groups["rest"].Value;
writer.WriteStringValue(rest);
writer.WriteStringValue(stringValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,8 @@ JsonSerializerOptions options
{
if (value.HasValue)
{
// Remove the "GAS_" prefix if it exists
var stringValue = value.Value.ToString();
var match = GasPrefixRegex.Match(stringValue);
if (!match.Success)
{
writer.WriteStringValue(stringValue);
return;
}
var rest = match.Groups["rest"].Value;
writer.WriteStringValue(rest);
var stringValue = value.ToString();
writer.WriteStringValue(stringValue);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion BO4E/protobuf-files/bo4e.proto
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ enum Energierichtung {
AUSSP = 0;
EINSP = 1;
RUHEND = 2;
KUNDENANLAGE = 3;
}
message Erreichbarkeit {
option (.protobuf_net.msgopt).namespace = "BO4E.COM";
Expand Down Expand Up @@ -961,7 +962,7 @@ message Marktlokation {
Geschaeftspartner Endkunde = 17;
Adresse Lokationsadresse = 18;
Geokoordinaten Geoadresse = 19;
Katasteradresse Katasterinformation = 20;
repeated Katasteradresse Katasterinformation = 20;
repeated Messlokationszuordnung ZugehoerigeMesslokationen = 28;
repeated Netznutzungsabrechnungsdaten Netznutzungsabrechnungsdaten = 37;
Sperrstatus Sperrstatus = 38;
Expand Down
41 changes: 39 additions & 2 deletions BO4ETestProject/TestGeraetemerkmalConverter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using BO4E.ENUM;
using BO4E.meta.LenientConverters;
Expand Down Expand Up @@ -84,6 +85,27 @@ public void TestNewtonsoft_Success_Nullable()
result.Merkmal.Should().Be(Geraetemerkmal.GAS_G4);
}

[TestMethod]
public void TestNewtonsoft_Success_Nullable_Serialization()
{
var myInstance = new SomethingWithANullableGeraetemerkmal()
{
Merkmal = Geraetemerkmal.GAS_G4,
};
var result = JsonConvert.SerializeObject(
myInstance,
new JsonSerializerSettings()
{
Converters = new List<Newtonsoft.Json.JsonConverter>()
{
new LenientGeraetemerkmalGasConverter(),
new Newtonsoft.Json.Converters.StringEnumConverter(),
},
}
);
result.Should().NotBeNullOrWhiteSpace().And.Contain("\"GAS_G4\"").And.NotContain("\"G4\"");
}

[TestMethod]
public void TestNewtonsoft_Success_Nullable_WASSER_MWZW()
{
Expand Down Expand Up @@ -120,6 +142,21 @@ public void TestSystemText_Success_NonNullable()
result.Merkmal.Should().Be(Geraetemerkmal.GAS_G4);
}

[TestMethod]
public void TestSystemText_Success_NonNullable_Serialization()
{
var myInstance = new SomethingWithANullableGeraetemerkmal()
{
Merkmal = Geraetemerkmal.GAS_G4,
};
var settings = new System.Text.Json.JsonSerializerOptions()
{
Converters = { new LenientSystemTextGeraetemerkmalGasConverter() },
};
var result = System.Text.Json.JsonSerializer.Serialize(myInstance, settings);
result.Should().NotBeNullOrWhiteSpace().And.Contain("\"GAS_G4\"").And.NotContain("\"G4\"");
}

[TestMethod]
public void TestSystemText_Success_NonNullable_WASSER_MWZW()
{
Expand Down Expand Up @@ -172,7 +209,7 @@ public void TestSystemText_Write_NonNullable()
};
var instance = new SomethingWithAGeraetemerkmal { Merkmal = Geraetemerkmal.GAS_G4 };
var json = System.Text.Json.JsonSerializer.Serialize(instance, settings);
json.Should().Be("{\"merkmal\":\"G4\"}");
json.Should().Be($"{{\"merkmal\":\"{Geraetemerkmal.GAS_G4.ToString()}\"}}");
}

[TestMethod]
Expand All @@ -187,7 +224,7 @@ public void TestSystemText_Write_Nullable()
Merkmal = Geraetemerkmal.GAS_G2P5,
};
var json = System.Text.Json.JsonSerializer.Serialize(instance, settings);
json.Should().Be("{\"merkmal\":\"G2P5\"}");
json.Should().Be("{\"merkmal\":\"GAS_G2P5\"}");
}

[TestMethod]
Expand Down
Loading