示例#1
0
        public void ConstructPostDataTest1()
        {
            string data = IJNetwork.ConstructPostData(
                "key");

            Assert.That(data, Is.EqualTo("key="), "ConstructPostDataTest1-1");

            data = IJNetwork.ConstructPostData(
                "key", "value");
            Assert.That(data, Is.EqualTo("key=value"), "ConstructPostDataTest1-2");

            data = IJNetwork.ConstructPostData(
                "key", "val",
                "キー");
            Assert.That(data, Is.EqualTo("key=val&%E3%82%AD%E3%83%BC="), "ConstructPostDataTest1-3");

            data = IJNetwork.ConstructPostData(
                "key", "val",
                "キー", "値");
            Assert.That(data, Is.EqualTo("key=val&%E3%82%AD%E3%83%BC=%E5%80%A4"), "ConstructPostDataTest1-4");

            data = IJNetwork.ConstructPostData(
                "key", "val",
                "キー", "値1 値2");
            Assert.That(data, Is.EqualTo("key=val&%E3%82%AD%E3%83%BC=%E5%80%A41%20%E5%80%A42"), "ConstructPostDataTest1-5");
        }
示例#2
0
        private string RemoveMylistGroup(NicoNetwork network, string mylist_id, string token)
        {
            HttpWebRequest request = WebRequest.Create("http://www.nicovideo.jp/api/mylistgroup/delete") as HttpWebRequest;

            request.Method = "POST";
            string          cookie_value     = network.GetUserSession();
            Cookie          cookie           = new Cookie("user_session", cookie_value, "/", ".nicovideo.jp");
            CookieContainer cookie_container = new CookieContainer();

            cookie_container.Add(cookie);
            request.CookieContainer = cookie_container;
            request.ContentType     = "application/x-www-form-urlencoded; charset=UTF-8";
            request.Headers.Add("x-requested-with", "XMLHttpRequest");

            string post_data = IJNetwork.ConstructPostData(
                "group_id", mylist_id,
                "token", token);

            using (Stream request_stream = request.GetRequestStream())
                using (TextWriter request_writer = new StreamWriter(request_stream, new UTF8Encoding()))
                {
                    request_writer.Write(post_data);
                }

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                using (Stream response_stream = response.GetResponseStream())
                    using (TextReader response_reader = new StreamReader(response_stream, new UTF8Encoding()))
                    {
                        return(response_reader.ReadToEnd());
                    }
        }
示例#3
0
        public void ConstructPostDataTest3()
        {
            string data = IJNetwork.ConstructPostData(new string[0]);

            Assert.That(data, Is.EqualTo(""), "ConstructPostDataTest3-1");

            data = IJNetwork.ConstructPostData(((string[])null));
            Assert.That(data, Is.EqualTo(""), "ConstructPostDataTest3-2");
        }
示例#4
0
        public void ConstructPostDataTest2()
        {
            string data = IJNetwork.ConstructPostData("key", "");

            Assert.That(data, Is.EqualTo("key="), "ConstructPostDataTest2-1");

            data = IJNetwork.ConstructPostData("key", null);
            Assert.That(data, Is.EqualTo("key="), "ConstructPostDataTest2-2");

            data = IJNetwork.ConstructPostData("key");
            Assert.That(data, Is.EqualTo("key="), "ConstructPostDataTest2-3");

            data = IJNetwork.ConstructPostData("", "val");
            Assert.That(data, Is.EqualTo("=val"), "ConstructPostDataTest2-4");

            data = IJNetwork.ConstructPostData("", "");
            Assert.That(data, Is.EqualTo("="), "ConstructPostDataTest2-5");

            data = IJNetwork.ConstructPostData("", null);
            Assert.That(data, Is.EqualTo("="), "ConstructPostDataTest2-6");

            data = IJNetwork.ConstructPostData("");
            Assert.That(data, Is.EqualTo("="), "ConstructPostDataTest2-7");

            data = IJNetwork.ConstructPostData(null, "val");
            Assert.That(data, Is.EqualTo("=val"), "ConstructPostDataTest2-8");

            data = IJNetwork.ConstructPostData(null, "");
            Assert.That(data, Is.EqualTo("="), "ConstructPostDataTest2-9");

            data = IJNetwork.ConstructPostData(null, null);
            Assert.That(data, Is.EqualTo("="), "ConstructPostDataTest2-10");

            data = IJNetwork.ConstructPostData(((string)null));
            Assert.That(data, Is.EqualTo("="), "ConstructPostDataTest2-11");

            data = IJNetwork.ConstructPostData();
            Assert.That(data, Is.EqualTo(""), "ConstructPostDataTest2-12");
        }