示例#1
0
        public void TestAddAndRemoveTorrent()
        {
            try
            {
                UTorrentClient client = new UTorrentClient("admin", "password");
                using (System.IO.FileStream file = System.IO.File.OpenRead("dummy.torrent"))
                {
                    var addResponse = client.PostTorrent(file);
                    Assert.IsNotNull(addResponse);
                    Assert.IsNotNull(addResponse.Result);
                    Assert.IsNull(addResponse.Result.Error);
                    Assert.IsNotNull(addResponse.AddedTorrent);
                    Torrent torrent = addResponse.AddedTorrent;

                    var deleteResponse = client.DeleteTorrent(torrent.Hash);
                    Assert.IsNotNull(deleteResponse);
                    Assert.IsNotNull(deleteResponse.Result);
                    Assert.IsNull(deleteResponse.Result.Error);
                }
            }
            catch (ServerUnavailableException)
            {
                Assert.Inconclusive("Serveur unavailable");
            }
            catch (InvalidCredentialException)
            {
                Assert.Inconclusive("Invalid credential");
            }
        }
        public void TestAddAndRemoveTorrent()
        {
            try
            {
                UTorrentClient client = new UTorrentClient("admin", "password");
                using (System.IO.FileStream file = System.IO.File.OpenRead("dummy.torrent"))
                {
                    var addResponse = client.PostTorrent(file);
                    Assert.IsNotNull(addResponse);
                    Assert.IsNotNull(addResponse.Result);
                    Assert.IsNull(addResponse.Result.Error);
                    Assert.IsNotNull(addResponse.AddedTorrent);
                    Torrent torrent = addResponse.AddedTorrent;

                    var deleteResponse = client.DeleteTorrent(torrent.Hash);
                    Assert.IsNotNull(deleteResponse);
                    Assert.IsNotNull(deleteResponse.Result);
                    Assert.IsNull(deleteResponse.Result.Error);
                }
            }
            catch (ServerUnavailableException)
            {
                Assert.Inconclusive("Serveur unavailable");
            }
            catch (InvalidCredentialException)
            {
                Assert.Inconclusive("Invalid credential");
            }
        }
        public void TestAddAndRemoveTorrent()
        {
            try
            {
                var dummyFile =
                    "ZDEwOmNyZWF0ZWQgYnkx" +
                    "Mzp1VG9ycmVudC8zMzAw" +
                    "MTM6Y3JlYXRpb24gZGF0" +
                    "ZWkxMzc1NTU5MjcyZTg6" +
                    "ZW5jb2Rpbmc1OlVURi04" +
                    "NDppbmZvZDY6bGVuZ3Ro" +
                    "aTVlNDpuYW1lOTpkdW1t" +
                    "eS50eHQxMjpwaWVjZSBs" +
                    "ZW5ndGhpMTYzODRlNjpw" +
                    "aWVjZXMyMDqCnDgEQBsH" +
                    "J/cPc9RBXhYkAMvlezc6" +
                    "cHJpdmF0ZWkxZWVl";

                var            bytes  = Convert.FromBase64String(dummyFile);
                UTorrentClient client = new UTorrentClient("admin", "password");
                using (var file = new MemoryStream(bytes))
                {
                    var addResponse = client.PostTorrent(file);
                    Assert.IsNotNull(addResponse);
                    Assert.IsNotNull(addResponse.Result);
                    Assert.IsNull(addResponse.Result.Error);
                    Assert.IsNotNull(addResponse.AddedTorrent);
                    Torrent torrent = addResponse.AddedTorrent;

                    var deleteResponse = client.DeleteTorrent(torrent.Hash);
                    Assert.IsNotNull(deleteResponse);
                    Assert.IsNotNull(deleteResponse.Result);
                    Assert.IsNull(deleteResponse.Result.Error);
                }
            }
            catch (AggregateException ex)
            {
                if (ex.InnerException is ServerUnavailableException || ex.InnerException is InvalidCredentialException)
                {
                    Assert.Inconclusive("Serveur unavailable");
                }
                throw;
            }
            catch (ServerUnavailableException)
            {
                Assert.Inconclusive("Serveur unavailable");
            }
            catch (InvalidCredentialException)
            {
                Assert.Inconclusive("Invalid credential");
            }
        }