Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4.3.1
with:
dotnet-version: 6.0.102
dotnet-version: 8.0.410
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Publish DelugeRPCClient.Net
uses: brandedoutcast/publish-nuget@v2.5.5
with:
PROJECT_FILE_PATH: DelugeRPCClient.Net/DelugeRPCClient.Net.csproj
NUGET_KEY: ${{secrets.nugetsAPIKEY}}
- name: Test
run: dotnet test --no-build --verbosity normal
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release .NET

on:
push:
tags:
- '*'

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v4.3.1
with:
dotnet-version: 8.0.410
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- name: Publish DelugeRPCClient.Net
uses: brandedoutcast/publish-nuget@v2.5.5
with:
PROJECT_FILE_PATH: DelugeRPCClient.Net/DelugeRPCClient.Net.csproj
NUGET_KEY: ${{secrets.nugetsAPIKEY}}
17 changes: 0 additions & 17 deletions DelugeRPCClient.Net.Tests/AuthentificationTests.cs

This file was deleted.

29 changes: 0 additions & 29 deletions DelugeRPCClient.Net.Tests/ConfigTests.cs

This file was deleted.

6 changes: 3 additions & 3 deletions DelugeRPCClient.Net.Tests/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace DelugeRPCClient.Net.Tests
{
internal class Constants
internal static class Constants
{
internal const string DelugeUrl = "http://localhost:8112/json";
internal const string DelugePassword = "deluge";
internal static string DelugeUrl => Environment.GetEnvironmentVariable("DELUGE_URL") ?? "http://localhost:8112/json";
internal static string DelugePassword => Environment.GetEnvironmentVariable("DELUGE_PASSWORD") ?? "deluge";
internal const string TestLabelName = "testlabel";
internal const string TorrentMagnet = "magnet:?xt=urn:btih:30987c19cf0eae3cf47766f387c621fa78a58ab9&dn=debian-9.2.1-amd64-netinst.iso";
internal const string TestTorrentFilename = "test.torrent";
Expand Down
113 changes: 113 additions & 0 deletions DelugeRPCClient.Net.Tests/DelugeClientCoverageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
using DelugeRPCClient.Net.Models;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;

namespace DelugeRPCClient.Net.Tests
{
[TestClass]
public class DelugeClientCoverageTests
{
[TestMethod]
public async Task FullClientWorkflow()
{
using var httpClient = TestUtils.CreateMockClient(TestUtils.DefaultResponses);
var client = new DelugeClient("http://mock", "pwd", httpClient: httpClient);
Assert.IsTrue(await client.Login());
Assert.IsNotNull(await client.ListTorrents());
Assert.IsNotNull(await client.ListTorrentsExtended());
Assert.IsNotNull(await client.GetTorrent("hash"));
Assert.IsNotNull(await client.GetTorrentExtended("hash"));
string torrentPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), Constants.TestTorrentFilename);
Assert.IsNotNull(await client.AddTorrentByMagnet("magnet"));
Assert.IsNotNull(await client.AddTorrentByFile(torrentPath));
Assert.IsNotNull(await client.AddTorrentByUrl("http://example.com/file.torrent"));
Assert.IsTrue(await client.RemoveTorrent("hash"));
Assert.IsTrue(await client.PauseTorrent("hash"));
Assert.IsTrue(await client.ResumeTorrent("hash"));
Assert.IsNull(await client.RecheckTorrents(new List<string> { "hash" }));
Assert.IsNotNull(await client.ListConfigs());
Assert.IsNotNull(await client.ListLabels());
Assert.IsTrue(await client.LabelExists("lbl"));
Assert.IsTrue(await client.AddLabel("lbl"));
Assert.IsTrue(await client.RemoveLabel("lbl"));
Assert.IsTrue(await client.SetTorrentLabel("hash", "lbl"));
Assert.IsTrue(await client.Logout());
}

[TestMethod]
public async Task PauseResumeReturnsFalseOnBool()
{
var dict = new Dictionary<string, object>(TestUtils.DefaultResponses)
{
["core.pause_torrent"] = false,
["core.resume_torrent"] = false
};
using var httpClient = TestUtils.CreateMockClient(dict);
var client = new DelugeClient("http://mock", "pwd", httpClient: httpClient);
Assert.IsFalse(await client.PauseTorrent("hash"));
Assert.IsFalse(await client.ResumeTorrent("hash"));
}

[TestMethod]
public void AddLabelThrowsOnInvalid()
{
using var httpClient = TestUtils.CreateMockClient(TestUtils.DefaultResponses);
var client = new DelugeClient("http://mock", "pwd", httpClient: httpClient);
Assert.ThrowsExceptionAsync<ArgumentException>(() => client.AddLabel(null));
}

[TestMethod]
public async Task ErrorAndDesyncThrow()
{
using var errClient = TestUtils.CreateMockClient(TestUtils.DefaultResponses, error: true);
var client = new DelugeClient("http://mock", "pwd", httpClient: errClient);
try
{
await client.ListLabels();
Assert.Fail("no exception");
}
catch (Exception)
{
}

using var desyncClient = TestUtils.CreateMockClient(TestUtils.DefaultResponses, mismatchId: true);
var client2 = new DelugeClient("http://mock", "pwd", httpClient: desyncClient);
try
{
await client2.ListLabels();
Assert.Fail("no exception");
}
catch (Exception)
{
}
}

[TestMethod]
public void ModelPropertyCoverage()
{
var types = new[] { typeof(Config), typeof(Torrent), typeof(TorrentExtended), typeof(TorrentOptions) };
foreach (var t in types)
{
var instance = Activator.CreateInstance(t);
foreach (var prop in t.GetProperties())
{
if (prop.CanWrite)
{
object value = prop.PropertyType.IsValueType ? Activator.CreateInstance(prop.PropertyType) : null;
prop.SetValue(instance, value);
}
if (prop.CanRead)
{
_ = prop.GetValue(instance);
}
}
}
Assert.IsTrue(typeof(Torrent).GetProperties().Length > 0);
}
}
}
64 changes: 0 additions & 64 deletions DelugeRPCClient.Net.Tests/DelugeClientTest.cs

This file was deleted.

10 changes: 5 additions & 5 deletions DelugeRPCClient.Net.Tests/DelugeRPCClient.Net.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.2" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
67 changes: 0 additions & 67 deletions DelugeRPCClient.Net.Tests/LabelTests.cs

This file was deleted.

Loading