public void AddParams()
 {
     var b = new UriQueryBuilder("http://example.com");
     b["Test"] = "2";
     b["Test"] = "7";
     Assert.Equal("7", b["Test"]);
 }
 public void ContainQuery()
 {
     var bld = new UriQueryBuilder("http://mytest.com/announce.aspx?key=1&foo=bar");
     Assert.True(bld.Contains("key"));
     Assert.True(bld.Contains("foo"));
     Assert.False(bld.Contains("bar"));
 }
        public void TestToString()
        {
            var bld = new UriQueryBuilder("http://mytest.com/announce.aspx?key=1");
            bld.Add("key", 2);
            bld.Add("foo", 2);
            bld.Add("foo", "bar");
            Assert.Equal(new Uri("http://mytest.com/announce.aspx?key=2&foo=bar"), bld.ToUri());

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

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

            bld = new UriQueryBuilder("http://mytest.com/announce.aspx");
            var infoHash = new byte[6] {0x01, 0x47, 0xff, 0xaa, 0xbb, 0xcc};
            bld.Add("key", UriHelper.UrlEncode(infoHash));
            Assert.Equal(new Uri("http://mytest.com/announce.aspx?key=%01G%ff%aa%bb%cc"), bld.ToUri());
        }
 public void CaseInsensitiveTest()
 {
     var b = new UriQueryBuilder("http://www.example.com?first=1&second=2&third=4");
     Assert.True(b.Contains("FiRsT"));
     Assert.Equal(b["FiRst"], "1");
 }
Exemple #5
0
        Uri CreateAnnounceString(AnnounceParameters parameters)
        {
            UriQueryBuilder b = new UriQueryBuilder (Uri);
            b.Add ("info_hash", parameters.InfoHash.UrlEncode ())
             .Add ("peer_id", parameters.PeerId)
             .Add ("port", parameters.Port)
             .Add ("uploaded", parameters.BytesUploaded)
             .Add ("downloaded", parameters.BytesDownloaded)
             .Add ("left", parameters.BytesLeft)
             .Add ("compact", 1)
             .Add ("numwant", 100);

            if (parameters.SupportsEncryption)
                b.Add ("supportcrypto", 1);
            if (parameters.RequireEncryption)
                b.Add ("requirecrypto", 1);
            if (!b.Contains ("key"))
                b.Add ("key", Key);
            if (!string.IsNullOrEmpty (parameters.Ipaddress))
                b.Add ("ip", parameters.Ipaddress);

            // If we have not successfully sent the started event to this tier, override the passed in started event
            // Otherwise append the event if it is not "none"
            //if (!parameters.Id.Tracker.Tier.SentStartedEvent)
            //{
            //    sb.Append("&event=started");
            //    parameters.Id.Tracker.Tier.SendingStartedEvent = true;
            //}
            if (parameters.ClientEvent != TorrentEvent.None)
                b.Add ("event", parameters.ClientEvent.ToString ().ToLower ());

            if (!string.IsNullOrEmpty (TrackerId))
                b.Add ("trackerid", TrackerId);

            return b.ToUri ();
        }