2017-09-21 04:18:47 +00:00
|
|
|
using System;
|
2016-04-04 17:40:51 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading;
|
2020-01-03 12:49:24 +00:00
|
|
|
using System.Threading.Tasks;
|
2016-03-25 00:56:29 +00:00
|
|
|
using FluentAssertions;
|
2020-01-03 12:49:24 +00:00
|
|
|
using Lidarr.Api.V1.Albums;
|
|
|
|
using Lidarr.Api.V1.Artist;
|
2021-08-19 21:35:06 +00:00
|
|
|
using Lidarr.Api.V1.Blocklist;
|
2017-10-31 01:28:29 +00:00
|
|
|
using Lidarr.Api.V1.Config;
|
|
|
|
using Lidarr.Api.V1.DownloadClient;
|
|
|
|
using Lidarr.Api.V1.History;
|
|
|
|
using Lidarr.Api.V1.Profiles.Quality;
|
|
|
|
using Lidarr.Api.V1.RootFolders;
|
2021-04-27 20:26:38 +00:00
|
|
|
using Lidarr.Api.V1.System.Tasks;
|
2017-10-31 01:28:29 +00:00
|
|
|
using Lidarr.Api.V1.Tags;
|
2020-01-03 12:49:24 +00:00
|
|
|
using Microsoft.AspNetCore.SignalR.Client;
|
|
|
|
using NLog;
|
|
|
|
using NLog.Config;
|
|
|
|
using NLog.Targets;
|
|
|
|
using NUnit.Framework;
|
2016-04-04 17:40:51 +00:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Core.MediaFiles.TrackImport.Manual;
|
2016-03-25 00:56:29 +00:00
|
|
|
using NzbDrone.Core.Qualities;
|
2016-04-04 17:40:51 +00:00
|
|
|
using NzbDrone.Integration.Test.Client;
|
|
|
|
using NzbDrone.SignalR;
|
2020-01-03 12:49:24 +00:00
|
|
|
using NzbDrone.Test.Common;
|
2016-04-04 17:40:51 +00:00
|
|
|
using NzbDrone.Test.Common.Categories;
|
|
|
|
using RestSharp;
|
2021-04-26 20:56:38 +00:00
|
|
|
using RestSharp.Serializers.SystemTextJson;
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
namespace NzbDrone.Integration.Test
|
|
|
|
{
|
|
|
|
[IntegrationTest]
|
|
|
|
public abstract class IntegrationTestBase
|
|
|
|
{
|
|
|
|
protected RestClient RestClient { get; private set; }
|
|
|
|
|
2021-08-19 21:35:06 +00:00
|
|
|
public ClientBase<BlocklistResource> Blocklist;
|
2016-03-25 00:56:29 +00:00
|
|
|
public CommandClient Commands;
|
2021-04-27 20:26:38 +00:00
|
|
|
public ClientBase<TaskResource> Tasks;
|
2016-04-04 17:40:51 +00:00
|
|
|
public DownloadClientClient DownloadClients;
|
2017-10-25 02:31:37 +00:00
|
|
|
public AlbumClient Albums;
|
2017-07-02 00:21:39 +00:00
|
|
|
public TrackClient Tracks;
|
2016-04-04 17:40:51 +00:00
|
|
|
public ClientBase<HistoryResource> History;
|
2016-07-31 21:40:07 +00:00
|
|
|
public ClientBase<HostConfigResource> HostConfig;
|
2016-04-04 17:40:51 +00:00
|
|
|
public IndexerClient Indexers;
|
2019-08-22 20:15:25 +00:00
|
|
|
public LogsClient Logs;
|
2016-04-04 17:40:51 +00:00
|
|
|
public ClientBase<NamingConfigResource> NamingConfig;
|
|
|
|
public NotificationClient Notifications;
|
2024-02-03 17:49:16 +00:00
|
|
|
public ClientBase<QualityProfileResource> QualityProfiles;
|
2016-04-04 17:40:51 +00:00
|
|
|
public ReleaseClient Releases;
|
2017-10-29 02:52:36 +00:00
|
|
|
public ReleasePushClient ReleasePush;
|
2016-04-04 17:40:51 +00:00
|
|
|
public ClientBase<RootFolderResource> RootFolders;
|
2017-07-02 00:21:39 +00:00
|
|
|
public ArtistClient Artist;
|
2016-04-04 17:40:51 +00:00
|
|
|
public ClientBase<TagResource> Tags;
|
2017-09-21 04:18:47 +00:00
|
|
|
public ClientBase<AlbumResource> WantedMissing;
|
|
|
|
public ClientBase<AlbumResource> WantedCutoffUnmet;
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
private List<SignalRMessage> _signalRReceived;
|
2019-10-28 21:12:26 +00:00
|
|
|
|
|
|
|
private HubConnection _signalrConnection;
|
2016-04-04 17:40:51 +00:00
|
|
|
|
2016-12-09 06:54:15 +00:00
|
|
|
protected IEnumerable<SignalRMessage> SignalRMessages => _signalRReceived;
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
public IntegrationTestBase()
|
|
|
|
{
|
|
|
|
new StartupContext();
|
|
|
|
|
|
|
|
LogManager.Configuration = new LoggingConfiguration();
|
|
|
|
var consoleTarget = new ConsoleTarget { Layout = "${level}: ${message} ${exception}" };
|
|
|
|
LogManager.Configuration.AddTarget(consoleTarget.GetType().Name, consoleTarget);
|
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Trace, consoleTarget));
|
|
|
|
}
|
|
|
|
|
|
|
|
public string TempDirectory { get; private set; }
|
|
|
|
|
2017-07-02 00:21:39 +00:00
|
|
|
public abstract string ArtistRootFolder { get; }
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
protected abstract string RootUrl { get; }
|
|
|
|
|
|
|
|
protected abstract string ApiKey { get; }
|
|
|
|
|
|
|
|
protected abstract void StartTestTarget();
|
|
|
|
|
|
|
|
protected abstract void InitializeTestTarget();
|
|
|
|
|
|
|
|
protected abstract void StopTestTarget();
|
|
|
|
|
|
|
|
[OneTimeSetUp]
|
|
|
|
public void SmokeTestSetup()
|
|
|
|
{
|
|
|
|
StartTestTarget();
|
|
|
|
InitRestClients();
|
|
|
|
InitializeTestTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void InitRestClients()
|
|
|
|
{
|
2017-10-31 01:28:29 +00:00
|
|
|
RestClient = new RestClient(RootUrl + "api/v1/");
|
2016-04-04 17:40:51 +00:00
|
|
|
RestClient.AddDefaultHeader("Authentication", ApiKey);
|
|
|
|
RestClient.AddDefaultHeader("X-Api-Key", ApiKey);
|
2021-04-26 20:56:38 +00:00
|
|
|
RestClient.UseSystemTextJson();
|
2016-04-04 17:40:51 +00:00
|
|
|
|
2021-08-19 21:35:06 +00:00
|
|
|
Blocklist = new ClientBase<BlocklistResource>(RestClient, ApiKey);
|
2016-04-04 17:40:51 +00:00
|
|
|
Commands = new CommandClient(RestClient, ApiKey);
|
2021-04-27 20:26:38 +00:00
|
|
|
Tasks = new ClientBase<TaskResource>(RestClient, ApiKey, "system/task");
|
2016-04-04 17:40:51 +00:00
|
|
|
DownloadClients = new DownloadClientClient(RestClient, ApiKey);
|
2017-10-25 02:31:37 +00:00
|
|
|
Albums = new AlbumClient(RestClient, ApiKey);
|
2017-10-26 02:02:14 +00:00
|
|
|
Tracks = new TrackClient(RestClient, ApiKey);
|
2016-04-04 17:40:51 +00:00
|
|
|
History = new ClientBase<HistoryResource>(RestClient, ApiKey);
|
2016-07-31 21:40:07 +00:00
|
|
|
HostConfig = new ClientBase<HostConfigResource>(RestClient, ApiKey, "config/host");
|
2016-04-04 17:40:51 +00:00
|
|
|
Indexers = new IndexerClient(RestClient, ApiKey);
|
2019-08-22 20:15:25 +00:00
|
|
|
Logs = new LogsClient(RestClient, ApiKey);
|
2016-04-04 17:40:51 +00:00
|
|
|
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, ApiKey, "config/naming");
|
|
|
|
Notifications = new NotificationClient(RestClient, ApiKey);
|
2024-02-03 17:49:16 +00:00
|
|
|
QualityProfiles = new ClientBase<QualityProfileResource>(RestClient, ApiKey);
|
2016-04-04 17:40:51 +00:00
|
|
|
Releases = new ReleaseClient(RestClient, ApiKey);
|
2017-10-29 02:52:36 +00:00
|
|
|
ReleasePush = new ReleasePushClient(RestClient, ApiKey);
|
2016-04-04 17:40:51 +00:00
|
|
|
RootFolders = new ClientBase<RootFolderResource>(RestClient, ApiKey);
|
2017-07-02 00:21:39 +00:00
|
|
|
Artist = new ArtistClient(RestClient, ApiKey);
|
2016-04-04 17:40:51 +00:00
|
|
|
Tags = new ClientBase<TagResource>(RestClient, ApiKey);
|
2017-09-21 04:18:47 +00:00
|
|
|
WantedMissing = new ClientBase<AlbumResource>(RestClient, ApiKey, "wanted/missing");
|
|
|
|
WantedCutoffUnmet = new ClientBase<AlbumResource>(RestClient, ApiKey, "wanted/cutoff");
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[OneTimeTearDown]
|
|
|
|
public void SmokeTestTearDown()
|
|
|
|
{
|
|
|
|
StopTestTarget();
|
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void IntegrationSetUp()
|
|
|
|
{
|
2019-08-22 20:15:25 +00:00
|
|
|
TempDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "_test_" + TestBase.GetUID());
|
|
|
|
|
|
|
|
// Wait for things to get quiet, otherwise the previous test might influence the current one.
|
|
|
|
Commands.WaitAll();
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[TearDown]
|
2019-10-28 21:12:26 +00:00
|
|
|
public async Task IntegrationTearDown()
|
2016-04-04 17:40:51 +00:00
|
|
|
{
|
|
|
|
if (_signalrConnection != null)
|
|
|
|
{
|
2019-10-28 21:12:26 +00:00
|
|
|
await _signalrConnection.StopAsync();
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
_signalrConnection = null;
|
|
|
|
_signalRReceived = new List<SignalRMessage>();
|
|
|
|
}
|
2019-08-22 20:15:25 +00:00
|
|
|
|
|
|
|
if (Directory.Exists(TempDirectory))
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Directory.Delete(TempDirectory, true);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public string GetTempDirectory(params string[] args)
|
|
|
|
{
|
|
|
|
var path = Path.Combine(TempDirectory, Path.Combine(args));
|
|
|
|
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2019-10-28 21:12:26 +00:00
|
|
|
protected async Task ConnectSignalR()
|
2016-04-04 17:40:51 +00:00
|
|
|
{
|
|
|
|
_signalRReceived = new List<SignalRMessage>();
|
2019-10-28 21:12:26 +00:00
|
|
|
_signalrConnection = new HubConnectionBuilder()
|
|
|
|
.WithUrl("http://localhost:8686/signalr/messages", options =>
|
|
|
|
{
|
|
|
|
options.AccessTokenProvider = () => Task.FromResult(ApiKey);
|
|
|
|
})
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
var cts = new CancellationTokenSource();
|
|
|
|
|
|
|
|
_signalrConnection.Closed += e =>
|
2016-04-04 17:40:51 +00:00
|
|
|
{
|
2019-10-28 21:12:26 +00:00
|
|
|
cts.Cancel();
|
|
|
|
return Task.CompletedTask;
|
|
|
|
};
|
|
|
|
|
|
|
|
_signalrConnection.On<SignalRMessage>("receiveMessage", (message) =>
|
|
|
|
{
|
|
|
|
_signalRReceived.Add(message);
|
2016-04-04 17:40:51 +00:00
|
|
|
});
|
|
|
|
|
2019-10-28 21:12:26 +00:00
|
|
|
var connected = false;
|
2016-04-04 17:40:51 +00:00
|
|
|
var retryCount = 0;
|
|
|
|
|
2019-10-28 21:12:26 +00:00
|
|
|
while (!connected)
|
2016-04-04 17:40:51 +00:00
|
|
|
{
|
2019-10-28 21:12:26 +00:00
|
|
|
try
|
2016-04-04 17:40:51 +00:00
|
|
|
{
|
2019-10-28 21:12:26 +00:00
|
|
|
await _signalrConnection.StartAsync();
|
|
|
|
connected = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
|
|
|
if (retryCount > 25)
|
|
|
|
{
|
|
|
|
Assert.Fail("Couldn't establish signalR connection");
|
|
|
|
}
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retryCount++;
|
|
|
|
Thread.Sleep(200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void WaitForCompletion(Func<bool> predicate, int timeout = 10000, int interval = 500)
|
|
|
|
{
|
|
|
|
var count = timeout / interval;
|
|
|
|
for (var i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (predicate())
|
2020-01-03 12:49:24 +00:00
|
|
|
{
|
2016-04-04 17:40:51 +00:00
|
|
|
return;
|
2020-01-03 12:49:24 +00:00
|
|
|
}
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
Thread.Sleep(interval);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (predicate())
|
2020-01-03 12:49:24 +00:00
|
|
|
{
|
2016-04-04 17:40:51 +00:00
|
|
|
return;
|
2020-01-03 12:49:24 +00:00
|
|
|
}
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
Assert.Fail("Timed on wait");
|
|
|
|
}
|
|
|
|
|
2017-07-08 12:08:24 +00:00
|
|
|
public ArtistResource EnsureArtist(string lidarrId, string artistName, bool? monitored = null)
|
2016-04-04 17:40:51 +00:00
|
|
|
{
|
2017-07-02 00:21:39 +00:00
|
|
|
var result = Artist.All().FirstOrDefault(v => v.ForeignArtistId == lidarrId);
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
{
|
2017-07-02 00:21:39 +00:00
|
|
|
var lookup = Artist.Lookup("lidarr:" + lidarrId);
|
|
|
|
var artist = lookup.First();
|
2017-09-21 04:18:47 +00:00
|
|
|
artist.QualityProfileId = 1;
|
2017-12-25 02:45:28 +00:00
|
|
|
artist.MetadataProfileId = 1;
|
2017-09-21 04:18:47 +00:00
|
|
|
artist.Path = Path.Combine(ArtistRootFolder, artist.ArtistName);
|
2017-07-02 00:21:39 +00:00
|
|
|
artist.Monitored = true;
|
|
|
|
artist.AddOptions = new Core.Music.AddArtistOptions();
|
|
|
|
Directory.CreateDirectory(artist.Path);
|
|
|
|
|
|
|
|
result = Artist.Post(artist);
|
2016-03-25 00:56:29 +00:00
|
|
|
Commands.WaitAll();
|
2017-07-03 18:39:06 +00:00
|
|
|
WaitForCompletion(() => Tracks.GetTracksInArtist(result.Id).Count > 0);
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
2019-08-22 20:15:25 +00:00
|
|
|
var changed = false;
|
|
|
|
|
|
|
|
if (result.RootFolderPath != ArtistRootFolder)
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
result.RootFolderPath = ArtistRootFolder;
|
|
|
|
result.Path = Path.Combine(ArtistRootFolder, result.ArtistName);
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:40:51 +00:00
|
|
|
if (monitored.HasValue)
|
|
|
|
{
|
|
|
|
if (result.Monitored != monitored.Value)
|
|
|
|
{
|
|
|
|
result.Monitored = monitored.Value;
|
|
|
|
changed = true;
|
|
|
|
}
|
2019-08-22 20:15:25 +00:00
|
|
|
}
|
2016-04-04 17:40:51 +00:00
|
|
|
|
2019-08-22 20:15:25 +00:00
|
|
|
if (changed)
|
|
|
|
{
|
2021-04-26 20:56:38 +00:00
|
|
|
result.NextAlbum = result.LastAlbum = null;
|
2019-08-22 20:15:25 +00:00
|
|
|
Artist.Put(result);
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-07-08 12:08:24 +00:00
|
|
|
public void EnsureNoArtist(string lidarrId, string artistTitle)
|
2016-04-04 17:40:51 +00:00
|
|
|
{
|
2017-07-02 00:21:39 +00:00
|
|
|
var result = Artist.All().FirstOrDefault(v => v.ForeignArtistId == lidarrId);
|
2016-04-04 17:40:51 +00:00
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
{
|
2017-07-02 00:21:39 +00:00
|
|
|
Artist.Delete(result.Id);
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-05 10:23:20 +00:00
|
|
|
public void EnsureTrackFile(ArtistResource artist, int albumId, int albumReleaseId, int trackNumber, Quality quality)
|
2016-03-25 00:56:29 +00:00
|
|
|
{
|
2023-05-05 10:23:20 +00:00
|
|
|
var result = Tracks.GetTracksInArtist(artist.Id).Single(v => v.AlbumId == albumId && v.AbsoluteTrackNumber == trackNumber);
|
2016-03-25 00:56:29 +00:00
|
|
|
|
2017-07-02 00:21:39 +00:00
|
|
|
if (result.TrackFile == null)
|
2016-03-25 00:56:29 +00:00
|
|
|
{
|
2019-08-22 20:15:25 +00:00
|
|
|
var path = Path.Combine(ArtistRootFolder, artist.ArtistName, "Track.mp3");
|
2016-03-25 00:56:29 +00:00
|
|
|
|
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
2017-07-02 00:21:39 +00:00
|
|
|
File.WriteAllText(path, "Fake Track");
|
2016-03-25 00:56:29 +00:00
|
|
|
|
2020-01-03 12:49:24 +00:00
|
|
|
Commands.PostAndWait(new ManualImportCommand
|
|
|
|
{
|
|
|
|
Files = new List<ManualImportFile>
|
|
|
|
{
|
|
|
|
new ManualImportFile
|
|
|
|
{
|
2019-08-22 20:15:25 +00:00
|
|
|
Path = path,
|
|
|
|
ArtistId = artist.Id,
|
|
|
|
AlbumId = albumId,
|
|
|
|
AlbumReleaseId = albumReleaseId,
|
2023-05-05 10:23:20 +00:00
|
|
|
TrackIds = new List<int> { trackNumber },
|
2019-08-22 20:15:25 +00:00
|
|
|
Quality = new QualityModel(quality)
|
|
|
|
}
|
2020-01-03 12:49:24 +00:00
|
|
|
}
|
|
|
|
});
|
2016-03-25 00:56:29 +00:00
|
|
|
Commands.WaitAll();
|
2020-01-03 12:49:24 +00:00
|
|
|
|
2023-05-05 10:23:20 +00:00
|
|
|
var track = Tracks.GetTracksInArtist(artist.Id).Single(x => x.AlbumId == albumId && x.AbsoluteTrackNumber == trackNumber);
|
2016-03-25 00:56:29 +00:00
|
|
|
|
2019-08-22 20:15:25 +00:00
|
|
|
track.TrackFileId.Should().NotBe(0);
|
2016-03-25 00:56:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-03 17:49:16 +00:00
|
|
|
public QualityProfileResource EnsureQualityProfileCutoff(int profileId, string cutoff, bool upgradeAllowed)
|
2016-03-25 00:56:29 +00:00
|
|
|
{
|
2022-05-24 03:52:27 +00:00
|
|
|
var needsUpdate = false;
|
2024-02-03 17:49:16 +00:00
|
|
|
var profile = QualityProfiles.Get(profileId);
|
2019-08-22 20:15:25 +00:00
|
|
|
var cutoffItem = profile.Items.First(x => x.Name == cutoff);
|
2016-03-25 00:56:29 +00:00
|
|
|
|
2019-08-22 20:15:25 +00:00
|
|
|
if (profile.Cutoff != cutoffItem.Id)
|
2016-03-25 00:56:29 +00:00
|
|
|
{
|
2019-08-22 20:15:25 +00:00
|
|
|
profile.Cutoff = cutoffItem.Id;
|
2022-05-24 03:52:27 +00:00
|
|
|
needsUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile.UpgradeAllowed != upgradeAllowed)
|
|
|
|
{
|
|
|
|
profile.UpgradeAllowed = upgradeAllowed;
|
|
|
|
needsUpdate = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needsUpdate)
|
|
|
|
{
|
2024-02-03 17:49:16 +00:00
|
|
|
profile = QualityProfiles.Put(profile);
|
2016-03-25 00:56:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
|
2016-04-04 17:40:51 +00:00
|
|
|
public TagResource EnsureTag(string tagLabel)
|
|
|
|
{
|
|
|
|
var tag = Tags.All().FirstOrDefault(v => v.Label == tagLabel);
|
|
|
|
|
|
|
|
if (tag == null)
|
|
|
|
{
|
|
|
|
tag = Tags.Post(new TagResource { Label = tagLabel });
|
|
|
|
}
|
|
|
|
|
|
|
|
return tag;
|
|
|
|
}
|
2016-03-25 00:56:29 +00:00
|
|
|
|
|
|
|
public void EnsureNoTag(string tagLabel)
|
|
|
|
{
|
|
|
|
var tag = Tags.All().FirstOrDefault(v => v.Label == tagLabel);
|
|
|
|
|
|
|
|
if (tag != null)
|
|
|
|
{
|
|
|
|
Tags.Delete(tag.Id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public DownloadClientResource EnsureDownloadClient(bool enabled = true)
|
|
|
|
{
|
|
|
|
var client = DownloadClients.All().FirstOrDefault(v => v.Name == "Test UsenetBlackhole");
|
|
|
|
|
|
|
|
if (client == null)
|
|
|
|
{
|
|
|
|
var schema = DownloadClients.Schema().First(v => v.Implementation == "UsenetBlackhole");
|
|
|
|
|
|
|
|
schema.Enable = enabled;
|
|
|
|
schema.Name = "Test UsenetBlackhole";
|
2018-09-02 04:42:03 +00:00
|
|
|
schema.Fields.First(v => v.Name == "watchFolder").Value = GetTempDirectory("Download", "UsenetBlackhole", "Watch");
|
|
|
|
schema.Fields.First(v => v.Name == "nzbFolder").Value = GetTempDirectory("Download", "UsenetBlackhole", "Nzb");
|
2016-03-25 00:56:29 +00:00
|
|
|
|
|
|
|
client = DownloadClients.Post(schema);
|
|
|
|
}
|
|
|
|
else if (client.Enable != enabled)
|
|
|
|
{
|
|
|
|
client.Enable = enabled;
|
|
|
|
|
|
|
|
client = DownloadClients.Put(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void EnsureNoDownloadClient()
|
|
|
|
{
|
|
|
|
var clients = DownloadClients.All();
|
|
|
|
|
|
|
|
foreach (var client in clients)
|
|
|
|
{
|
|
|
|
DownloadClients.Delete(client.Id);
|
|
|
|
}
|
|
|
|
}
|
2016-04-04 17:40:51 +00:00
|
|
|
}
|
|
|
|
}
|