diff --git a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/Serializer/ProtobufSerializerTests.cs b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/Serializer/ProtobufSerializerTests.cs index 100081916e7..980a3e45034 100644 --- a/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/Serializer/ProtobufSerializerTests.cs +++ b/test/OpenTelemetry.Exporter.OpenTelemetryProtocol.Tests/Implementation/Serializer/ProtobufSerializerTests.cs @@ -246,7 +246,7 @@ public void WriteStringWithTag_ASCIIString_WritesCorrectly() Assert.Equal(10, buffer[0]); // Tag Assert.Equal(5, buffer[1]); // Length - byte[] expectedContent = Encoding.ASCII.GetBytes("Hello"); + byte[] expectedContent = "Hello"u8.ToArray(); byte[] actualContent = new byte[5]; Array.Copy(buffer, 2, actualContent, 0, 5); Assert.True(expectedContent.SequenceEqual(actualContent)); diff --git a/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsEventListenerTest.cs b/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsEventListenerTest.cs index 0ee7d0dc71e..923e67a80d7 100644 --- a/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsEventListenerTest.cs +++ b/test/OpenTelemetry.Tests/Internal/SelfDiagnosticsEventListenerTest.cs @@ -191,7 +191,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_EnoughSpace() // '\n' will be appended to the original string "abc" after EncodeInBuffer is called. // The byte where '\n' will be placed should not be touched within EncodeInBuffer, so it stays as '\0'. - byte[] expected = Encoding.UTF8.GetBytes("abc\0"); + byte[] expected = "abc\0"u8.ToArray(); AssertBufferOutput(expected, buffer, startPos, endPos + 1); } @@ -204,7 +204,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEnoughSpaceForFullStr // It's a quick estimate by assumption that most Unicode characters takes up to 2 16-bit UTF-16 chars, // which can be up to 4 bytes when encoded in UTF-8. int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos); - byte[] expected = Encoding.UTF8.GetBytes("ab...\0"); + byte[] expected = "ab...\0"u8.ToArray(); AssertBufferOutput(expected, buffer, startPos, endPos + 1); } @@ -214,7 +214,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_NotEvenSpaceForTruncated byte[] buffer = new byte[20]; int startPos = buffer.Length - Ellipses.Length; // Just enough space for "...\n". int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", false, buffer, startPos); - byte[] expected = Encoding.UTF8.GetBytes("...\0"); + byte[] expected = "...\0"u8.ToArray(); AssertBufferOutput(expected, buffer, startPos, endPos + 1); } @@ -233,7 +233,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_EnoughSpace( byte[] buffer = new byte[20]; int startPos = buffer.Length - EllipsesWithBrackets.Length - 6; // Just enough space for "abc" even if "...\n" need to be added. int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos); - byte[] expected = Encoding.UTF8.GetBytes("{abc}\0"); + byte[] expected = "{abc}\0"u8.ToArray(); AssertBufferOutput(expected, buffer, startPos, endPos + 1); } @@ -243,7 +243,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEnoughSpa byte[] buffer = new byte[20]; int startPos = buffer.Length - EllipsesWithBrackets.Length - 5; // Just not space for "...\n". int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos); - byte[] expected = Encoding.UTF8.GetBytes("{ab...}\0"); + byte[] expected = "{ab...}\0"u8.ToArray(); AssertBufferOutput(expected, buffer, startPos, endPos + 1); } @@ -253,7 +253,7 @@ public void SelfDiagnosticsEventListener_EncodeInBuffer_IsParameter_NotEvenSpace byte[] buffer = new byte[20]; int startPos = buffer.Length - EllipsesWithBrackets.Length; // Just enough space for "{...}\n". int endPos = SelfDiagnosticsEventListener.EncodeInBuffer("abc", true, buffer, startPos); - byte[] expected = Encoding.UTF8.GetBytes("{...}\0"); + byte[] expected = "{...}\0"u8.ToArray(); AssertBufferOutput(expected, buffer, startPos, endPos + 1); } diff --git a/test/OpenTelemetry.Tests/Trace/SpanContextTest.cs b/test/OpenTelemetry.Tests/Trace/SpanContextTest.cs index 18b4bd8c73a..5d79157dbd8 100644 --- a/test/OpenTelemetry.Tests/Trace/SpanContextTest.cs +++ b/test/OpenTelemetry.Tests/Trace/SpanContextTest.cs @@ -8,10 +8,10 @@ namespace OpenTelemetry.Trace.Tests; public class SpanContextTest { - private static readonly byte[] FirstTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)'a' }; - private static readonly byte[] SecondTraceIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'0', 0, 0, 0, 0, 0, 0, 0, 0 }; - private static readonly byte[] FirstSpanIdBytes = { 0, 0, 0, 0, 0, 0, 0, (byte)'a' }; - private static readonly byte[] SecondSpanIdBytes = { (byte)'0', 0, 0, 0, 0, 0, 0, 0 }; + private static readonly byte[] FirstTraceIdBytes = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0a"u8.ToArray(); + private static readonly byte[] SecondTraceIdBytes = "\0\0\0\0\0\0\00\0\0\0\0\0\0\0\0"u8.ToArray(); + private static readonly byte[] FirstSpanIdBytes = "\0\0\0\0\0\0\0a"u8.ToArray(); + private static readonly byte[] SecondSpanIdBytes = "0\0\0\0\0\0\0\0"u8.ToArray(); private static readonly SpanContext First = new(