Exemple #1
0
        public void ToHex_FromHex_Roundtrips_UriSafe(string input)
        {
            byte[] data    = Encoding.UTF8.GetBytes(input);
            string encoded = EncodingUtilities.ToHex(data);

            byte[] output = EncodingUtilities.FromHex(encoded);
            string actual = Encoding.UTF8.GetString(output);

            Assert.Equal(input, actual);
        }
Exemple #2
0
        private static void Base64RoundTrip(string input, bool uriSafe)
        {
            byte[] data    = Encoding.UTF8.GetBytes(input);
            string encoded = EncodingUtilities.ToBase64(data, uriSafe);

            byte[] output = EncodingUtilities.FromBase64(encoded);
            string actual = Encoding.UTF8.GetString(output);

            Assert.Equal(input, actual);
        }
Exemple #3
0
        public void ToHex_ConvertsCorrectly(string input)
        {
            // Arrange
            byte[] bytes    = Encoding.UTF8.GetBytes(input);
            string expected = ToExpectedHex(bytes);

            // Act
            string actual = EncodingUtilities.ToHex(bytes);

            // Assert
            Assert.Equal(expected, actual);
        }
Exemple #4
0
        public void FromHex_ConvertsCorrectly(string input)
        {
            // Arrange
            byte[] expected = Encoding.UTF8.GetBytes(input);
            string data1    = ToExpectedHex(expected).ToUpperInvariant();
            string data2    = ToExpectedHex(expected).ToLowerInvariant();

            // Act
            byte[] actual1 = EncodingUtilities.FromHex(data1);
            byte[] actual2 = EncodingUtilities.FromHex(data2);

            // Assert
            Assert.Equal(expected, actual1);
            Assert.Equal(expected, actual2);
        }
Exemple #5
0
        public void FromHex_Throws_OnOddInput(string invalid)
        {
            InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => EncodingUtilities.FromHex(invalid));

            Assert.Contains(string.Format("Input is not a valid hex-encoded string: '{0}'. Please provide a valid hex-encoded string.", invalid), ex.Message);
        }