forked from Beatlegger/Transmission.API.RPC
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMethodsTest.cs
More file actions
166 lines (128 loc) · 5.28 KB
/
MethodsTest.cs
File metadata and controls
166 lines (128 loc) · 5.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using System.Collections;
using System.Linq;
using System.Net.Http;
using Transmission.API.RPC.Entity;
using Transmission.API.RPC.Arguments;
namespace Transmission.API.RPC.Test
{
[TestClass]
public class MethodsTest
{
const string FILE_PATH = "./Data/ubuntu-10.04.4-server-amd64.iso.torrent";
const string HOST = "http://192.168.1.50:9091/transmission/rpc";
const string SESSION_ID = "";
Client client = new Client(new HttpClient(), HOST, SESSION_ID);
#region Torrent Test
[TestMethod]
public void AddTorrent_Test()
{
if (!File.Exists(FILE_PATH))
throw new Exception("Torrent file not found");
var fstream = File.OpenRead(FILE_PATH);
byte[] filebytes = new byte[fstream.Length];
fstream.Read(filebytes, 0, Convert.ToInt32(fstream.Length));
string encodedData = Convert.ToBase64String(filebytes);
//The path relative to the server (priority than the metadata)
//string filename = "/DataVolume/shares/Public/Transmission/torrents/ubuntu-10.04.4-server-amd64.iso.torrent";
var torrent = new NewTorrent
{
//Filename = filename,
Metainfo = encodedData,
Paused = true
};
var newTorrentInfo = client.TorrentAdd(torrent);
Assert.IsNotNull(newTorrentInfo);
Assert.IsTrue(newTorrentInfo.Id != 0);
}
[TestMethod]
public void AddTorrent_Magnet_Test()
{
var torrent = new NewTorrent
{
Filename = "magnet:?xt=urn:btih:9e241c218299b1d813275e066f94dbe05bc25e53&dn=Rick.and.Morty.S03E03.720p.HDTV.x264-BATV%5Bettv%5D&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
Paused = false
};
var newTorrentInfo = client.TorrentAdd(torrent);
Assert.IsNotNull(newTorrentInfo);
Assert.IsTrue(newTorrentInfo.Id != 0);
}
[TestMethod]
public void GetTorrentInfo_Test()
{
var torrentsInfo = client.TorrentGet(TorrentFields.ALL_FIELDS);
Assert.IsNotNull(torrentsInfo);
Assert.IsNotNull(torrentsInfo.Torrents);
Assert.IsTrue(torrentsInfo.Torrents.Any());
}
[TestMethod]
public void SetTorrentSettings_Test()
{
var torrentsInfo = client.TorrentGet(TorrentFields.ALL_FIELDS);
var torrentInfo = torrentsInfo.Torrents.FirstOrDefault();
Assert.IsNotNull(torrentInfo, "Torrent not found");
var trackerInfo = torrentInfo.Trackers.FirstOrDefault();
Assert.IsNotNull(trackerInfo, "Tracker not found");
var trackerCount = torrentInfo.Trackers.Length;
TorrentSettings settings = new TorrentSettings()
{
Ids = new object[] { torrentInfo.HashString },
TrackerRemove = new long[] { trackerInfo.Id }
};
client.TorrentSet(settings);
torrentsInfo = client.TorrentGet(TorrentFields.ALL_FIELDS, torrentInfo.HashString);
torrentInfo = torrentsInfo.Torrents.FirstOrDefault();
Assert.IsFalse(trackerCount == torrentInfo.Trackers.Length);
}
[TestMethod]
public void RenamePathTorrent_Test()
{
var torrentsInfo = client.TorrentGet(TorrentFields.ALL_FIELDS);
var torrentInfo = torrentsInfo.Torrents.FirstOrDefault();
Assert.IsNotNull(torrentInfo, "Torrent not found");
var result = client.TorrentRenamePath(torrentInfo.Id, torrentInfo.Files[0].Name, "test_" + torrentInfo.Files[0].Name);
Assert.IsNotNull(result, "Torrent not found");
Assert.IsTrue(result.Id != 0);
}
[TestMethod]
public void RemoveTorrent_Test()
{
var torrentsInfo = client.TorrentGet(TorrentFields.ALL_FIELDS);
var torrentInfo = torrentsInfo.Torrents.FirstOrDefault();
Assert.IsNotNull(torrentInfo, "Torrent not found");
client.TorrentRemove(new object[] { torrentInfo.Id });
torrentsInfo = client.TorrentGet(TorrentFields.ALL_FIELDS);
Assert.IsFalse(torrentsInfo.Torrents.Any(t => t.Id == torrentInfo.Id));
}
#endregion
#region Session Test
[TestMethod]
public void SessionGetTest()
{
var info = client.GetSessionInformation();
Assert.IsNotNull(info);
Assert.IsNotNull(info.Version);
}
[TestMethod]
public void ChangeSessionTest()
{
//Get current session information
var sessionInformation = client.GetSessionInformation();
//Save old speed limit up
var oldSpeedLimit = (long)sessionInformation.SpeedLimitUp;
//Set new session settings
client.SetSessionSettings(new SessionSettings() { SpeedLimitUp = 100 });
//Get new session information
var newSessionInformation = client.GetSessionInformation();
//Check new speed limit
Assert.AreEqual(newSessionInformation.SpeedLimitUp, 100);
//Restore speed limit
newSessionInformation.SpeedLimitUp = oldSpeedLimit;
//Set new session settinhs
client.SetSessionSettings(new SessionSettings() { SpeedLimitUp = oldSpeedLimit });
}
#endregion
}
}