Skip to content

Commit

Permalink
Add DelugeClientConfig to set timeout and other future stuff (#5)
Browse files Browse the repository at this point in the history
* Added docker-compose.yml to help testing

* Added DelugeClientConfig class to store timeout and other future stuff

* Set defaut timeout to 3 seconds

* Update README.md
  • Loading branch information
valcriss authored Nov 4, 2024
1 parent d29c036 commit 564a40d
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 90 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,4 @@ MigrationBackup/

# Ionide (cross platform F# VS Code tools) working folder
.ionide/
docker/
6 changes: 2 additions & 4 deletions DelugeRPCClient.Net.Tests/AuthentificationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
namespace DelugeRPCClient.Net.Tests
{
[TestClass]
public class AuthentificationTests
public class AuthentificationTests : DelugeClientTest
{
[TestMethod]
public async Task LoginLogout()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);
bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
DelugeClient client = await Login();
bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
}
Expand Down
64 changes: 64 additions & 0 deletions DelugeRPCClient.Net.Tests/DelugeClientTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using DelugeRPCClient.Net.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DelugeRPCClient.Net.Tests
{
public class DelugeClientTest
{
protected async Task<DelugeClient> Login()
{
DelugeClientConfig config = new DelugeClientConfig()
{
IgnoreSslErrors = true,
Timeout = new TimeSpan(0, 0, 30)
};
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword, config);
bool loginResult = await client.Login();
Assert.IsTrue(loginResult);

return client;
}

protected async Task Logout(DelugeClient client)
{
bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
}

protected async Task<Torrent> AddTestTorrent(DelugeClient client)
{
Torrent torrent = await client.AddTorrentByFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Constants.TestTorrentFilename));
Assert.IsNotNull(torrent);
Thread.Sleep(1000);
return torrent;
}

protected async Task RemoveTestTorrent(DelugeClient client, Torrent torrent)
{
bool removeTorrentResult = await client.RemoveTorrent(torrent.Hash);
Assert.IsTrue(removeTorrentResult);
Thread.Sleep(1000);
}

protected async Task AddTestLabel(DelugeClient client)
{
bool addLabelResult = await client.AddLabel(Constants.TestLabelName);
Assert.IsTrue(addLabelResult);
Thread.Sleep(1000);
}

protected async Task RemoveTestLabel(DelugeClient client)
{
bool removeLabelResult = await client.RemoveLabel(Constants.TestLabelName);
Assert.IsTrue(removeLabelResult);
Thread.Sleep(1000);
}
}
}
59 changes: 23 additions & 36 deletions DelugeRPCClient.Net.Tests/LabelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,66 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace DelugeRPCClient.Net.Tests
{
[TestClass]
public class LabelTests
public class LabelTests : DelugeClientTest
{
[TestMethod]
public async Task ListLabels()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);

DelugeClient client = await Login();

await AddTestLabel(client);

List<string> labels = await client.ListLabels();
Assert.IsNotNull(labels);
Assert.AreNotEqual(0, labels.Count);

await RemoveTestLabel(client);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await Logout(client);
}

[TestMethod]
public async Task AddRemoveLabel()
public async Task AddAndRemoveLabel()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);
DelugeClient client = await Login();

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
await AddTestLabel(client);

bool addLabelResult = await client.AddLabel(Constants.TestLabelName);
Assert.IsTrue(addLabelResult);
await RemoveTestLabel(client);

Thread.Sleep(1000);

bool removeLabelResult = await client.RemoveLabel(Constants.TestLabelName);
Assert.IsTrue(removeLabelResult);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await Logout(client);
}

[TestMethod]
public async Task AssignLabel()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);
DelugeClient client = await Login();

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
await AddTestLabel(client);

List<Torrent> torrents = await client.ListTorrents(new Dictionary<string, string>() { { "label", "" } });
Assert.IsNotNull(torrents);
Assert.AreNotEqual(0, torrents.Count);

Torrent torrent = torrents[0];
Torrent testTorrent = await AddTestTorrent(client);

bool assignResult = await client.SetTorrentLabel(torrent.Hash, Constants.TestLabelName);
bool assignResult = await client.SetTorrentLabel(testTorrent.Hash, Constants.TestLabelName);
Assert.IsTrue(assignResult);
Thread.Sleep(1000);

bool unsertLabelResult = await client.SetTorrentLabel(torrent.Hash, null);
bool unsertLabelResult = await client.SetTorrentLabel(testTorrent.Hash, null);
Assert.IsTrue(unsertLabelResult);
Thread.Sleep(1000);

bool removeLabelResult = await client.RemoveLabel(Constants.TestLabelName);
Assert.IsTrue(removeLabelResult);
Thread.Sleep(1000);
await RemoveTestLabel(client);

await RemoveTestTorrent(client, testTorrent);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await Logout(client);
}
}
}
68 changes: 28 additions & 40 deletions DelugeRPCClient.Net.Tests/TorrentsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
namespace DelugeRPCClient.Net.Tests
{
[TestClass]
public class TorrentsTests
public class TorrentsTests : DelugeClientTest
{
[TestMethod]
public async Task ListAndGetTorrent()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);
DelugeClient client = await Login();

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
Torrent testTorrent = await AddTestTorrent(client);

List<Torrent> torrents = await client.ListTorrents();
Assert.IsNotNull(torrents);
Expand All @@ -29,17 +28,17 @@ public async Task ListAndGetTorrent()
Torrent torrent = await client.GetTorrent(torrents[0].Hash);
Assert.IsNotNull(torrent);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await RemoveTestTorrent(client, testTorrent);

await Logout(client);
}

[TestMethod]
public async Task ListAndGetTorrentExtended()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);
DelugeClient client = await Login();

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
Torrent testTorrent = await AddTestTorrent(client);

List<TorrentExtended> torrents = await client.ListTorrentsExtended();
Assert.IsNotNull(torrents);
Expand All @@ -48,17 +47,15 @@ public async Task ListAndGetTorrentExtended()
TorrentExtended torrent = await client.GetTorrentExtended(torrents[0].Hash);
Assert.IsNotNull(torrent);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await RemoveTestTorrent(client, testTorrent);

await Logout(client);
}

[TestMethod]
public async Task AddRemoveTorrentByMagnet()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
DelugeClient client = await Login();

Torrent torrent = await client.AddTorrentByMagnet(Constants.TorrentMagnet);
Assert.IsNotNull(torrent);
Expand All @@ -68,17 +65,13 @@ public async Task AddRemoveTorrentByMagnet()
bool removeTorrentResult = await client.RemoveTorrent(torrent.Hash);
Assert.IsTrue(removeTorrentResult);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await Logout(client);
}

[TestMethod]
public async Task AddRemoveTorrentByFile()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
DelugeClient client = await Login();

Torrent torrent = await client.AddTorrentByFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Constants.TestTorrentFilename));
Assert.IsNotNull(torrent);
Expand All @@ -88,17 +81,13 @@ public async Task AddRemoveTorrentByFile()
bool removeTorrentResult = await client.RemoveTorrent(torrent.Hash);
Assert.IsTrue(removeTorrentResult);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await Logout(client);
}

[TestMethod]
public async Task AddRemoveTorrentByUrl()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
DelugeClient client = await Login();

Torrent torrent = await client.AddTorrentByUrl(Constants.TestTorrentUrl);
Assert.IsNotNull(torrent);
Expand All @@ -108,17 +97,15 @@ public async Task AddRemoveTorrentByUrl()
bool removeTorrentResult = await client.RemoveTorrent(torrent.Hash);
Assert.IsTrue(removeTorrentResult);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await Logout(client);
}

[TestMethod]
public async Task PauseResumeTorrent()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);
DelugeClient client = await Login();

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
Torrent testTorrent = await AddTestTorrent(client);

List<Torrent> torrents = await client.ListTorrents();
Assert.IsNotNull(torrents);
Expand All @@ -139,19 +126,19 @@ public async Task PauseResumeTorrent()
Assert.IsTrue(pauseResult);
bool resumeResult = await client.ResumeTorrent(torrent.Hash);
Assert.IsTrue(resumeResult);
}
}

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await RemoveTestTorrent(client, testTorrent);

await Logout(client);
}

[TestMethod]
public async Task RecheckTorrents()
{
DelugeClient client = new DelugeClient(url: Constants.DelugeUrl, password: Constants.DelugePassword);
DelugeClient client = await Login();

bool loginResult = await client.Login();
Assert.IsTrue(loginResult);
Torrent testTorrent = await AddTestTorrent(client);

List<Torrent> torrents = await client.ListTorrents();
Assert.IsNotNull(torrents);
Expand All @@ -162,8 +149,9 @@ public async Task RecheckTorrents()
bool? recheckResult = await client.RecheckTorrents(torrent.Hash.Split(",").ToList());
Assert.IsNull(recheckResult);

bool logoutResult = await client.Logout();
Assert.IsTrue(logoutResult);
await RemoveTestTorrent(client, testTorrent);

await Logout(client);
}
}
}
Loading

0 comments on commit 564a40d

Please sign in to comment.