Ejemplo n.º 1
0
        public void ToCharArrayPartialTest()
        {
            var expected = "9c".ToCharArray();
            var data     = new byte[] { 255, 156, 255 };

            var actual = HexConvert.ToCharArray(data, 1, 1, lowerCase: true);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 2
0
        public void ToCharArrayTest()
        {
            var expected = "9c".ToCharArray();
            var data     = new byte[] { 156 };

            var actual = HexConvert.ToCharArray(data, lowerCase: true);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public void BufferToHexConvertTest(int count)
        {
            var expectedBuffer = new byte[count];

            new Random(count).NextBytes(expectedBuffer);
            var expectedHexString = BitConverter.ToString(expectedBuffer).Replace("-", "").ToLowerInvariant();
            var expectedHexBuffer = expectedHexString.ToCharArray();

            // buffer -> hex string
            var hexString = HexConvert.ToString(expectedBuffer, 0, expectedBuffer.Length);

            Assert.Equal(expectedHexString, hexString);
            // buffer -> hex buffer
            var hexBuffer = HexConvert.ToCharArray(expectedBuffer, 0, expectedBuffer.Length);

            Assert.Equal(expectedHexBuffer, hexBuffer);

            // buffer -> hex buffer (copy)
            hexBuffer = new char[expectedHexBuffer.Length];
            HexConvert.Encode(new ArraySegment <byte>(expectedBuffer, 0, expectedBuffer.Length), new ArraySegment <char>(hexBuffer));
            Assert.Equal(expectedHexBuffer, hexBuffer);
        }