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"); }
public void TwoInfoHashes() { Assert.Throws <FormatException> (() => MagnetLink.FromUri(new Uri("magnet://btih:?foo=bar&xt=urn:btih:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&xt=urn:btih:ANCKHTQCWBTRNJIV4WNAE52SJUQCZO5C"))); }
public void UnsupportedScheme() { Assert.Throws <FormatException> (() => MagnetLink.FromUri(new Uri("http://not_a_magnet_link.com"))); }
public void InvalidMagnetLink_DoubleEquals() { Assert.Throws <FormatException> (() => MagnetLink.FromUri(new Uri("magnet://btih:?xt=urn=:btih:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C"))); }
public void ValidMagnetLink_UnknownParameters() { var rawUrl = "magnet:?xt=urn:btih:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&hello&invalid=parameter"; Assert.DoesNotThrow(() => MagnetLink.Parse(rawUrl)); }
public void ShouldAcceptHybridV1V2Uri() { Assert.DoesNotThrow(() => MagnetLink.FromUri(new Uri("magnet:?xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&xt=urn:btmh:1220d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb&dn=bittorrent-v1-v2-hybrid-test"))); }
public void ThrowsOnMultipleV1Uri() { Assert.Throws <FormatException> (() => MagnetLink.FromUri( new Uri("magnet:?xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&dn=bittorrent-v1-test"))); }
public void ThrowsOnMultipleV2Uri() { Assert.Throws <FormatException> (() => MagnetLink.FromUri( new Uri("magnet:?xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e&xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e&dn=bittorrent-v2-test"))); }