Exemplo n.º 1
0
        public static void TryWriteEncoding_DestinationTooSmall_ShouldReturnFalse(object value)
        {
            using var writer = new CborWriter();
            Helpers.WriteValue(writer, value);

            byte[] encoding = writer.GetEncoding();
            byte[] target   = new byte[encoding.Length - 1];

            bool result = writer.TryWriteEncoding(target, out int bytesWritten);

            Assert.False(result);
            Assert.Equal(0, bytesWritten);
            Assert.All(target, b => Assert.Equal(0, b));
        }
Exemplo n.º 2
0
        public static void TryWriteEncoding_HappyPath(object value)
        {
            using var writer = new CborWriter();
            Helpers.WriteValue(writer, value);

            byte[] encoding = writer.GetEncoding();
            byte[] target   = new byte[encoding.Length];

            bool result = writer.TryWriteEncoding(target, out int bytesWritten);

            Assert.True(result);
            Assert.Equal(encoding.Length, bytesWritten);
            Assert.Equal(encoding, target);
        }