diff --git a/sdk/core/Azure.Core/tests/RecordSessionTests.cs b/sdk/core/Azure.Core/tests/RecordSessionTests.cs index 014bf0620272..3219a40f838c 100644 --- a/sdk/core/Azure.Core/tests/RecordSessionTests.cs +++ b/sdk/core/Azure.Core/tests/RecordSessionTests.cs @@ -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; @@ -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")] diff --git a/sdk/core/Azure.Core/tests/TestFramework/RecordEntry.cs b/sdk/core/Azure.Core/tests/TestFramework/RecordEntry.cs index a4bf2d1bbaf2..759bf1f0ee38 100644 --- a/sdk/core/Azure.Core/tests/TestFramework/RecordEntry.cs +++ b/sdk/core/Azure.Core/tests/TestFramework/RecordEntry.cs @@ -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) {