Skip to content

Commit 39150ea

Browse files
authored
Merge pull request #22 from MTESSDev/bugfix/json-document-wrongtoken
fix jsondocument could not be serialized as string
2 parents 834ad93 + 2cc9e13 commit 39150ea

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/MDAT/MDAT.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Company>MESS</Company>
1111
<PackageProjectUrl>https://github.com/MTESSDev/mdAT</PackageProjectUrl>
1212
<RepositoryUrl>https://github.com/MTESSDev/mdAT</RepositoryUrl>
13-
<Version>1.4.0</Version>
13+
<Version>1.4.1</Version>
1414
<Description>Markdown Auto-Tests for .net 6+, based on MSTestsV2 DataSource.</Description>
1515
</PropertyGroup>
1616

src/MDAT/Resolver/JsonDocumentConverter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public override void WriteJson(JsonWriter writer, object? value, Newtonsoft.Json
1414
{
1515
if (value is JsonDocument netJson)
1616
{
17-
writer.WriteValue(netJson.RootElement.ToString());
17+
using var reader = new JsonTextReader(new StringReader(netJson.RootElement.ToString()));
18+
writer.WriteToken(reader); // Écrit correctement le contenu JSON dans le flux
1819
}
1920
}
2021

src/MDATTests/MarkdownTestAttributeTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,19 @@ public async Task Md_Extraction_test(Expected expected)
244244
/// </summary>
245245
[TestMethod]
246246
[MarkdownTest("~\\Tests\\md-json-document-test.md")]
247-
public async Task Md_JsonDocument_test(JsonDocument jsonDocument, Expected expected)
247+
public async Task Md_JsonDocument_test(JsonDocument jsonDocument, Test1 test1, Expected expected, Expected expected2)
248248
{
249249
object value = await Verify.Assert(() =>
250250
Task.FromResult(jsonDocument), expected);
251251

252+
object value2 = await Verify.Assert(() =>
253+
Task.FromResult(test1), expected2);
254+
255+
}
256+
257+
public class Test1
258+
{
259+
public JsonDocument JsonDocument { get; set; }
252260
}
253261

254262
/// <summary>

src/MDATTests/Tests/md-json-document-test.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Description
99

1010
``````yaml
1111
jsonDocument: {"demo": "json"}
12+
test1:
13+
JsonDocument: {"demo": "json"}
1214
expected:
1315
name: null
1416
generateExpectedData: null
@@ -17,4 +19,14 @@ expected:
1719
jsonPath: $
1820
allowAdditionalProperties: false
1921
data: {"demo": "json"}
22+
expected2:
23+
name: null
24+
generateExpectedData: null
25+
verify:
26+
- type: match
27+
jsonPath: $
28+
allowAdditionalProperties: false
29+
data:
30+
JsonDocument:
31+
demo: json
2032
``````

0 commit comments

Comments
 (0)