示例#1
0
        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);
        }
示例#2
0
        public void Base64CodecEncodeCall_WithNullOrWhiteSpParam_ShouldThrow()
        {
            // Arrange
            var base64Codec = new Base64Codec();

            // Act
            var encodedText = base64Codec.Encode(" ");

            // should have thrown
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
 public void Mine()
 {
     _ = _mine.Encode(_source);
 }
示例#7
0
        public void EncodeToString()
        {
            string result = _codec.Encode(SOURCE);

            Assert.Equal(TARGET, result);
        }