Ejemplo n.º 1
0
        public void ConvertEmptyArrayShouldBeEmptyString()
        {
            var bytes  = new byte [0];
            var result = HexConvert.ToString(bytes);

            Assert.AreEqual(0, result.Length);
        }
Ejemplo n.º 2
0
        public void ConvertFFShouldBeFF()
        {
            var bytes  = new byte [] { 0xff };
            var result = HexConvert.ToString(bytes);

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual("ff", result);
        }
Ejemplo n.º 3
0
        public void ConvertOneByteShouldBeTwoCharacters()
        {
            var bytes  = new byte [] { 0x01 };
            var result = HexConvert.ToString(bytes);

            Assert.AreEqual(2, result.Length);
            Assert.AreEqual("01", result);
        }
Ejemplo n.º 4
0
        public void TestConversion()
        {
            const string originalHash  = "012eab4c54886ca3fa52039afe03dcdf";
            var          byteHash      = HexConvert.FromString(originalHash);
            var          convertedHash = HexConvert.ToString(byteHash);

            Assert.AreEqual(originalHash, convertedHash);
        }
Ejemplo n.º 5
0
        public void ToStringTest()
        {
            var expected = "9c";
            var data     = new byte[] { 156 };

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

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

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

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 7
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);
        }