public static void WriteTextString_IndefiniteLength_ImbalancedWrites_ShouldThrowInvalidOperationException(string opName)
        {
            var writer = new CborWriter();

            writer.WriteStartTextString();
            Assert.Throws <InvalidOperationException>(() => Helpers.ExecOperation(writer, opName));
        }
Esempio n. 2
0
        public static void WriteEncodedValue_BadIndefiniteLengthStringValue_ShouldThrowInvalidOperationException()
        {
            var writer = new CborWriter();

            writer.WriteStartTextString();
            Assert.Throws <InvalidOperationException>(() => writer.WriteEncodedValue(new byte[] { 0x01 }));
        }
            public static void ExecOperation(CborWriter writer, string op)
            {
                switch (op)
                {
                case nameof(writer.WriteInt64): writer.WriteInt64(42); break;

                case nameof(writer.WriteByteString): writer.WriteByteString(Array.Empty <byte>()); break;

                case nameof(writer.WriteTextString): writer.WriteTextString(""); break;

                case nameof(writer.WriteStartTextString): writer.WriteStartTextString(); break;

                case nameof(writer.WriteStartByteString): writer.WriteStartByteString(); break;

                case nameof(writer.WriteStartArray): writer.WriteStartArray(); break;

                case nameof(writer.WriteStartMap): writer.WriteStartMap(); break;

                case nameof(writer.WriteEndByteString): writer.WriteEndByteString(); break;

                case nameof(writer.WriteEndTextString): writer.WriteEndTextString(); break;

                case nameof(writer.WriteEndArray): writer.WriteEndArray(); break;

                case nameof(writer.WriteEndMap): writer.WriteEndMap(); break;

                default: throw new Exception($"Unrecognized CborWriter operation name {op}");
                }
            }
 public static void WriteChunkedTextString(CborWriter writer, string[] chunks)
 {
     writer.WriteStartTextString();
     foreach (string chunk in chunks)
     {
         writer.WriteTextString(chunk);
     }
     writer.WriteEndTextString();
 }
Esempio n. 5
0
        public static void WriteEncodedValue_IndefiniteLengthTextString_HappyPath()
        {
            using var writer = new CborWriter(encodeIndefiniteLengths: true);

            writer.WriteStartTextString();
            writer.WriteTextString("foo");
            writer.WriteEncodedValue("63626172".HexToByteArray());
            writer.WriteEndTextString();

            byte[] encoding = writer.GetEncoding();
            Assert.Equal("7f63666f6f63626172ff", encoding.ByteArrayToHex().ToLower());
        }
        public static void WriteStartTextString_NoPatching_UnsupportedConformance_ShouldThrowInvalidOperationException(CborConformanceLevel conformanceLevel)
        {
            var writer = new CborWriter(conformanceLevel, convertIndefiniteLengthEncodings: false);

            Assert.Throws <InvalidOperationException>(() => writer.WriteStartTextString());
        }