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); }
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); }
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); }