Skip to content

Commit

Permalink
Test Framework - Don't serialize string Json element directly to sess…
Browse files Browse the repository at this point in the history
…ion (#15007)
  • Loading branch information
JoshLove-msft authored Sep 9, 2020
1 parent 6609ff9 commit e240204
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions sdk/core/Azure.Core.TestFramework/src/RecordEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ private void SerializeBody(Utf8JsonWriter jsonWriter, string name, byte[] reques

// We use array as a wrapper for string based serialization
// so if the root is an array we can't write it directly
// fallback to generic string writing
if (document.RootElement.ValueKind != JsonValueKind.Array)
// fallback to generic string writing. Also, if the root is a string
// we don't want to write it directly, as this would make matching
// not won't work in libraries that allow passing JSON as a string.
if (document.RootElement.ValueKind != JsonValueKind.Array &&
document.RootElement.ValueKind != JsonValueKind.String)
{
// Make sure we can replay JSON is exactly the same as the source
// for the case where service response was pre-formatted
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/tests/RecordSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class RecordSessionTests
[TestCase("{\"json\" :\"value\"}", "application/json")]
[TestCase("[\"json\", \"value\"]", "application/json")]
[TestCase("[{\"json\":\"value\"}, {\"json\":\"value\"}]", "application/json")]
[TestCase("\"\"", "application/json")]
[TestCase("invalid json", "application/json")]
[TestCase("{ \"json\": \"value\" }", "unknown")]
[TestCase("multi\rline", "application/xml")]
Expand Down

0 comments on commit e240204

Please sign in to comment.