示例#1
0
        public void TestParams()
        {
            string testUrl = "tcp://*****:*****@127.0.0.1:4001/myUri";
            URL    url     = new URL(testUrl);

            Assert.IsFalse(url.HasParams());
            Assert.AreEqual(0, url.GetParams().Length);
            Assert.IsNull(url.GetParam("PARAM1="));

            testUrl = "tcp://*****:*****@127.0.0.1:4001/cuae;PARAM1=1;PARAM2=2";
            url     = new URL(testUrl);
            Assert.IsTrue(url.HasParams());
            Assert.AreEqual("PARAM1=1", url.GetParam("PARAM1"));
            Assert.AreEqual("PARAM2=2", url.GetParam("PARAM2"));

            // get iterator over params
            string[] p = url.GetParams();
            Assert.AreEqual(2, p.Length);
            Assert.IsTrue(Find("PARAM1=1", p));
            Assert.IsTrue(Find("PARAM2=2", p));

            // add a new param
            url.AddParam("0123456789");
            Assert.AreEqual("0123456789", url.GetParam("0123"));
            p = url.GetParams();
            Assert.AreEqual(3, p.Length);
            Assert.IsTrue(Find("PARAM1=1", p));
            Assert.IsTrue(Find("PARAM2=2", p));
            Assert.IsTrue(Find("0123456789", p));

            // remove a param
            Assert.AreEqual("PARAM1=1", url.RemoveParam("PARAM1"));
            Assert.IsNull(url.GetParam("PARAM1="));
            p = url.GetParams();
            Assert.AreEqual(2, p.Length);
            Assert.IsTrue(Find("PARAM2=2", p));
            Assert.IsTrue(Find("0123456789", p));

            // clear all params
            url.ClearParams();
            Assert.IsFalse(url.HasParams());
        }
示例#2
0
        public void TestParse1()
        {
            string testUrl = "tcp://*****:*****@127.0.0.1:4001";
            URL    url1    = new URL(testUrl);

            Assert.AreEqual("tcp", url1.Scheme);
            Assert.AreEqual("user", url1.User);
            Assert.AreEqual("password", url1.Password);
            Assert.AreEqual("127.0.0.1", url1.Host);
            Assert.AreEqual(4001, url1.Port);

            //scheme tests

            Assert.IsFalse(url1.HasTerms());
            Assert.IsFalse(url1.HasParams());

            Assert.AreEqual("tcp://*****:*****@127.0.0.1:4001/", url1.ToString());
        }