public static void TryPeek_EmptyBuffer_ShouldReturnFalse() { var reader = new CborValueReader(ReadOnlySpan <byte> .Empty); bool result = reader.TryPeek(out CborInitialByte _); Assert.False(result); }
public static void Peek_SingleByteBuffer_ShouldReturnSameByte(byte initialByte) { ReadOnlySpan <byte> buffer = stackalloc byte[] { initialByte }; var reader = new CborValueReader(buffer); CborInitialByte header = reader.Peek(); Assert.Equal(initialByte, header.InitialByte); }
public static void Peek_EmptyBuffer_ShouldThrowInvalidOperationException() { Assert.Throws <InvalidOperationException>(() => { var reader = new CborValueReader(ReadOnlySpan <byte> .Empty); reader.Peek(); }); }
public static void ReadCborNegativeIntegerEncoding_SingleValue_HappyPath(ulong expectedResult, string hexEncoding) { byte[] data = hexEncoding.HexToByteArray(); var reader = new CborValueReader(data); ulong actualResult = reader.ReadCborNegativeIntegerEncoding(); Assert.Equal(expectedResult, actualResult); }
public static void ReadInt64_SingleValue_ShouldSupportNonCanonicalEncodings(string hexEncoding) { byte[] data = hexEncoding.HexToByteArray(); var reader = new CborValueReader(data); long result = reader.ReadInt64(); Assert.Equal(-24, result); }
public static void ReadByteString_SingleValue_HappyPath(string hexExpectedValue, string hexEncoding) { byte[] encoding = hexEncoding.HexToByteArray(); byte[] expectedValue = hexExpectedValue.HexToByteArray(); var reader = new CborValueReader(encoding); byte[] output = reader.ReadByteString(); Assert.Equal(expectedValue, output); }
public static void TryPeek_SingleByteBuffer_ShouldReturnSameByte(byte initialByte) { ReadOnlySpan <byte> buffer = stackalloc byte[] { initialByte }; var reader = new CborValueReader(buffer); bool result = reader.TryPeek(out CborInitialByte header); Assert.True(result); Assert.Equal(initialByte, header.InitialByte); }
public static void ReadInt64_IndefiniteLengthIntegers_ShouldThrowNotImplementedException(string hexEncoding) { byte[] data = hexEncoding.HexToByteArray(); Assert.Throws <NotImplementedException>(() => { var reader = new CborValueReader(data); reader.ReadInt64(); }); }
public static void ReadCborNegativeIntegerEncoding_InvalidData_ShouldThrowFormatException(string hexEncoding) { byte[] data = hexEncoding.HexToByteArray(); Assert.Throws <FormatException>(() => { var reader = new CborValueReader(data); reader.ReadCborNegativeIntegerEncoding(); }); }
public static void ReadUInt64_OutOfRangeValues_ShouldThrowOverflowException(string hexEncoding) { byte[] data = hexEncoding.HexToByteArray(); Assert.Throws <OverflowException>(() => { var reader = new CborValueReader(data); reader.ReadUInt64(); }); }
public static void TryReadByteString_SingleValue_HappyPath(string hexExpectedValue, string hexEncoding) { byte[] buffer = new byte[32]; byte[] encoding = hexEncoding.HexToByteArray(); byte[] expectedValue = hexExpectedValue.HexToByteArray(); var reader = new CborValueReader(encoding); bool result = reader.TryReadByteString(buffer, out int bytesWritten); Assert.True(result); Assert.Equal(expectedValue.Length, bytesWritten); Assert.Equal(expectedValue, buffer[..bytesWritten]);
public static void Roundtrip_UInt64(ulong input) { using var writer = new CborWriter(); writer.WriteUInt64(input); byte[] encoding = writer.ToArray(); var reader = new CborValueReader(encoding); ulong result = reader.ReadUInt64(); Assert.Equal(input, result); }
public static void Roundtrip_TextString(string?input) { using var writer = new CborWriter(); writer.WriteTextString(input); byte[] encoding = writer.ToArray(); var reader = new CborValueReader(encoding); string result = reader.ReadTextString(); Assert.Equal(input ?? "", result); }
public static void ReadCborNegativeIntegerEncoding_InvalidTypes_ShouldThrowInvalidOperationException(string hexEncoding) { byte[] data = hexEncoding.HexToByteArray(); InvalidOperationException exn = Assert.Throws <InvalidOperationException>(() => { var reader = new CborValueReader(data); reader.ReadCborNegativeIntegerEncoding(); }); Assert.Equal("Data item major type mismatch.", exn.Message); }
public static void Roundtrip_ByteString(string?hexInput) { byte[]? input = hexInput?.HexToByteArray(); #endif using var writer = new CborWriter(); writer.WriteByteString(input); byte[] encoding = writer.ToArray(); var reader = new CborValueReader(encoding); byte[] result = reader.ReadByteString(); AssertHelper.HexEqual(input ?? Array.Empty <byte>(), result); }