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

Fix recordings when array is the root of the service response #11543

Merged
merged 1 commit into from
Apr 23, 2020
Merged
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: 2 additions & 1 deletion sdk/core/Azure.Core/tests/RecordSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Linq;
using System.Text;
using System.Text.Json;
using Azure.Core.Pipeline;
using Azure.Core.Testing;
using NUnit.Framework;

Expand All @@ -14,6 +13,8 @@ namespace Azure.Core.Tests
public class RecordSessionTests
{
[TestCase("{\"json\":\"value\"}", "application/json")]
[TestCase("[\"json\", \"value\"]", "application/json")]
[TestCase("[{\"json\":\"value\"}, {\"json\":\"value\"}]", "application/json")]
[TestCase("invalid json", "application/json")]
[TestCase("{ \"json\": \"value\" }", "unknown")]
[TestCase("multi\rline", "application/xml")]
Expand Down
13 changes: 10 additions & 3 deletions sdk/core/Azure.Core/tests/TestFramework/RecordEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@ private void SerializeBody(Utf8JsonWriter jsonWriter, string name, byte[] reques
try
{
using JsonDocument document = JsonDocument.Parse(requestBody);
jsonWriter.WritePropertyName(name.AsSpan());
document.RootElement.WriteTo(jsonWriter);
return;

// 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)
{
jsonWriter.WritePropertyName(name.AsSpan());
document.RootElement.WriteTo(jsonWriter);
return;
}
}
catch (Exception)
{
Expand Down