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

feat: Annotate COM.Verwendungszweck itself with new JsonConverters; Prevent StackOverflows on the way (part of DEV-77714) #567

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions BO4E/COM/Verwendungszweck.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using BO4E.meta;
using BO4E.meta.LenientConverters;
using Newtonsoft.Json;
using ProtoBuf;

Expand All @@ -11,6 +12,8 @@ namespace BO4E.COM;
/// </summary>
[ProtoContract]
[NonOfficial(NonOfficialCategory.REGULATORY_REQUIREMENTS)]
[System.Text.Json.Serialization.JsonConverter(typeof(SystemTextVerwendungszweckEnumToComConverter))]
[Newtonsoft.Json.JsonConverter(typeof(NewtonsoftVerwendungszweckEnumToComConverter))]
public class Verwendungszweck : COM
{
/// <summary>
Expand Down
36 changes: 36 additions & 0 deletions BO4ETestProject/TestStringEnumConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
settings
);
actual.Should().NotBeNull();
actual.Foo.Should().Be(expectedGasqualitaet);

Check warning on line 160 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 160 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 160 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

Check warning on line 160 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(actual, settings);
reSerializedJsonString.Should().Contain(expectedGasqualitaet?.ToString() ?? "null");
Expand Down Expand Up @@ -207,7 +207,7 @@
settings
);
actual.Should().NotBeNull();
actual.Foo.Should().Be(expectedGasqualitaet);

Check warning on line 210 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 210 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 210 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

Check warning on line 210 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(actual, settings);
reSerializedJsonString.Should().Contain(expectedGasqualitaet.ToString());
Expand Down Expand Up @@ -263,7 +263,7 @@
settings
);
actual.Should().NotBeNull();
actual.Foo.Should().Be(expectedGasqualitaet);

Check warning on line 266 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 266 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 266 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

Check warning on line 266 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

var reSerializedJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(actual, settings);
reSerializedJsonString.Should().Contain(expectedGasqualitaet?.ToString() ?? "null");
Expand Down Expand Up @@ -318,7 +318,7 @@
settings
);
actual.Should().NotBeNull();
actual.Foo.Should().Be(expectedGasqualitaet);

Check warning on line 321 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 321 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 321 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

Check warning on line 321 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

var reSerializedJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(actual, settings);
reSerializedJsonString.Should().Contain(expectedGasqualitaet.ToString());
Expand All @@ -342,7 +342,7 @@
settings
);
actual.Should().NotBeNull();
actual.Foo.Should().Be(expectedGasqualitaet);

Check warning on line 345 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 345 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 345 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

Check warning on line 345 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(actual, settings);
reSerializedJsonString.Should().Contain(expectedGasqualitaet.ToString());
Expand Down Expand Up @@ -371,7 +371,7 @@
settings
);
actual.Should().NotBeNull();
actual.Foo.Should().Be(expectedGasqualitaet);

Check warning on line 374 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 374 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 374 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

Check warning on line 374 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

var reSerializedJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(actual, settings);
reSerializedJsonString.Should().Contain(expectedGasqualitaet.ToString());
Expand Down Expand Up @@ -415,7 +415,7 @@
settings
);
actual.Should().NotBeNull();
actual.Foo.Should().Be(expectedVerwendungszweck);

Check warning on line 418 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 418 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / pushfeature

Dereference of a possibly null reference.

Check warning on line 418 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

Check warning on line 418 in BO4ETestProject/TestStringEnumConverter.cs

View workflow job for this annotation

GitHub Actions / unittest (8.0.401)

Dereference of a possibly null reference.

var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(actual, settings);
reSerializedJsonString.Should().Contain(expectedVerwendungszweck?.ToString() ?? "null");
Expand Down Expand Up @@ -763,4 +763,40 @@
var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(result);
reSerializedJsonString.Should().Contain("MEHRMINDERMENGENABRECHNUNG");
}

[TestMethod]
[DataRow("{\"verwendungszwecke\": [{\"zwecke\":\"MEHRMINDERMENGENABRECHNUNG\"}]")]
public void Test_STJ_VerwendungszweckEnum_To_COM_Converter_With_Annotated_Property_At_Zaehlwerk(
string jsonString
)
{
var result = System.Text.Json.JsonSerializer.Deserialize<BO4E.COM.Zaehlwerk>(jsonString);
result
.Should()
.NotBeNull()
.And.Subject.As<BO4E.COM.Zaehlwerk>()
.Verwendungszwecke?.Should()
.NotBeNull()
.And.ContainEquivalentOf(BO4E.ENUM.Verwendungszweck.MEHRMINDERMENGENABRECHNUNG);
var reSerializedJsonString = System.Text.Json.JsonSerializer.Serialize(result);
reSerializedJsonString.Should().Contain("MEHRMINDERMENGENABRECHNUNG");
}

[TestMethod]
[DataRow("{\"verwendungszwecke\": [{\"zwecke\":\"MEHRMINDERMENGENABRECHNUNG\"}]")]
public void Test_Newtonsoft_VerwendungszweckEnum_To_COM_Converter_With_Annotated_Property_At_Zaehlwerk(
string jsonString
)
{
var result = Newtonsoft.Json.JsonConvert.DeserializeObject<BO4E.COM.Zaehlwerk>(jsonString);
result
.Should()
.NotBeNull()
.And.Subject.As<BO4E.COM.Zaehlwerk>()
.Verwendungszwecke?.Should()
.NotBeNull()
.And.ContainEquivalentOf(BO4E.ENUM.Verwendungszweck.MEHRMINDERMENGENABRECHNUNG);
var reSerializedJsonString = Newtonsoft.Json.JsonConvert.SerializeObject(result);
reSerializedJsonString.Should().Contain("MEHRMINDERMENGENABRECHNUNG");
}
}
Loading