* Stylecop Rules and Fixes
This commit is contained in:
Qstick 2020-01-03 07:49:24 -05:00
commit a4b78b44ce
1307 changed files with 8702 additions and 7403 deletions

View file

@ -20,14 +20,15 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[TestFixture]
public class RemotePathMappingCheckFixture : CoreTest<RemotePathMappingCheck>
{
private string downloadRootPath = @"c:\Test".AsOsAgnostic();
private string downloadItemPath = @"c:\Test\item".AsOsAgnostic();
private string _downloadRootPath = @"c:\Test".AsOsAgnostic();
private string _downloadItemPath = @"c:\Test\item".AsOsAgnostic();
private DownloadClientInfo clientStatus;
private DownloadClientItem downloadItem;
private Mock<IDownloadClient> downloadClient;
static Exception[] DownloadClientExceptions = {
private DownloadClientInfo _clientStatus;
private DownloadClientItem _downloadItem;
private Mock<IDownloadClient> _downloadClient;
private static Exception[] DownloadClientExceptions =
{
new DownloadClientUnavailableException("error"),
new DownloadClientAuthenticationException("error"),
new DownloadClientException("error")
@ -36,44 +37,48 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[SetUp]
public void Setup()
{
downloadItem = new DownloadClientItem {
DownloadClient = "Test",
DownloadId = "TestId",
OutputPath = new OsPath(downloadItemPath)
_downloadItem = new DownloadClientItem
{
DownloadClient = "Test",
DownloadId = "TestId",
OutputPath = new OsPath(_downloadItemPath)
};
clientStatus = new DownloadClientInfo {
IsLocalhost = true,
OutputRootFolders = new List<OsPath> { new OsPath(downloadRootPath) }
_clientStatus = new DownloadClientInfo
{
IsLocalhost = true,
OutputRootFolders = new List<OsPath> { new OsPath(_downloadRootPath) }
};
downloadClient = Mocker.GetMock<IDownloadClient>();
downloadClient.Setup(s => s.Definition)
_downloadClient = Mocker.GetMock<IDownloadClient>();
_downloadClient.Setup(s => s.Definition)
.Returns(new DownloadClientDefinition { Name = "Test" });
downloadClient.Setup(s => s.GetItems())
.Returns(new List<DownloadClientItem> { downloadItem });
_downloadClient.Setup(s => s.GetItems())
.Returns(new List<DownloadClientItem> { _downloadItem });
downloadClient.Setup(s => s.GetStatus())
.Returns(clientStatus);
_downloadClient.Setup(s => s.GetStatus())
.Returns(_clientStatus);
Mocker.GetMock<IProvideDownloadClient>()
.Setup(s => s.GetDownloadClients())
.Returns(new IDownloadClient[] { downloadClient.Object });
.Returns(new IDownloadClient[] { _downloadClient.Object });
Mocker.GetMock<IDiskProvider>()
.Setup(x => x.FolderExists(It.IsAny<string>()))
.Returns((string path) => {
Ensure.That(path, () => path).IsValidPath();
return false;
});
.Returns((string path) =>
{
Ensure.That(path, () => path).IsValidPath();
return false;
});
Mocker.GetMock<IDiskProvider>()
.Setup(x => x.FileExists(It.IsAny<string>()))
.Returns((string path) => {
Ensure.That(path, () => path).IsValidPath();
return false;
});
.Returns((string path) =>
{
Ensure.That(path, () => path).IsValidPath();
return false;
});
}
private void GivenFolderExists(string folder)
@ -90,7 +95,6 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Returns(true);
}
private void GivenDocker()
{
Mocker.GetMock<IOsInfo>()
@ -101,7 +105,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_ok_if_setup_correctly()
{
GivenFolderExists(downloadRootPath);
GivenFolderExists(_downloadRootPath);
Subject.Check().ShouldBeOk();
}
@ -115,8 +119,8 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_mapping_error_if_remote_client_root_path_invalid()
{
clientStatus.IsLocalhost = false;
clientStatus.OutputRootFolders = new List<OsPath> { new OsPath("An invalid path") };
_clientStatus.IsLocalhost = false;
_clientStatus.OutputRootFolders = new List<OsPath> { new OsPath("An invalid path") };
Subject.Check().ShouldBeError(wikiFragment: "bad-remote-path-mapping");
}
@ -124,8 +128,8 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_download_client_error_if_local_client_root_path_invalid()
{
clientStatus.IsLocalhost = true;
clientStatus.OutputRootFolders = new List<OsPath> { new OsPath("An invalid path") };
_clientStatus.IsLocalhost = true;
_clientStatus.OutputRootFolders = new List<OsPath> { new OsPath("An invalid path") };
Subject.Check().ShouldBeError(wikiFragment: "bad-download-client-settings");
}
@ -133,19 +137,20 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_path_mapping_error_if_remote_client_download_root_missing()
{
clientStatus.IsLocalhost = false;
_clientStatus.IsLocalhost = false;
Subject.Check().ShouldBeError(wikiFragment: "bad-remote-path-mapping");
}
[Test, TestCaseSource("DownloadClientExceptions")]
[Test]
[TestCaseSource("DownloadClientExceptions")]
public void should_return_ok_if_client_throws_downloadclientexception(Exception ex)
{
downloadClient.Setup(s => s.GetStatus())
_downloadClient.Setup(s => s.GetStatus())
.Throws(ex);
Subject.Check().ShouldBeOk();
ExceptionVerification.ExpectedErrors(0);
}
@ -153,24 +158,25 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
public void should_return_docker_path_mapping_error_if_on_docker_and_root_missing()
{
GivenDocker();
Subject.Check().ShouldBeError(wikiFragment: "docker-bad-remote-path-mapping");
}
[Test]
public void should_return_ok_on_track_imported_event()
{
GivenFolderExists(downloadRootPath);
GivenFolderExists(_downloadRootPath);
var importEvent = new TrackImportedEvent(new LocalTrack(), new TrackFile(), new List<TrackFile>(), true, new DownloadClientItem());
Subject.Check(importEvent).ShouldBeOk();
}
[Test]
public void should_return_permissions_error_on_track_import_failed_event_if_file_exists()
{
var localTrack = new LocalTrack {
Path = Path.Combine(downloadItemPath, "file.mp3")
var localTrack = new LocalTrack
{
Path = Path.Combine(_downloadItemPath, "file.mp3")
};
GivenFileExists(localTrack.Path);
@ -182,9 +188,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_permissions_error_on_track_import_failed_event_if_folder_exists()
{
GivenFolderExists(downloadItemPath);
GivenFolderExists(_downloadItemPath);
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
var importEvent = new TrackImportFailedEvent(null, null, true, _downloadItem);
Subject.Check(importEvent).ShouldBeError(wikiFragment: "permissions-error");
}
@ -192,7 +198,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_permissions_error_on_track_import_failed_event_for_local_client_if_folder_does_not_exist()
{
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
var importEvent = new TrackImportFailedEvent(null, null, true, _downloadItem);
Subject.Check(importEvent).ShouldBeError(wikiFragment: "permissions-error");
}
@ -200,8 +206,8 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_mapping_error_on_track_import_failed_event_for_remote_client_if_folder_does_not_exist()
{
clientStatus.IsLocalhost = false;
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
_clientStatus.IsLocalhost = false;
var importEvent = new TrackImportFailedEvent(null, null, true, _downloadItem);
Subject.Check(importEvent).ShouldBeError(wikiFragment: "bad-remote-path-mapping");
}
@ -209,9 +215,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_mapping_error_on_track_import_failed_event_for_remote_client_if_path_invalid()
{
clientStatus.IsLocalhost = false;
downloadItem.OutputPath = new OsPath("an invalid path");
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
_clientStatus.IsLocalhost = false;
_downloadItem.OutputPath = new OsPath("an invalid path");
var importEvent = new TrackImportFailedEvent(null, null, true, _downloadItem);
Subject.Check(importEvent).ShouldBeError(wikiFragment: "bad-remote-path-mapping");
}
@ -219,9 +225,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_return_download_client_error_on_track_import_failed_event_for_remote_client_if_path_invalid()
{
clientStatus.IsLocalhost = true;
downloadItem.OutputPath = new OsPath("an invalid path");
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
_clientStatus.IsLocalhost = true;
_downloadItem.OutputPath = new OsPath("an invalid path");
var importEvent = new TrackImportFailedEvent(null, null, true, _downloadItem);
Subject.Check(importEvent).ShouldBeError(wikiFragment: "bad-download-client-settings");
}
@ -230,21 +236,22 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
public void should_return_docker_mapping_error_on_track_import_failed_event_inside_docker_if_folder_does_not_exist()
{
GivenDocker();
clientStatus.IsLocalhost = false;
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
_clientStatus.IsLocalhost = false;
var importEvent = new TrackImportFailedEvent(null, null, true, _downloadItem);
Subject.Check(importEvent).ShouldBeError(wikiFragment: "docker-bad-remote-path-mapping");
}
[Test, TestCaseSource("DownloadClientExceptions")]
[Test]
[TestCaseSource("DownloadClientExceptions")]
public void should_return_ok_on_import_failed_event_if_client_throws_downloadclientexception(Exception ex)
{
downloadClient.Setup(s => s.GetStatus())
_downloadClient.Setup(s => s.GetStatus())
.Throws(ex);
var importEvent = new TrackImportFailedEvent(null, null, true, downloadItem);
var importEvent = new TrackImportFailedEvent(null, null, true, _downloadItem);
Subject.Check(importEvent).ShouldBeOk();
ExceptionVerification.ExpectedErrors(0);