Skip to content

Commit c4f4e11

Browse files
CopiloteNeRGy164
andcommitted
Fix BaseTypes deserialization with System.Text.Json (#6)
* Fix BaseTypes deserialization with System.Text.Json - add BaseTypes parameter to JsonConstructor Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: eNeRGy164 <10671831+eNeRGy164@users.noreply.github.com>
1 parent 7bd1772 commit c4f4e11

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

src/DendroDocs.Shared/Descriptions/TypeDescription.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public TypeDescription(
1616
IReadOnlyList<MethodDescription> methods,
1717
IReadOnlyList<EnumMemberDescription> enumMembers,
1818
IReadOnlyList<EventDescription> events,
19-
List<AttributeDescription> attributes
19+
List<AttributeDescription> attributes,
20+
List<string> baseTypes
2021
)
2122
: this(type, fullName)
2223
{
@@ -27,6 +28,7 @@ List<AttributeDescription> attributes
2728
if (enumMembers is not null) this.enumMembers = [.. enumMembers];
2829
if (events is not null) this.events = [.. events];
2930
if (attributes is not null) this.Attributes.AddRange(attributes);
31+
if (baseTypes is not null) this.BaseTypes.AddRange(baseTypes);
3032
}
3133

3234
[Newtonsoft.Json.JsonProperty(Order = 1, PropertyName = nameof(Fields))]

tests/DendroDocs.Shared.Tests/Serialization/NewtonsoftDeserializationTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,26 @@ public void AStatementInASwitchSectionShouldHaveTheSwitchSectionAsParent()
369369
var @switch = (Switch)types[0].Methods[0].Statements[0];
370370
@switch.Sections[0].Statements[0].Parent.ShouldBe(@switch.Sections[0]);
371371
}
372+
373+
[TestMethod]
374+
public void BaseTypes_Should_BeDeserializedCorrectly()
375+
{
376+
// Assign
377+
var json = @"[{
378+
""FullName"": ""Pitstop.TimeService.Events.DayHasPassed"",
379+
""BaseTypes"": [
380+
""Pitstop.Infrastructure.Messaging.Event"",
381+
""System.Object""
382+
]
383+
}]";
384+
385+
// Act
386+
var types = JsonConvert.DeserializeObject<List<TypeDescription>>(json, JsonDefaults.DeserializerSettings())!;
387+
388+
// Assert
389+
types.Count.ShouldBe(1);
390+
types[0].BaseTypes.Count.ShouldBe(2);
391+
types[0].BaseTypes.ShouldContain("Pitstop.Infrastructure.Messaging.Event");
392+
types[0].BaseTypes.ShouldContain("System.Object");
393+
}
372394
}

tests/DendroDocs.Shared.Tests/Serialization/TextJsonDeserializationTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,29 @@ public void MethodWithoutReturnTypeInJson_Should_DefaultToVoid()
455455
types[0].Methods[0].Name.ShouldBe("VoidMethod");
456456
types[0].Methods[0].ReturnType.ShouldBe("void");
457457
}
458+
459+
[TestMethod]
460+
public void BaseTypes_Should_BeDeserializedCorrectly()
461+
{
462+
// Assign
463+
var json =
464+
"""
465+
[{
466+
"FullName": "Pitstop.TimeService.Events.DayHasPassed",
467+
"BaseTypes": [
468+
"Pitstop.Infrastructure.Messaging.Event",
469+
"System.Object"
470+
]
471+
}]
472+
""";
473+
474+
// Act
475+
var types = JsonSerializer.Deserialize<List<TypeDescription>>(json, JsonDefaults.DeserializerOptions())!;
476+
477+
// Assert
478+
types.Count.ShouldBe(1);
479+
types[0].BaseTypes.Count.ShouldBe(2);
480+
types[0].BaseTypes.ShouldContain("Pitstop.Infrastructure.Messaging.Event");
481+
types[0].BaseTypes.ShouldContain("System.Object");
482+
}
458483
}

0 commit comments

Comments
 (0)