Пример #1
0
        public void NullIsReturnedIfNullIsPassedIn()
        {
            // when
            var obtained = PercentEncoder.Encode(null, Encoding.ASCII);

            // then
            Assert.That(obtained, Is.Null);
        }
Пример #2
0
        public void EmptyStringIsHandledSeparately()
        {
            // when
            var obtained = PercentEncoder.Encode(string.Empty, Encoding.ASCII);

            // then
            Assert.That(obtained, Is.EqualTo(string.Empty));
        }
Пример #3
0
        public void Rfc3986UnreservedCharactersAreNotEncoded()
        {
            // when
            var obtained = PercentEncoder.Encode(UnreservedCharacters, Encoding.UTF8);

            // then
            Assert.That(obtained, Is.EqualTo(UnreservedCharacters));
        }
Пример #4
0
        public void CharactersOutsideOfAsciiRangeAreEncodedFirst()
        {
            // when
            var obtained = PercentEncoder.Encode("aösÖ€dÁF", Encoding.UTF8);

            // then
            var expected = "a%C3%B6s%C3%96%E2%82%ACd%C3%81F";

            Assert.That(obtained, Is.EqualTo(expected));
        }
Пример #5
0
        public void MixingReservedAndUnreservedCharactersWorks()
        {
            // when
            var obtained = PercentEncoder.Encode("a+bc()~/\\&0_", Encoding.UTF8);

            // then
            var expected = "a%2Bbc%28%29~%2F%5C%260_"; // precomputed using Python

            Assert.That(obtained, Is.EqualTo(expected));
        }
Пример #6
0
        public void ReservedCharactersArePercentEncoded()
        {
            // when
            var obtained = PercentEncoder.Encode("+()/\\&%$#@!`?<>[]{}", Encoding.UTF8);

            // then
            var expected = "%2B%28%29%2F%5C%26%25%24%23%40%21%60%3F%3C%3E%5B%5D%7B%7D"; // precomputed using Python

            Assert.That(obtained, Is.EqualTo(expected));
        }
Пример #7
0
        public void ItIsPossibleToMarkAdditionalCharactersAsReserved()
        {
            // when
            var additionalReservedCharacters = new [] { '€', '0', '_' };
            var obtained = PercentEncoder.Encode("0123456789-._~", Encoding.UTF8, additionalReservedCharacters);

            // then
            var expected = "%30123456789-.%5F~";

            Assert.That(obtained, Is.EqualTo(expected));
        }