Ejemplo n.º 1
0
        public void TestLarge()
        {
            string url =
                "ivrMenu[Name]=Huvudmeny&ivrMenu[ExtensionId]=6&ivrMenu[OpenPhraseId]=267&ivrMenu[ScheduleId]=1&ivrMenu[ClosePhraseId]=268&ivrMenu[CloseActionId]=3&ivrMenu[CloseActionValue]=26&ivrMenu[TimeoutPhraseId]=267&ivrMenu[TimeoutActionId]=&ivrMenu[TimeoutActionValue]=&ivrMenu[TimeoutSeconds]=10&ivrMenu[Digits][1][Digit]=1&ivrMenu[Digits][1][ActionId]=1&ivrMenu[Digits][1][ActionValue]=49&ivrMenu[Digits][2][Digit]=2&ivrMenu[Digits][2][ActionId]=&ivrMenu[Digits][2][ActionValue]=&ivrMenu[Digits][3][Digit]=3&ivrMenu[Digits][3][ActionId]=&ivrMenu[Digits][3][ActionValue]=&ivrMenu[Digits][4][Digit]=4&ivrMenu[Digits][4][ActionId]=&ivrMenu[Digits][4][ActionValue]=&ivrMenu[Digits][5][Digit]=5&ivrMenu[Digits][5][ActionId]=&ivrMenu[Digits][5][ActionValue]=&ivrMenu[Digits][6][Digit]=6&ivrMenu[Digits][6][ActionId]=&ivrMenu[Digits][6][ActionValue]=&ivrMenu[Digits][7][Digit]=7&ivrMenu[Digits][7][ActionId]=&ivrMenu[Digits][7][ActionValue]=&ivrMenu[Digits][8][Digit]=8&ivrMenu[Digits][8][ActionId]=&ivrMenu[Digits][8][ActionValue]=&ivrMenu[Digits][9][Digit]=9&ivrMenu[Digits][9][ActionId]=&ivrMenu[Digits][9][ActionValue]=&ivrMenu[Digits][0][ActionId]=&ivrMenu[Digits][0][ActionValue]=&ivrMenu[Digits][*][ActionId]=&ivrMenu[Digits][*][ActionValue]=&ivrMenu[Digits][#][ActionId]=&ivrMenu[Digits][#][ActionValue]=";

            UrlDecoder decoder = new UrlDecoder();

            Assert.True(decoder.CanParse("application/x-www-form-urlencoded"));
            Assert.False(decoder.CanParse("text/plain"));
            Assert.False(decoder.CanParse(string.Empty));
            Assert.False(decoder.CanParse(null));

            MemoryStream stream = new MemoryStream();

            //string urlencoded = HttpUtility.UrlEncode(url);
            byte[] bytes = Encoding.ASCII.GetBytes(url);
            stream.Write(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);

            HttpInput input = decoder.Decode(stream, "application/x-www-form-urlencoded", Encoding.ASCII);

            Assert.Equal("Huvudmeny", input["ivrMenu"]["Name"].Value);
            Assert.Equal("6", input["ivrMenu"]["ExtensionId"].Value);
            Assert.Equal("267", input["ivrMenu"]["OpenPhraseId"].Value);
            Assert.Equal("1", input["ivrMenu"]["Digits"]["1"]["Digit"].Value);
            Assert.Equal("1", input["ivrMenu"]["Digits"]["1"]["ActionId"].Value);
            Assert.Equal("49", input["ivrMenu"]["Digits"]["1"]["ActionValue"].Value);
        }
Ejemplo n.º 2
0
        public void Test()
        {
            UrlDecoder decoder = new UrlDecoder();

            Assert.True(decoder.CanParse("application/x-www-form-urlencoded"));
            Assert.False(decoder.CanParse("text/plain"));
            Assert.False(decoder.CanParse(string.Empty));
            Assert.False(decoder.CanParse(null));

            MemoryStream stream = new MemoryStream();

            string value = @"user[firstname]=jonas&user[extension][id]=1&myname=jonas&user[firstname]=arne";

            // it's always VALUES and not the complete string that should be encoded.
            //string urlencoded = HttpUtility.UrlEncode(@"user[firstname]=jonas&user[extension][id]=1&myname=jonas&user[firstname]=arne");
            byte[] bytes = Encoding.ASCII.GetBytes(value);
            stream.Write(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);

            HttpInput input = decoder.Decode(stream, "application/x-www-form-urlencoded", Encoding.ASCII);

            Assert.Equal("jonas", input["myname"].Value);
            Assert.Equal(2, input["user"]["firstname"].Count);
            Assert.Equal("jonas", input["user"]["firstname"].Values[0]);
            Assert.Equal("arne", input["user"]["firstname"].Values[1]);
            Assert.Equal("1", input["user"]["extension"]["id"].Value);
            Assert.Null(input["unknow"].Value);
            Assert.Equal(HttpInputItem.Empty, input["unknown"]);
        }
Ejemplo n.º 3
0
        public void TestLogin()
        {
            string url =
                "email=somewhere%40gauffin.com&password=myPassWord";

            UrlDecoder decoder = new UrlDecoder();

            Assert.True(decoder.CanParse("application/x-www-form-urlencoded"));
            Assert.False(decoder.CanParse("text/plain"));
            Assert.False(decoder.CanParse(string.Empty));
            Assert.False(decoder.CanParse(null));

            MemoryStream stream     = new MemoryStream();
            string       urlencoded = url;

            byte[] bytes = Encoding.ASCII.GetBytes(urlencoded);
            stream.Write(bytes, 0, bytes.Length);
            stream.Seek(0, SeekOrigin.Begin);

            HttpInput input = decoder.Decode(stream, "application/x-www-form-urlencoded", Encoding.ASCII);

            Assert.Equal("*****@*****.**", input["email"].Value);
            Assert.Equal("myPassWord", input["password"].Value);
        }