public void TestToString()
        {
            UriQueryBuilder bld = new UriQueryBuilder("http://mytest.com/announce.aspx?key=1");

            bld.Add("key", 2);
            bld.Add("foo", 2);
            bld.Add("foo", "bar");
            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx?key=2&foo=bar"), bld.ToUri(), "#1");

            bld = new UriQueryBuilder("http://mytest.com/announce.aspx?passkey=1");
            bld.Add("key", 2);
            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx?passkey=1&key=2"), bld.ToUri(), "#2");

            bld = new UriQueryBuilder("http://mytest.com/announce.aspx");
            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx"), bld.ToUri(), "#3");

            bld = new UriQueryBuilder("http://mytest.com/announce.aspx");
            byte[] infoHash = new byte[] { 0x01, 0x47, 0xff, 0xaa, 0xbb, 0xcc };
            bld.Add("key", UriHelper.UrlEncode(infoHash));
            Assert.AreEqual(new Uri("http://mytest.com/announce.aspx?key=%01G%ff%aa%bb%cc"), bld.ToUri(), "#4");
        }
Example #2
0
 public string UrlEncode()
 {
     return(UriHelper.UrlEncode(Hash).Replace("+", "%20"));
 }