コード例 #1
0
        public void ParseMagnetLink()
        {
            InfoHash   hash   = Create();
            string     magnet = string.Format("magnet:?xt=urn:btih:{0}", hash.ToHex());
            MagnetLink other  = MagnetLink.Parse(magnet);

            Assert.AreEqual(hash, other.InfoHash, "#1");
        }
コード例 #2
0
 public void HexTest()
 {
     InfoHash hash = Create();
     string hex = hash.ToHex();
     Assert.AreEqual(40, hex.Length, "#1");
     InfoHash other = InfoHash.FromHex(hex);
     Assert.AreEqual(hash, other, "#2");
 }
コード例 #3
0
        public void InvalidMagnetLink2()
        {
            InfoHash   hash   = Create();
            string     magnet = string.Format("magnet:?xt=urn:btih:", hash.ToHex());
            MagnetLink other  = new MagnetLink(magnet);

            Assert.AreEqual(hash, other.InfoHash, "#1");
        }
コード例 #4
0
        public void ParseMagnetLink()
        {
            InfoHash   hash   = Create();
            string     magnet = $"magnet:?xt=urn:btih:{hash.ToHex ()}";
            MagnetLink other  = MagnetLink.Parse(magnet);

            Assert.AreEqual(hash, other.InfoHashes.V1, "#1");
        }
コード例 #5
0
 public void InvalidMagnetLink3()
 {
     Assert.Throws <FormatException> (() => {
         InfoHash hash    = Create();
         string magnet    = string.Format("magnet:?xt=urn:btih:", hash.ToHex());
         MagnetLink other = MagnetLink.Parse(magnet);
         Assert.AreEqual(hash, other.InfoHash, "#1");
     });
 }
コード例 #6
0
 public void InvalidMagnetLink()
 {
     Assert.Throws <UriFormatException> (() => {
         InfoHash hash    = Create();
         string magnet    = $"magnet?xt=urn:btih:{hash.ToHex ()}";
         MagnetLink other = MagnetLink.Parse(magnet);
         Assert.AreEqual(hash, other.InfoHash, "#1");
     });
 }
コード例 #7
0
 //[ExpectedException(typeof(FormatException))]
 public void InvalidMagnetLink()
 {
     Assert.Catch <FormatException>(() => {
         InfoHash hash    = Create();
         string magnet    = string.Format("magnet?xt=urn:btih:{0}", hash.ToHex());
         MagnetLink other = new MagnetLink(magnet);
         Assert.AreEqual(hash, other.InfoHash, "#1");
     });
 }
コード例 #8
0
        public void InfoHashTest()
        {
            MagnetLink link = MagnetLink.Parse("magnet:?xt.1=urn:sha1:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C");

            Assert.AreEqual(InfoHash.FromBase32("YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C"), link.InfoHash, "#1");

            //base32
            InfoHash initial = new InfoHash(System.Text.Encoding.ASCII.GetBytes("foobafoobafoobafooba"));

            link = MagnetLink.Parse("magnet:?xt=urn:sha1:MZXW6YTBMZXW6YTBMZXW6YTBMZXW6YTB");
            Assert.AreEqual(initial, link.InfoHash, "#2");

            //base40 = hex
            InfoHash hash = Create();
            string   hex  = hash.ToHex();

            link = MagnetLink.Parse("magnet:?xt=urn:btih:" + hex);
            Assert.AreEqual(hash, link.InfoHash, "#3");
        }
コード例 #9
0
 public void InvalidMagnetLink4()
 {
     Assert.Throws <FormatException> (() =>
     {
         InfoHash hash    = Create();
         string magnet    = string.Format("magnet:?xt=urn:btih:23526246235623564234365879634581726345981", hash.ToHex());
         MagnetLink other = MagnetLink.Parse(magnet);
         Assert.AreEqual(hash, other.InfoHash, "#1");
     });
 }
コード例 #10
0
        public void InvalidMagnetLink3()
        {
            InfoHash   hash   = Create();
            string     magnet = string.Format("magnet:?xt=urn:btih:23526246235623564234365879634581726345981", hash.ToHex());
            MagnetLink other  = new MagnetLink(magnet);

            Assert.AreEqual(hash, other.InfoHash, "#1");
        }