Ejemplo n.º 1
0
        public async Task Test1()
        {
            HttpOption option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/ajax/ns/TestFile/Download1.aspx HTTP/1.1
Host: www.fish-mvc-demo.com
Connection: keep-alive
Content-Length: 171
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Origin: http://www.fish-mvc-demo.com
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 OPR/31.0.1889.174
Content-Type: application/x-www-form-urlencoded
Referer: http://www.fish-mvc-demo.com/Pages/Demo/TestFileDownload.aspx
Accept-Encoding: gzip, deflate, lzma
Accept-Language: zh-CN,zh;q=0.8

filename=%E4%B8%AD%E6%96%87%E6%B1%89%E5%AD%97%E6%97%A0%E4%B9%B1%E7%A0%81%7E%21%40%23%24%25%5E%26*%28%29_%2B-%3D%3C%3E%3F%7C.txt&submit=%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6");

            string headerValue = null;

            option.ReadResponseAction = (response) => headerValue = response.Headers["Content-Disposition"];

            string returnText = await option.SendAsync <string>();

            string expected = Guid.Empty.ToString();

            Assert.AreEqual(expected, returnText);
            Assert.IsTrue(System.Web.HttpUtility.UrlDecode(headerValue).IndexOf("中文汉字无乱码") > 0);
        }
Ejemplo n.º 2
0
        private async Task Test4Internal(string url)
        {
            string input = @"
Address=武汉
Address=上海
Address=武汉
Address=
Address=
Age=20
Age=20
Age=20
Age=
Age=
[email protected]
Email=
[email protected]
Email=
Email=
Name=A1
Name=A2
Name=A3
Name=
Name=A5
Tel=12345678
Tel=22222222
Tel=
Tel=
Tel=12345678
batchAddCustomer=保存客户资料";

            HttpOption option = new HttpOption {
                Url    = url,
                Method = "POST",
                Data   = StringToFormDataCollection(input)
            };

            string actual = await option.SendAsync <string>();

            string expected = @"
    <Customer>
        <Name>A1</Name>
        <Age>20</Age>
        <Address>武汉</Address>
        <Tel>12345678</Tel>
        <Email>[email protected]</Email>
    </Customer>
    <Customer>
        <Name>A2</Name>
        <Age>20</Age>
        <Address>上海</Address>
        <Tel>22222222</Tel>
        <Email />
    </Customer>
</ArrayOfCustomer>".Trim();

            Assert.IsTrue(actual.EndsWith(expected));
        }
Ejemplo n.º 3
0
        public async Task TestAllUser()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/Pages/TestAuthorize/AllUser.aspx",
                Method = "GET"
            };

            string actual = await option.SendAsync <string>();

            Assert.IsTrue(actual.IndexOf("此页面可由所有用户访问。") > 0);
        }
Ejemplo n.º 4
0
        public async Task <PageResult> GetWebsiteTitles(HttpContext context, string urls)
        {
            context.WriteHeader("action-before-await");

            context.WriteHeader("---------------------------------------------------------");


            TestTaskPageViewData viewData = new TestTaskPageViewData();

            viewData.Input = urls;

            if (string.IsNullOrEmpty(urls))
            {
                viewData.Input = @"
http://cn.bing.com/
http://email.163.com/
http://www.aliyun.com/
http://baike.baidu.com/
http://www.dingtalk.com/
http://www.taobao.com/
http://www.tmall.com/";
            }
            else
            {
                string[] urlArray = urls.SplitTrim('\r', '\n');
                List <KeyValuePair <string, string> > list = new List <KeyValuePair <string, string> >(urlArray.Length);

                foreach (string url in urlArray)
                {
                    try {
                        HttpOption option = new HttpOption {
                            Url     = url,
                            Timeout = 2000
                        };
                        string text = await option.SendAsync <string>();

                        context.WriteHeader("HttpClient.SendAsync<string>(url)--after-await");

                        string title = GetHtmlTitle(text) ?? "-----------------";

                        list.Add(new KeyValuePair <string, string>(url, title));
                    }
                    catch (Exception ex) {
                        list.Add(new KeyValuePair <string, string>(url, ex.GetBaseException().Message));
                    }

                    viewData.Result = list;
                }
            }

            context.WriteHeader("action-after-await-return");

            return(new PageResult(null, viewData));
        }
Ejemplo n.º 5
0
        public async Task Test2()
        {
            System.IO.FileInfo file1 = new System.IO.FileInfo("Newtonsoft.Json.dll");
            System.IO.FileInfo file2 = new System.IO.FileInfo("ClownFish.Web.dll");

            HttpOption option = new HttpOption {
                Method = "POST",
                Url    = "http://www.fish-mvc-demo.com/Ajax/ns/UploadFile/Test1.aspx",
                Data   = new {
                    a = file1,
                    b = file2,
                    c = 2,
                    d = 5
                }
            };


            string actual = await option.SendAsync <string>();

//{
//  "file1": {
//	"name": "E:\\ProjectFiles\\ClownFish.Web\\ClownFish.Web3\\Test\\ClownFish.TestApplication1\\bin\\Newtonsoft.Json.dll",
//	"lenght": 430080
//  },
//  "file2": {
//	"name": "E:\\ProjectFiles\\ClownFish.Web\\ClownFish.Web3\\Test\\ClownFish.TestApplication1\\bin\\ClownFish.Web.dll",
//	"lenght": 165888
//  },
//  "sum": 595975
//}
            string expected = (2 + 5 + file1.Length + file2.Length).ToString();

            Assert.IsTrue(actual.IndexOf(expected) > 0);



            HttpOption option2 = new HttpOption {
                Method = "POST",
                Url    = "http://www.fish-mvc-demo.com/Ajax/ns/UploadFile/Test2.aspx",
                Data   = new {
                    a = file1,
                    b = file2,
                    c = 2,
                    d = 5
                }
            };


            string actual2 = await option2.SendAsync <string>();

            Assert.AreEqual(actual2, actual);
        }
Ejemplo n.º 6
0
        public async Task Test1()
        {
            HttpOption option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/Ajax/ns/Demo/TestGuid2.aspx HTTP/1.1

a=8679b2c7-75e5-47b7-86db-aa60addc10ab");

            // Action 要求以 PUT 方式提交,所以应该是404错误。

            int stateCode = await option.GetStatusCode();

            Assert.AreEqual(404, stateCode);


            option = HttpOption.FromRawText(@"
PUT http://www.fish-mvc-demo.com/Ajax/ns/Demo/TestGuid2.aspx HTTP/1.1

a=8679b2c7-75e5-47b7-86db-aa60addc10ab");

            string actual = await option.SendAsync <string>();

            string expected = "8679b2c7-75e5-47b7-86db-aa60addc10ab";

            Assert.AreEqual(expected, actual);



            option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/Ajax/ns/Demo/TestContextDataAttribute.aspx HTTP/1.1
User-Agent: Hello-Fish

a=8679b2c7-75e5-47b7-86db-aa60addc10ab");

            actual = await option.SendAsync <string>();

            expected = "Hello-Fish";
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 7
0
        public async Task TestSubmitNumber()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-mvc-demo.com/Ajax/ns/Demo/TestEnum.aspx?submit=submit",
                Data   = new { week = "2" },
                Method = "GET"
            };

            string actual = await option.SendAsync <string>();

            string expected = "Tuesday";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public async Task TestAutoFindAction1()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/api/ns/TestAutoAction/submit.aspx",
                Method = "POST",
                Data   = new { Base64 = "yes", input = "Fish Li" }
            };

            string actual = await option.SendAsync <string>();

            string expected = "RmlzaCBMaQ==";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 9
0
        public async Task TestSubmitName()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/api/ns/Demo1/TestEnum.aspx?submit=submit",
                Data   = new { week = "Thursday" },
                Method = "GET"
            };

            string actual = await option.SendAsync <string>();

            string expected = "Thursday";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 10
0
        public async Task TestNamespace_3()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/Ajax/DEMO.Controllers.TestTask.TaskDemoService/Add.aspx",
                Data   = new { a = 2, b = 3 },
                Method = "GET"
            };

            string actual = await option.SendAsync <string>();

            string expected = "105";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 11
0
        public async Task TestMd5()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/api/ns/Demo1/GetMd5.aspx",
                Data   = new { input = "Fish Li" },
                Method = "GET"
            };

            string actual = await option.SendAsync <string>();

            string expected = "44d2d9635ed5cdea2a858cd7a1cc2b0c";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 12
0
        public async Task TestNamespace_2()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/Ajax/Fish.BB.Test/Add.aspx",
                Data   = new { a = 2, b = 3 },
                Method = "GET"
            };

            string actual = await option.SendAsync <string>();

            string expected = "15";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 13
0
        public async Task Test2()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-mvc-demo.com/ajax/pk/DemoPk/Add.cspx",
                Method = "POST",
                Data   = new { a = 1, b = 2 }
            };

            string actual = await option.SendAsync <string>();

            string expected = "3";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 14
0
        public async Task TestAutoFindAction3()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/api/ns/TestAutoAction/submit.aspx",
                Method = "POST",
                Data   = new { Sha1 = "yes", input = "Fish Li" }
            };

            string actual = await option.SendAsync <string>();

            string expected = "A6DCC78B685D0CEA701CA90A948B9295F3685FDF";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 15
0
        public async Task TestAutoFindAction2()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-web-demo.com/api/ns/TestAutoAction/submit.aspx",
                Method = "POST",
                Data   = new { Md5 = "yes", input = "Fish Li" }
            };

            string actual = await option.SendAsync <string>();

            string expected = "44D2D9635ED5CDEA2A858CD7A1CC2B0C";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 16
0
        public async Task Test3()
        {
            HttpOption option = HttpOption.FromRawText(@"
POST http://www.fish-mvc-demo.com/Ajax/ns/TestFile/Sum.aspx HTTP/1.1
Content-Type: application/x-www-form-urlencoded

numbers=1&numbers=2&numbers=3&numbers=4&numbers=5");


            string actual = await option.SendAsync <string>();

            string expected = "15";

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 17
0
        public async static Task <int> GetStatusCode(this HttpOption option)
        {
            try {
                await option.SendAsync <string>();

                return(200);
            }
            catch (RemoteWebException remoteWebException) {
                return(remoteWebException.GetStatusCode());
            }
            catch (WebException ex) {
                return(ex.GetStatusCode());
            }
            catch (Exception) {
                return(500);
            }
        }
Ejemplo n.º 18
0
        public async Task Test3()
        {
            HttpOption option = new HttpOption {
                Url    = "http://www.fish-mvc-demo.com/ajax/pk/DemoPk/AddCustomer.cspx",
                Method = "POST",
                Data   = new { Address = "武汉", Age = 20, Email = "*****@*****.**", Name = "abc", Tel = "12345678" }
            };

            string actual = await option.SendAsync <string>();

            string expected = @"
    <Name>abc</Name>
    <Age>20</Age>
    <Address>武汉</Address>
    <Tel>12345678</Tel>
    <Email>[email protected]</Email>
</Customer>".Trim();

            Assert.IsTrue(actual.EndsWith(expected));
        }
Ejemplo n.º 19
0
        public async Task Test2()
        {
            HttpOption option = HttpOption.FromRawText(@"
GET http://www.fish-mvc-demo.com/file-download/demo1/%E4%B8%AD%E6%96%87%E6%B1%89%E5%AD%97%E6%97%A0%E4%B9%B1%E7%A0%81~!%40%23%24%25%5E%26*()_%2B-%3D%3C%3E%3F%7C.txt HTTP/1.1
Host: www.fish-mvc-demo.com
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36 OPR/31.0.1889.174
Referer: http://www.fish-mvc-demo.com/Pages/Demo/TestFileDownload.aspx
Accept-Encoding: gzip, deflate, lzma, sdch
Accept-Language: zh-CN,zh;q=0.8

");

            string actual = await option.SendAsync <string>();

            string expected = Guid.Empty.ToString();

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 20
0
        public async Task TestCustomerType()
        {
            HttpOption option = new HttpOption {
                Url  = "http://www.fish-web-demo.com/api/ns/Demo2/TestCustomerType.aspx",
                Data = new FormDataCollection()
                       .AddString("customer.Name", "name----1")
                       .AddString("customer.Tel", "tel----1")
                       .AddString("salesman.Name", "name----2")
                       .AddString("salesman.Tel", "tel----2"),
                Method = "POST"
            };

            string actual = await option.SendAsync <string>();

            string expected = @"
customer.Name = name----1
customer.Tel = tel----1
salesman.Name = name----2
salesman.Name = tel----2".Trim();

            Assert.AreEqual(expected, actual);
        }