Пример #1
0
        public void Given_Base32Converter_When_NullBase32StringIsConvertedToByteArray_Then_ResultIsNull()
        {
            var base32String = default(String);

            var result = Base32Convert.FromBase32String(base32String);

            Assert.Null(result);
        }
Пример #2
0
        public void Given_Base32Converter_When_ABase32StringIsConvertedToByteArray_Then_CorrectDataIsReturned(
            String expected,
            String base32String)
        {
            var result = Base32Convert.FromBase32String(base32String);

            Assert.Equal(expected, Encoding.UTF8.GetString(result));
        }
Пример #3
0
        Given_Base32Converter_When_AStringInUTF8IsConvertedToBase32StringWithoutPaddingAndBack_Then_ItIsTheSameAsTheOriginalString(
            String input)
        {
            var applyPadding = false;

            var base32 = Base32Convert.ToBase32String(Encoding.UTF8.GetBytes(input), applyPadding);
            var result = Base32Convert.FromBase32String(base32);

            Assert.Equal(input, Encoding.UTF8.GetString(result));
        }
Пример #4
0
        static public void EncodeThenDecodeNoPadding(IEnumerator[] a)
        {
            List <byte> octets = new List <byte>();

            for (int j = 1; j < a.Length; j++)
            {
                octets.Add((byte)a[j].Current);
            }

            byte[] result = Base32Convert.FromBase32String(Base32Convert.ToBase32String(octets, Base32FormattingOptions.None), Base32FormattingOptions.None);
            Assert.IsTrue(SameContent(result, octets, Comparer <byte> .Default));
        }
Пример #5
0
 public void Decode_null_throws()
 {
     Assert.Throws <ArgumentNullException>(
         () => Base32Convert.FromBase32String(null, Base32FormattingOptions.InsertTrailingPadding));
 }
Пример #6
0
 static private string DecodeOmitPadding(string s)
 {
     byte[] bytes = Base32Convert.FromBase32String(s, Base32FormattingOptions.None);
     return(Encoding.UTF7.GetString(bytes));
 }
Пример #7
0
 static private string Decode(string s)
 {
     byte[] bytes = Base32Convert.FromBase32String(s, Base32FormattingOptions.InsertTrailingPadding);
     return(Encoding.UTF7.GetString(bytes));
 }
Пример #8
0
 public void DecodeOmitPadding_WrongNumberOfCharacters_6_throws()
 {
     Assert.Throws <ArgumentException>(
         () => Base32Convert.FromBase32String("123456", Base32FormattingOptions.None));
 }
Пример #9
0
 public void DecodeOmitPadding_PaddingCharacter_throws()
 {
     Assert.Throws <ArgumentException>(
         () => Base32Convert.FromBase32String("my======", Base32FormattingOptions.None));
 }
Пример #10
0
 public void DecodeOmitPadding_CharacterNotInAlphabet_throws()
 {
     Assert.Throws <ArgumentException>(
         () => Base32Convert.FromBase32String("#y", Base32FormattingOptions.None));
 }
Пример #11
0
 public void DecodeOmitPadding_null_throws()
 {
     Assert.Throws <ArgumentNullException>(
         () => Base32Convert.FromBase32String(null, Base32FormattingOptions.None));
 }
Пример #12
0
 public void Decode_WrongNumberOfPaddingCharacters_throws()
 {
     Assert.Throws <ArgumentException>(
         () => Base32Convert.FromBase32String("my=====", Base32FormattingOptions.InsertTrailingPadding));
 }
Пример #13
0
 public void Decode_MisplacedPaddingCharacter_throws()
 {
     Assert.Throws <ArgumentException>(
         () => Base32Convert.FromBase32String("m=y======", Base32FormattingOptions.InsertTrailingPadding));
 }
Пример #14
0
 public void Decode_CharacterNotInAlphabet_throws()
 {
     Assert.Throws <ArgumentException>(
         () => Base32Convert.FromBase32String("#y======", Base32FormattingOptions.InsertTrailingPadding));
 }
Пример #15
0
 public void Given_Base32Converter_When_ANonBase32StringIsConvertedToByteArray_Then_AnExceptionIsThrown(String base32String)
 {
     Assert.Throws <ArgumentException>(() => Base32Convert.FromBase32String(base32String));
 }
Пример #16
0
        public void Given_Base32Converter_When_WhitespaceBase32StringIsConvertedToByteArray_Then_ResultIsEmptyArray(String base32String)
        {
            var result = Base32Convert.FromBase32String(base32String);

            Assert.Empty(result);
        }