public void EncoderTests(int length) { var original = new byte[length]; new Random(1337).NextBytes(original); var expected = Convert.ToBase64String(original); var actual = Codec.Encode(original); Assert.Equal(expected, actual); }
public void Base64CodecEncodeCall_WithNullOrWhiteSpParam_ShouldThrow() { // Arrange var base64Codec = new Base64Codec(); // Act var encodedText = base64Codec.Encode(" "); // should have thrown }
public void Base64Codec_GivenBase64StringDecodeMethodWorks_ShouldPass() { // Arrange var base64Codec = new Base64Codec(); string expectedText = "Hello .NET Nuts and bolts"; // Act var encodedText = base64Codec.Encode(expectedText); var decodedText = base64Codec.Decode(encodedText); // Assert Assert.AreEqual(decodedText, expectedText); }
public void RoundtripNoPadding(int length) { var noPaddingCodec = new Base64Codec(false); var original = new byte[length]; new Random(1337).NextBytes(original); var encoded = noPaddingCodec.Encode(original); Assert.False(encoded.EndsWith('=')); var decoded = noPaddingCodec.Decode(encoded); Assert.Equal(original, decoded); }
public void Base64Codec_GivenValidStringEncodeMethodWorks_ShouldPass() { // Arrange var base64Codec = new Base64Codec(); string expectedText = "Hello .NET Nuts and bolts"; // Act var encodedText = base64Codec.Encode(expectedText); // is it a Base64 string encodedText = encodedText.Trim(); bool isBase64 = (!string.IsNullOrWhiteSpace(encodedText) && encodedText.Length % 4 == 0 && Regex.IsMatch(encodedText, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None)); // Assert Assert.IsTrue(isBase64); }
public void Mine() { _ = _mine.Encode(_source); }
public void EncodeToString() { string result = _codec.Encode(SOURCE); Assert.Equal(TARGET, result); }