public void ToUriV1()
        {
            var infoHash  = Create();
            var name      = "MyName/Url/Encoded";
            var announces = new[] {
                "http://testUrl.com/foo/bar/announce",
                "http://test2Url.com/foo/bar",
            };
            var webSeeds = new[] {
                "http://whatever.com/file.exe",
                "http://whatever2.com/file.exe",
            };
            var magnetLink = new MagnetLink(infoHash, name, announces, webSeeds);
            var uriString  = magnetLink.ToV1String();

            Assert.IsFalse(uriString.Contains(announces[0]), "The uri should be Uri encoded");
            Assert.IsFalse(uriString.Contains(webSeeds[0]), "The uri should be Uri encoded");
            Assert.IsFalse(uriString.Contains(name), "The name should be Uri encoded");

            magnetLink = MagnetLink.Parse(uriString);
            Assert.AreEqual(infoHash, magnetLink.InfoHash, "#1");
            Assert.AreEqual(name, magnetLink.Name, "#2");
            CollectionAssert.AreEquivalent(announces, magnetLink.AnnounceUrls, "#3");
            CollectionAssert.AreEquivalent(webSeeds, magnetLink.Webseeds, "#4");

            Assert.AreEqual(magnetLink.ToV1String(), MagnetLink.FromUri(magnetLink.ToV1Uri()).ToV1String(), "#5");
        }
Example #2
0
        public void ShouldAcceptV2Uri()
        {
            var link = MagnetLink.FromUri(new Uri("magnet:?xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e&dn=bittorrent-v2-test"));

            Assert.IsNull(link.InfoHashes.V1);
            Assert.IsNotNull(link.InfoHashes.V2);
            Assert.AreEqual("caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e", link.InfoHashes.V2.ToHex().ToLowerInvariant());
        }
Example #3
0
        public void ShouldAcceptHybridV1V2Uri()
        {
            var link = MagnetLink.FromUri(new Uri("magnet:?xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&xt=urn:btmh:1220d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb&dn=bittorrent-v1-v2-hybrid-test"));

            Assert.IsNotNull(link.InfoHashes.V1);
            Assert.IsNotNull(link.InfoHashes.V2);
            Assert.AreEqual("631a31dd0a46257d5078c0dee4e66e26f73e42ac", link.InfoHashes.V1.ToHex().ToLowerInvariant());
            Assert.AreEqual("d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb", link.InfoHashes.V2.ToHex().ToLowerInvariant());
        }
 public void UnsupportedScheme()
 {
     Assert.Throws <FormatException> (() => MagnetLink.FromUri(new Uri("http://not_a_magnet_link.com")));
 }
 public void TwoInfoHashes()
 {
     Assert.Throws <FormatException> (() => MagnetLink.FromUri(new Uri("magnet://btih:?foo=bar&xt=urn:btih:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C&xt=urn:btih:ANCKHTQCWBTRNJIV4WNAE52SJUQCZO5C")));
 }
 public void InvalidMagnetLink_DoubleEquals()
 {
     Assert.Throws <FormatException> (() => MagnetLink.FromUri(new Uri("magnet://btih:?xt=urn=:btih:YNCKHTQCWBTRNJIV4WNAE52SJUQCZO5C")));
 }
Example #7
0
 public void ShouldAcceptHybridV1V2Uri()
 {
     Assert.DoesNotThrow(() => MagnetLink.FromUri(new Uri("magnet:?xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&xt=urn:btmh:1220d8dd32ac93357c368556af3ac1d95c9d76bd0dff6fa9833ecdac3d53134efabb&dn=bittorrent-v1-v2-hybrid-test")));
 }
Example #8
0
 public void ThrowsOnMultipleV1Uri()
 {
     Assert.Throws <FormatException> (() => MagnetLink.FromUri(
                                          new Uri("magnet:?xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&xt=urn:btih:631a31dd0a46257d5078c0dee4e66e26f73e42ac&dn=bittorrent-v1-test")));
 }
Example #9
0
 public void ThrowsOnMultipleV2Uri()
 {
     Assert.Throws <FormatException> (() => MagnetLink.FromUri(
                                          new Uri("magnet:?xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e&xt=urn:btmh:1220caf1e1c30e81cb361b9ee167c4aa64228a7fa4fa9f6105232b28ad099f3a302e&dn=bittorrent-v2-test")));
 }