Esempio n. 1
0
 public static void WriteUInt64_SingleValue_HappyPath(ulong input, string hexExpectedEncoding)
 {
     byte[] expectedEncoding = hexExpectedEncoding.HexToByteArray();
     using var writer = new CborWriter();
     writer.WriteUInt64(input);
     AssertHelper.HexEqual(expectedEncoding, writer.ToArray());
 }
Esempio n. 2
0
 internal static void WriteNull_SingleValue_HappyPath()
 {
     byte[] expectedEncoding = "f6".HexToByteArray();
     using var writer = new CborWriter();
     writer.WriteNull();
     AssertHelper.HexEqual(expectedEncoding, writer.ToArray());
 }
Esempio n. 3
0
 public static void WriteTextString_IndefiniteLength_SingleValue_HappyPath(string[] chunkInputs, string hexExpectedEncoding)
 {
     byte[] expectedEncoding = hexExpectedEncoding.HexToByteArray();
     using var writer = new CborWriter();
     Helpers.WriteChunkedTextString(writer, chunkInputs);
     AssertHelper.HexEqual(expectedEncoding, writer.ToArray());
 }
Esempio n. 4
0
 internal static void WriteSpecialValue_SingleValue_HappyPath(CborSpecialValue input, string hexExpectedEncoding)
 {
     byte[] expectedEncoding = hexExpectedEncoding.HexToByteArray();
     using var writer = new CborWriter();
     writer.WriteSpecialValue(input);
     AssertHelper.HexEqual(expectedEncoding, writer.ToArray());
 }
Esempio n. 5
0
 public static void WriteArray_NestedValues_HappyPath(object[] values, string expectedHexEncoding)
 {
     byte[] expectedEncoding = expectedHexEncoding.HexToByteArray();
     using var writer = new CborWriter();
     Helpers.WriteArray(writer, values);
     byte[] actualEncoding = writer.ToArray();
     AssertHelper.HexEqual(expectedEncoding, actualEncoding);
 }
Esempio n. 6
0
        public static void WriteUnixTimeSeconds_Double_SingleValue_HappyPath(double value, string expectedHexEncoding)
        {
            using var writer = new CborWriter();
            writer.WriteUnixTimeSeconds(value);

            byte[] encoding = writer.ToArray();
            AssertHelper.HexEqual(expectedHexEncoding.HexToByteArray(), encoding);
        }
Esempio n. 7
0
 public static void WriteMap_DuplicateKeys_ShouldSucceed(object[] values, string expectedHexEncoding)
 {
     byte[] expectedEncoding = expectedHexEncoding.HexToByteArray();
     using var writer = new CborWriter();
     Helpers.WriteMap(writer, values);
     byte[] actualEncoding = writer.ToArray();
     AssertHelper.HexEqual(expectedEncoding, actualEncoding);
 }
Esempio n. 8
0
 public static void WriteMap_IndefiniteLength_NestedValues_HappyPath(object[] values, string expectedHexEncoding)
 {
     byte[] expectedEncoding = expectedHexEncoding.HexToByteArray();
     using var writer = new CborWriter();
     Helpers.WriteMap(writer, values, useDefiniteLengthCollections: false);
     byte[] actualEncoding = writer.ToArray();
     AssertHelper.HexEqual(expectedEncoding, actualEncoding);
 }
Esempio n. 9
0
 public static void WriteTag_SingleValue_HappyPath(ulong tag, object value, string hexExpectedEncoding)
 {
     byte[] expectedEncoding = hexExpectedEncoding.HexToByteArray();
     using var writer = new CborWriter();
     writer.WriteTag((CborTag)tag);
     Helpers.WriteValue(writer, value);
     AssertHelper.HexEqual(expectedEncoding, writer.ToArray());
 }
Esempio n. 10
0
        public static void WriteDecimal_SingleValue_HappyPath(string stringValue, string expectedHexEncoding)
        {
            decimal value = decimal.Parse(stringValue, Globalization.CultureInfo.InvariantCulture);

            using var writer = new CborWriter();
            writer.WriteDecimal(value);
            byte[] encoding = writer.ToArray();
            AssertHelper.HexEqual(expectedHexEncoding.HexToByteArray(), encoding);
        }
Esempio n. 11
0
        public static void WriteDateTimeOffset_SingleValue_HappyPath(string valueString, string expectedHexEncoding)
        {
            DateTimeOffset value = DateTimeOffset.Parse(valueString);

            using var writer = new CborWriter();
            writer.WriteDateTimeOffset(value);

            byte[] encoding = writer.ToArray();
            AssertHelper.HexEqual(expectedHexEncoding.HexToByteArray(), encoding);
        }
Esempio n. 12
0
        public static void WriteEncodedValue_ContextScenaria_HappyPath(object value, bool useDefiniteLength, string hexExpectedEncoding)
        {
            using var writer = new CborWriter();

            Helpers.WriteValue(writer, value, useDefiniteLengthCollections: useDefiniteLength);

            string hexEncoding = writer.ToArray().ByteArrayToHex().ToLower();

            Assert.Equal(hexExpectedEncoding, hexEncoding);
        }
Esempio n. 13
0
        public static void WriteInteger_SingleValue_HappyPath(string valueString, string expectedHexEncoding)
        {
            BigInteger value = BigInteger.Parse(valueString);

            using var writer = new CborWriter();
            writer.WriteBigInteger(value);

            byte[] encoding = writer.ToArray();
            AssertHelper.HexEqual(expectedHexEncoding.HexToByteArray(), encoding);
        }
Esempio n. 14
0
 public static void WriteTag_NestedTags_HappyPath(ulong[] tags, object value, string hexExpectedEncoding)
 {
     byte[] expectedEncoding = hexExpectedEncoding.HexToByteArray();
     using var writer = new CborWriter();
     foreach (var tag in tags)
     {
         writer.WriteTag((CborTag)tag);
     }
     Helpers.WriteValue(writer, value);
     AssertHelper.HexEqual(expectedEncoding, writer.ToArray());
 }
Esempio n. 15
0
        public static void Roundtrip_TextString(string?input)
        {
            using var writer = new CborWriter();
            writer.WriteTextString(input);
            byte[] encoding = writer.ToArray();

            var    reader = new CborReader(encoding);
            string result = reader.ReadTextString();

            Assert.Equal(input ?? "", result);
        }
Esempio n. 16
0
        public static void Roundtrip_UInt64(ulong input)
        {
            using var writer = new CborWriter();
            writer.WriteUInt64(input);
            byte[] encoding = writer.ToArray();

            var   reader = new CborReader(encoding);
            ulong result = reader.ReadUInt64();

            Assert.Equal(input, result);
        }
Esempio n. 17
0
        public static void WriteEncodedValue_RootValue_HappyPath(string hexEncodedValue)
        {
            byte[] encodedValue = hexEncodedValue.HexToByteArray();

            using var writer = new CborWriter();
            writer.WriteEncodedValue(encodedValue);

            string hexResult = writer.ToArray().ByteArrayToHex();

            Assert.Equal(hexEncodedValue, hexResult.ToLower());
        }
Esempio n. 18
0
        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 CborReader(encoding);
            byte[] result = reader.ReadByteString();
            AssertHelper.HexEqual(input ?? Array.Empty <byte>(), result);
        }
Esempio n. 19
0
        public static void WriteEncodedValue_IndefiniteLengthByteString_HappyPath()
        {
            using var writer = new CborWriter();

            writer.WriteStartByteStringIndefiniteLength();
            writer.WriteByteString(new byte[] { 1, 1, 1 });
            writer.WriteEncodedValue("43020202".HexToByteArray());
            writer.WriteEndByteStringIndefiniteLength();

            byte[] encoding = writer.ToArray();
            Assert.Equal("5f4301010143020202ff", encoding.ByteArrayToHex().ToLower());
        }
Esempio n. 20
0
        public static void WriteEncodedValue_IndefiniteLengthTextString_HappyPath()
        {
            using var writer = new CborWriter();

            writer.WriteStartTextStringIndefiniteLength();
            writer.WriteTextString("foo");
            writer.WriteEncodedValue("63626172".HexToByteArray());
            writer.WriteEndTextStringIndefiniteLength();

            byte[] encoding = writer.ToArray();
            Assert.Equal("7f63666f6f63626172ff", encoding.ByteArrayToHex().ToLower());
        }
Esempio n. 21
0
        public static void ByteString_Encoding_ShouldContainInputBytes(string?hexInput)
        {
            byte[]? input = hexInput?.HexToByteArray();
#endif
            using var writer = new CborWriter();
            writer.WriteByteString(input);
            byte[] encoding = writer.ToArray();

            int length = input?.Length ?? 0;
            int lengthEncodingLength = GetLengthEncodingLength(length);

            Assert.Equal(lengthEncodingLength + length, encoding.Length);
            AssertHelper.HexEqual(input ?? Array.Empty <byte>(), encoding.Skip(lengthEncodingLength).ToArray());
Esempio n. 22
0
        public static void WriteEncodedValue_NestedValue_HappyPath(string hexEncodedValue)
        {
            byte[] encodedValue = hexEncodedValue.HexToByteArray();

            using var writer = new CborWriter();
            writer.WriteStartArray(3);
            writer.WriteInt64(1);
            writer.WriteEncodedValue(encodedValue);
            writer.WriteTextString("");
            writer.WriteEndArray();

            string hexResult = writer.ToArray().ByteArrayToHex();

            Assert.Equal("8301" + hexEncodedValue + "60", hexResult.ToLower());
        }
Esempio n. 23
0
 public static void ToArray_OnInCompleteValue_ShouldThrowInvalidOperationExceptoin()
 {
     using var writer = new CborWriter();
     Assert.Throws <InvalidOperationException>(() => writer.ToArray());
 }
Esempio n. 24
0
        public static void WriteTag_NoValue_ShouldThrowInvalidOperationException(ulong[] tags)
        {
            using var writer = new CborWriter();

            foreach (ulong tag in tags)
            {
                writer.WriteTag((CborTag)tag);
            }

            InvalidOperationException exn = Assert.Throws <InvalidOperationException>(() => writer.ToArray());

            Assert.Equal("Buffer contains incomplete CBOR document.", exn.Message);
        }