From 479edf90a5b20b0b6a93ea3e6a95436468a522ad Mon Sep 17 00:00:00 2001 From: Marton Balassa <7115274+BalassaMarton@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:37:54 +0100 Subject: [PATCH] Fixed test for Utf8JsonReaderExtensions --- .../dotnet/src/Core/Protocol/Json/ThrowHelper.cs | 4 +++- .../src/Core/Protocol/Json/Utf8JsonReaderExtensions.cs | 2 +- .../Protocol/Json/Utf8JsonReaderExtensions.Tests.cs | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/messaging/dotnet/src/Core/Protocol/Json/ThrowHelper.cs b/src/messaging/dotnet/src/Core/Protocol/Json/ThrowHelper.cs index 317b83e6a..da8abbf23 100644 --- a/src/messaging/dotnet/src/Core/Protocol/Json/ThrowHelper.cs +++ b/src/messaging/dotnet/src/Core/Protocol/Json/ThrowHelper.cs @@ -10,11 +10,13 @@ // or implied. See the License for the specific language governing permissions // and limitations under the License. +using System.Text.Json; + namespace MorganStanley.ComposeUI.Messaging.Protocol.Json; internal static class ThrowHelper { - public static InvalidOperationException StringExpected() => new InvalidOperationException("String expected"); + public static InvalidOperationException StringExpected(JsonTokenType actualTokenType) => new InvalidOperationException($"String expected (actual: {actualTokenType})"); public static ArgumentException DestinationTooShort(string paramName) => new ArgumentException("The destination buffer is too short", paramName); diff --git a/src/messaging/dotnet/src/Core/Protocol/Json/Utf8JsonReaderExtensions.cs b/src/messaging/dotnet/src/Core/Protocol/Json/Utf8JsonReaderExtensions.cs index 4e13322cf..6d69a77dd 100644 --- a/src/messaging/dotnet/src/Core/Protocol/Json/Utf8JsonReaderExtensions.cs +++ b/src/messaging/dotnet/src/Core/Protocol/Json/Utf8JsonReaderExtensions.cs @@ -44,7 +44,7 @@ public static int CopyString(this ref Utf8JsonReader reader, Span utf8Dest { if (reader.TokenType is not (JsonTokenType.String or JsonTokenType.PropertyName)) { - throw ThrowHelper.StringExpected(); + throw ThrowHelper.StringExpected(reader.TokenType); } var valueLength = reader.HasValueSequence diff --git a/src/messaging/dotnet/test/Core.Tests/Protocol/Json/Utf8JsonReaderExtensions.Tests.cs b/src/messaging/dotnet/test/Core.Tests/Protocol/Json/Utf8JsonReaderExtensions.Tests.cs index 1df838170..703a00d90 100644 --- a/src/messaging/dotnet/test/Core.Tests/Protocol/Json/Utf8JsonReaderExtensions.Tests.cs +++ b/src/messaging/dotnet/test/Core.Tests/Protocol/Json/Utf8JsonReaderExtensions.Tests.cs @@ -20,7 +20,7 @@ namespace MorganStanley.ComposeUI.Messaging.Protocol.Json; public class Utf8JsonReaderExtensionsTests { - [Theory(Skip ="ci fail")] + [Theory] [ClassData(typeof(CopyStringTheoryData))] public void CopyString_writes_the_unescaped_UTF8_string_to_the_buffer(CopyStringTestData testData) { @@ -55,10 +55,10 @@ public Utf8JsonReader CreateReader() reader = new Utf8JsonReader(MemoryHelper.CreateMultipartSequence(_utf8Buffers)); } - Debug.Assert(reader.Read()); - Debug.Assert(reader.TokenType == JsonTokenType.StartArray); - Debug.Assert(reader.Read()); - Debug.Assert(reader.TokenType == JsonTokenType.String); + reader.Read().Should().Be(true); + reader.TokenType.Should().Be(JsonTokenType.StartArray); + reader.Read().Should().Be(true); + reader.TokenType.Should().Be(JsonTokenType.String); return reader; }