Compare commits
225 Commits
curl-upgra
...
v2.0.0.485
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b03f434329 | ||
|
|
68290b0385 | ||
|
|
773274f3cc | ||
|
|
a33d8968ed | ||
|
|
e41baccd02 | ||
|
|
fef3423019 | ||
|
|
11926d8b2d | ||
|
|
4189bc6f76 | ||
|
|
601b54c244 | ||
|
|
905ab18336 | ||
|
|
f46a576df5 | ||
|
|
60231fbcae | ||
|
|
63860e783e | ||
|
|
cf8b9df5ad | ||
|
|
ff6841e410 | ||
|
|
ab49afe116 | ||
|
|
afcf136c4f | ||
|
|
d1b85444d0 | ||
|
|
63e0eba02f | ||
|
|
475c99d492 | ||
|
|
23552c3267 | ||
|
|
a49e37239e | ||
|
|
65b936ed94 | ||
|
|
359ef04861 | ||
|
|
8cf028e071 | ||
|
|
eea3419849 | ||
|
|
62bc63312d | ||
|
|
6a6d415625 | ||
|
|
1fbe82ae47 | ||
|
|
87f3cc9014 | ||
|
|
ab07a40931 | ||
|
|
10f292b225 | ||
|
|
de5ce23989 | ||
|
|
d0e226e269 | ||
|
|
d7cb5090fc | ||
|
|
416e9abca5 | ||
|
|
6dcb7768a9 | ||
|
|
baf83b4c71 | ||
|
|
285288db1a | ||
|
|
ec3dd982f6 | ||
|
|
410aa467b8 | ||
|
|
0c89a4ae8f | ||
|
|
a1edbafa8a | ||
|
|
ef5a400c68 | ||
|
|
8cc02a9d9c | ||
|
|
e83e852e0d | ||
|
|
4e10d30cf6 | ||
|
|
f335cc1af8 | ||
|
|
f4bea5512c | ||
|
|
9f8091e4d7 | ||
|
|
5aa02eb15c | ||
|
|
6bbe4ce066 | ||
|
|
563b5ef017 | ||
|
|
b9df5634bf | ||
|
|
755575d107 | ||
|
|
8eaab46488 | ||
|
|
4fbc481780 | ||
|
|
a41b5723d4 | ||
|
|
c2b66cf524 | ||
|
|
0d782e1cac | ||
|
|
edf549d0fd | ||
|
|
cf7ce9804f | ||
|
|
e8d01daf03 | ||
|
|
766520b851 | ||
|
|
14144bd4d9 | ||
|
|
7b0e40d5d0 | ||
|
|
2dbf095fd5 | ||
|
|
2a86f8c241 | ||
|
|
c184e7ddcc | ||
|
|
95c81f8905 | ||
|
|
db15949704 | ||
|
|
a63248401e | ||
|
|
1b32411219 | ||
|
|
cd7368512d | ||
|
|
a5bc4a8f11 | ||
|
|
2ae41a3404 | ||
|
|
312136a57c | ||
|
|
53e51af9c7 | ||
|
|
f852ca91c0 | ||
|
|
413dd51db1 | ||
|
|
9d93fc1092 | ||
|
|
0bbb82c67f | ||
|
|
cd8ae0d036 | ||
|
|
d726a7acb2 | ||
|
|
c94636e2b3 | ||
|
|
3749f3e2e5 | ||
|
|
1f93bec055 | ||
|
|
a003a89b14 | ||
|
|
35fca89dad | ||
|
|
e97e13e897 | ||
|
|
f8d5f1fc94 | ||
|
|
46a1ff3e2d | ||
|
|
f36d5dc881 | ||
|
|
f8b8fcfb8d | ||
|
|
de7f68570e | ||
|
|
fa006d85fd | ||
|
|
413ce1d9a7 | ||
|
|
41f769790d | ||
|
|
b63bcd16a7 | ||
|
|
b485bdaeec | ||
|
|
b70d167911 | ||
|
|
924fe80997 | ||
|
|
cd450a44bf | ||
|
|
35741b9cae | ||
|
|
c9d1807670 | ||
|
|
94886e767b | ||
|
|
e4c3418987 | ||
|
|
5613ab05e0 | ||
|
|
372442af2c | ||
|
|
28c45f941b | ||
|
|
ea1616586f | ||
|
|
e48600da42 | ||
|
|
5d9d2e684e | ||
|
|
2e392e0f5e | ||
|
|
83370ddbbb | ||
|
|
c20b152c28 | ||
|
|
bf5067466d | ||
|
|
ec7f749541 | ||
|
|
56ecbf4a31 | ||
|
|
1b39911135 | ||
|
|
6aaefae2d5 | ||
|
|
db9d601115 | ||
|
|
e7331539f0 | ||
|
|
58bd57bed6 | ||
|
|
7a58082cd7 | ||
|
|
2e08f195e4 | ||
|
|
a1a5e29c3e | ||
|
|
5033886b90 | ||
|
|
29419d6575 | ||
|
|
3c22f68f5a | ||
|
|
a0d98951aa | ||
|
|
70f7404499 | ||
|
|
abd70f5381 | ||
|
|
878e973081 | ||
|
|
2bf3b9e7dd | ||
|
|
2326db0dea | ||
|
|
3590fedeaf | ||
|
|
f4866cae69 | ||
|
|
149d191f62 | ||
|
|
bb9bd63382 | ||
|
|
34fda24124 | ||
|
|
c8d10829a0 | ||
|
|
ae2bdb757a | ||
|
|
714ad075fc | ||
|
|
87a05df2fd | ||
|
|
f3263efa52 | ||
|
|
1cad11d207 | ||
|
|
781df8b20a | ||
|
|
ebcce05588 | ||
|
|
bbf2134fe1 | ||
|
|
081c5fc332 | ||
|
|
47915d5e05 | ||
|
|
47e221d9a0 | ||
|
|
bf485f6f2c | ||
|
|
b365d8a537 | ||
|
|
fee8da88a6 | ||
|
|
cc0dbf1af4 | ||
|
|
836131ebb1 | ||
|
|
9a870a3709 | ||
|
|
afe05189da | ||
|
|
2abaef16f1 | ||
|
|
37d5a3f2ad | ||
|
|
be4d70e3a9 | ||
|
|
79043f2c64 | ||
|
|
1dab0aee6a | ||
|
|
9b162f2d5e | ||
|
|
5518cf5362 | ||
|
|
f7e3d9b4c2 | ||
|
|
6d9a952bd1 | ||
|
|
3501e33722 | ||
|
|
fa89d33900 | ||
|
|
0af48fb2e8 | ||
|
|
7e9f0d0522 | ||
|
|
1f8bd8e1e9 | ||
|
|
2855090005 | ||
|
|
060b9f6fd1 | ||
|
|
9304547c95 | ||
|
|
c56c83e169 | ||
|
|
c6fa883662 | ||
|
|
4043d07ab1 | ||
|
|
8af3348e7f | ||
|
|
49d0d4c357 | ||
|
|
47b1157b96 | ||
|
|
adc79f0eba | ||
|
|
6b117427f8 | ||
|
|
7884dd9a39 | ||
|
|
45d8b1e2ad | ||
|
|
cf306f4aba | ||
|
|
d7aa23388e | ||
|
|
82a99b7f80 | ||
|
|
2f6d9e191e | ||
|
|
0782a15979 | ||
|
|
ddd119a4eb | ||
|
|
d4788b4cae | ||
|
|
812999423b | ||
|
|
657730f4d2 | ||
|
|
0255eb3aca | ||
|
|
fc15daa37e | ||
|
|
10264a5bfb | ||
|
|
ef044f1ff5 | ||
|
|
ef03e9e9a7 | ||
|
|
3bd7c09acf | ||
|
|
fbd2f8dea4 | ||
|
|
15e07f72d4 | ||
|
|
f25bfe9d28 | ||
|
|
d5e720c404 | ||
|
|
c9a8ebc2e6 | ||
|
|
5e7e816c03 | ||
|
|
f56076a135 | ||
|
|
54dd527f01 | ||
|
|
c6eb19c04d | ||
|
|
38b65ba27d | ||
|
|
a2a49ce934 | ||
|
|
047d5a4388 | ||
|
|
aae69ff49a | ||
|
|
da451cfe03 | ||
|
|
01e2f4e7e5 | ||
|
|
8aacc61c50 | ||
|
|
111e401a2c | ||
|
|
8d91f18823 | ||
|
|
cea6469ab8 | ||
|
|
ced7a7dce2 | ||
|
|
20a2cfe260 | ||
|
|
5b0a285b84 | ||
|
|
68ea8a551c |
BIN
Logo/1024.png
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 55 KiB |
BIN
Logo/128.png
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 3.4 KiB |
BIN
Logo/16.png
|
Before Width: | Height: | Size: 707 B After Width: | Height: | Size: 490 B |
BIN
Logo/256.png
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 7.2 KiB |
BIN
Logo/32.png
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.1 KiB |
BIN
Logo/400.png
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 15 KiB |
BIN
Logo/48.png
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 1.5 KiB |
BIN
Logo/512.png
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 21 KiB |
BIN
Logo/64.png
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 2.0 KiB |
BIN
Logo/800.png
|
Before Width: | Height: | Size: 48 KiB After Width: | Height: | Size: 34 KiB |
BIN
Logo/96-Outline-White.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
52
README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
# Sonarr
|
||||
|
||||
Sonarr is a PVR for Usenet and BitTorrent users. It can monitor multiple RSS feeds for new episodes of your favorite shows and will grab, sort and rename them. It can also be configured to automatically upgrade the quality of files already downloaded when a better quality format becomes available.
|
||||
|
||||
## Major Features Include:
|
||||
|
||||
* Support for major platforms: Windows, Linux, macOS, Raspberry Pi, etc.
|
||||
* Automatically detects new episodes
|
||||
* Can scan your existing library and download any missing episodes
|
||||
* Can watch for better quality of the episodes you already have and do an automatic upgrade. *eg. from DVD to Blu-Ray*
|
||||
* Automatic failed download handling will try another release if one fails
|
||||
* Manual search so you can pick any release or to see why a release was not downloaded automatically
|
||||
* Fully configurable episode renaming
|
||||
* Full integration with SABnzbd and NZBGet
|
||||
* Full integration with Kodi, Plex (notification, library update, metadata)
|
||||
* Full support for specials and multi-episode releases
|
||||
* And a beautiful UI
|
||||
|
||||
## Configuring Development Environment:
|
||||
|
||||
### Requirements
|
||||
|
||||
* Visual Studio 2015 (https://www.visualstudio.com/vs/)
|
||||
* [Git](https://git-scm.com/downloads)
|
||||
* [NodeJS](https://nodejs.org/en/download/)
|
||||
|
||||
### Setup
|
||||
|
||||
* Make sure all the required software mentioned above are installed.
|
||||
* Clone the repository into your development machine. [*info*](https://help.github.com/articles/working-with-repositories)
|
||||
* Grab the submodules `git submodule init && git submodule update`
|
||||
* Install the required Node Packages `npm install`
|
||||
* Start gulp to monitor your dev environment for any changes that need post processing using `npm start` command.
|
||||
|
||||
*Please note gulp must be running at all times while you are working with Sonarr client source files.*
|
||||
|
||||
### Development
|
||||
|
||||
* Open `NzbDrone.sln` in Visual Studio
|
||||
* Make sure `NzbDrone.Console` is set as the startup project
|
||||
|
||||
### License
|
||||
|
||||
* [GNU GPL v3](http://www.gnu.org/licenses/gpl.html)
|
||||
* Copyright 2010-2017
|
||||
|
||||
### Sponsors
|
||||
|
||||
* [JetBrains](http://www.jetbrains.com/) for providing us with free licenses to their great tools
|
||||
* [ReSharper](http://www.jetbrains.com/resharper/)
|
||||
* [WebStorm](http://www.jetbrains.com/webstorm/)
|
||||
* [TeamCity](http://www.jetbrains.com/teamcity/)
|
||||
@@ -25,7 +25,7 @@ gulp.task('copyHtml', function () {
|
||||
});
|
||||
|
||||
gulp.task('copyContent', function () {
|
||||
return gulp.src([paths.src.content + '**/*.*', '!**/*.less'])
|
||||
return gulp.src([paths.src.content + '**/*.*', '!**/*.less', '!**/*.css'])
|
||||
.pipe(gulp.dest(paths.dest.content))
|
||||
.pipe(livereload());
|
||||
});
|
||||
|
||||
11
gulp/less.js
@@ -5,7 +5,7 @@ var postcss = require('gulp-postcss');
|
||||
var sourcemaps = require('gulp-sourcemaps');
|
||||
var autoprefixer = require('autoprefixer-core');
|
||||
var livereload = require('gulp-livereload');
|
||||
|
||||
var cleancss = require('gulp-clean-css');
|
||||
var print = require('gulp-print');
|
||||
var paths = require('./paths');
|
||||
var errorHandler = require('./errorHandler');
|
||||
@@ -16,6 +16,10 @@ gulp.task('less', function() {
|
||||
paths.src.content + 'bootstrap.less',
|
||||
paths.src.content + 'theme.less',
|
||||
paths.src.content + 'overrides.less',
|
||||
paths.src.content + 'bootstrap.toggle-switch.css',
|
||||
paths.src.content + 'fullcalendar.css',
|
||||
paths.src.content + 'Messenger/messenger.css',
|
||||
paths.src.content + 'Messenger/messenger.flat.css',
|
||||
paths.src.root + 'Series/series.less',
|
||||
paths.src.root + 'Activity/activity.less',
|
||||
paths.src.root + 'AddSeries/addSeries.less',
|
||||
@@ -33,12 +37,13 @@ gulp.task('less', function() {
|
||||
.pipe(sourcemaps.init())
|
||||
.pipe(less({
|
||||
dumpLineNumbers : 'false',
|
||||
compress : true,
|
||||
yuicompress : true,
|
||||
compress : false,
|
||||
yuicompress : false,
|
||||
ieCompat : true,
|
||||
strictImports : true
|
||||
}))
|
||||
.pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
|
||||
.pipe(cleancss())
|
||||
.on('error', errorHandler.onError)
|
||||
.pipe(sourcemaps.write(paths.dest.content))
|
||||
.pipe(gulp.dest(paths.dest.content))
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"del": "1.2.0",
|
||||
"gulp": "3.9.0",
|
||||
"gulp-cached": "1.1.0",
|
||||
"gulp-clean-css": "^3.0.4",
|
||||
"gulp-concat": "2.6.0",
|
||||
"gulp-declare": "0.3.0",
|
||||
"gulp-handlebars": "3.0.1",
|
||||
|
||||
53
readme.md
@@ -1,53 +0,0 @@
|
||||
# Sonarr #
|
||||
|
||||
|
||||
Sonarr is a PVR for Usenet and BitTorrent users. It can monitor multiple RSS feeds for new episodes of your favorite shows and will grab, sort and rename them. It can also be configured to automatically upgrade the quality of files already downloaded when a better quality format becomes available.
|
||||
|
||||
## Major Features Include: ##
|
||||
|
||||
* Support for major platforms: Windows, Linux, OSX, Raspberry Pi, etc.
|
||||
* Automatically detects new episodes
|
||||
* Can scan your existing library and download any missing episodes
|
||||
* Can watch for better quality of the episodes you already have and do an automatic upgrade. *eg. from DVD to Blu-Ray*
|
||||
* Automatic failed download handling will try another release if one fails
|
||||
* Manual search so you can pick any release or to see why a release was not downloaded automatically
|
||||
* Fully configurable episode renaming
|
||||
* Full integration with SABNzbd and NzbGet
|
||||
* Full integration with XBMC, Plex (notification, library update, metadata)
|
||||
* Full support for specials and multi-episode releases
|
||||
* And a beautiful UI
|
||||
|
||||
|
||||
## Configuring Development Environment: ##
|
||||
|
||||
### Requirements ###
|
||||
- Visual Studio 2015 [Free Community Edition](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx)
|
||||
- [Git](http://git-scm.com/downloads)
|
||||
- [NodeJS](http://nodejs.org/download/)
|
||||
|
||||
### Setup ###
|
||||
|
||||
- Make sure all the required software mentioned above are installed.
|
||||
- Clone the repository into your development machine. [*info*](https://help.github.com/articles/working-with-repositories)
|
||||
- Grab the submodules `git submodule init && git submodule update`
|
||||
- install the required Node Packages `npm install`
|
||||
- start gulp to monitor your dev environment for any changes that need post processing using `npm start` command.
|
||||
|
||||
*Please note gulp must be running at all times while you are working with Sonarr client source files.*
|
||||
|
||||
|
||||
### Development ###
|
||||
- Open `NzbDrone.sln` in Visual Studio
|
||||
- Make sure `NzbDrone.Console` is set as the startup project
|
||||
|
||||
|
||||
### License ###
|
||||
* [GNU GPL v3](http://www.gnu.org/licenses/gpl.html)
|
||||
Copyright 2010-2016
|
||||
|
||||
|
||||
### Sponsors ###
|
||||
- [JetBrains](http://www.jetbrains.com/) for providing us with free licenses to their great tools
|
||||
- [ReSharper](http://www.jetbrains.com/resharper/)
|
||||
- [WebStorm](http://www.jetbrains.com/webstorm/)
|
||||
- [TeamCity](http://www.jetbrains.com/teamcity/)
|
||||
@@ -52,8 +52,7 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.3\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="4.4.1" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.3" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -42,17 +42,17 @@
|
||||
<HintPath>..\packages\NBuilder.4.0.0\lib\net40\FizzWare.NBuilder.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.5.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="4.18.0" targetFramework="net40" />
|
||||
<package id="FluentAssertions" version="4.19.0" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="4.0.0" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.5.0" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.6.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -33,12 +33,12 @@ namespace NzbDrone.Api.Authentication
|
||||
{
|
||||
if (_configFileProvider.AuthenticationMethod == AuthenticationType.Forms)
|
||||
{
|
||||
RegisterFormsAuth(pipelines);
|
||||
RegisterFormsAuth(pipelines);
|
||||
}
|
||||
|
||||
else if (_configFileProvider.AuthenticationMethod == AuthenticationType.Basic)
|
||||
{
|
||||
pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(_authenticationService, "Sonarr"));
|
||||
pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(_authenticationService, "Sonarr"));
|
||||
}
|
||||
|
||||
pipelines.BeforeRequest.AddItemToEndOfPipeline((Func<NancyContext, Response>) RequiresAuthentication);
|
||||
@@ -64,10 +64,13 @@ namespace NzbDrone.Api.Authentication
|
||||
new DefaultHmacProvider(new PassphraseKeyGenerator(_configService.HmacPassphrase, Encoding.ASCII.GetBytes(_configService.HmacSalt)))
|
||||
);
|
||||
|
||||
FormsAuthentication.FormsAuthenticationCookieName = "_ncfa_sonarr";
|
||||
|
||||
FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration
|
||||
{
|
||||
RedirectUrl = _configFileProvider.UrlBase + "/login",
|
||||
UserMapper = _authenticationService,
|
||||
Path = _configFileProvider.UrlBase,
|
||||
CryptographyConfiguration = cryptographyConfiguration
|
||||
});
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace NzbDrone.Api.Calendar
|
||||
var end = DateTime.Today.AddDays(futureDays);
|
||||
var unmonitored = false;
|
||||
var premiersOnly = false;
|
||||
var asAllDay = false;
|
||||
var tags = new List<int>();
|
||||
|
||||
// TODO: Remove start/end parameters in v3, they don't work well for iCal
|
||||
@@ -46,6 +47,7 @@ namespace NzbDrone.Api.Calendar
|
||||
var queryFutureDays = Request.Query.FutureDays;
|
||||
var queryUnmonitored = Request.Query.Unmonitored;
|
||||
var queryPremiersOnly = Request.Query.PremiersOnly;
|
||||
var queryAsAllDay = Request.Query.AsAllDay;
|
||||
var queryTags = Request.Query.Tags;
|
||||
|
||||
if (queryStart.HasValue) start = DateTime.Parse(queryStart.Value);
|
||||
@@ -73,6 +75,11 @@ namespace NzbDrone.Api.Calendar
|
||||
premiersOnly = bool.Parse(queryPremiersOnly.Value);
|
||||
}
|
||||
|
||||
if (queryAsAllDay.HasValue)
|
||||
{
|
||||
asAllDay = bool.Parse(queryAsAllDay.Value);
|
||||
}
|
||||
|
||||
if (queryTags.HasValue)
|
||||
{
|
||||
var tagInput = (string)queryTags.Value.ToString();
|
||||
@@ -102,11 +109,19 @@ namespace NzbDrone.Api.Calendar
|
||||
var occurrence = calendar.Create<Event>();
|
||||
occurrence.Uid = "NzbDrone_episode_" + episode.Id;
|
||||
occurrence.Status = episode.HasFile ? EventStatus.Confirmed : EventStatus.Tentative;
|
||||
occurrence.Start = new CalDateTime(episode.AirDateUtc.Value) { HasTime = true };
|
||||
occurrence.End = new CalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true };
|
||||
occurrence.Description = episode.Overview;
|
||||
occurrence.Categories = new List<string>() { episode.Series.Network };
|
||||
|
||||
if (asAllDay)
|
||||
{
|
||||
occurrence.Start = new CalDateTime(episode.AirDateUtc.Value) { HasTime = false };
|
||||
}
|
||||
else
|
||||
{
|
||||
occurrence.Start = new CalDateTime(episode.AirDateUtc.Value) { HasTime = true };
|
||||
occurrence.End = new CalDateTime(episode.AirDateUtc.Value.AddMinutes(episode.Series.Runtime)) { HasTime = true };
|
||||
}
|
||||
|
||||
switch (episode.Series.SeriesType)
|
||||
{
|
||||
case SeriesTypes.Daily:
|
||||
|
||||
@@ -73,14 +73,14 @@ namespace NzbDrone.Api.ClientSchema
|
||||
|
||||
if (propertyInfo.PropertyType == typeof(int))
|
||||
{
|
||||
var value = Convert.ToInt32(field.Value);
|
||||
propertyInfo.SetValue(target, value, null);
|
||||
var value = field.Value.ToString().ParseInt32();
|
||||
propertyInfo.SetValue(target, value ?? 0, null);
|
||||
}
|
||||
|
||||
else if (propertyInfo.PropertyType == typeof(long))
|
||||
{
|
||||
var value = Convert.ToInt64(field.Value);
|
||||
propertyInfo.SetValue(target, value, null);
|
||||
var value = field.Value.ToString().ParseInt64();
|
||||
propertyInfo.SetValue(target, value ?? 0, null);
|
||||
}
|
||||
|
||||
else if (propertyInfo.PropertyType == typeof(int?))
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace NzbDrone.Api.Config
|
||||
|
||||
public bool SkipFreeSpaceCheckWhenImporting { get; set; }
|
||||
public bool CopyUsingHardlinks { get; set; }
|
||||
public bool ImportExtraFiles { get; set; }
|
||||
public string ExtraFileExtensions { get; set; }
|
||||
public bool EnableMediaInfo { get; set; }
|
||||
}
|
||||
@@ -44,6 +45,7 @@ namespace NzbDrone.Api.Config
|
||||
|
||||
SkipFreeSpaceCheckWhenImporting = model.SkipFreeSpaceCheckWhenImporting,
|
||||
CopyUsingHardlinks = model.CopyUsingHardlinks,
|
||||
ImportExtraFiles = model.ImportExtraFiles,
|
||||
ExtraFileExtensions = model.ExtraFileExtensions,
|
||||
EnableMediaInfo = model.EnableMediaInfo
|
||||
};
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using NzbDrone.Api.REST;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.MediaFiles.Events;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.SignalR;
|
||||
using HttpStatusCode = System.Net.HttpStatusCode;
|
||||
|
||||
namespace NzbDrone.Api.EpisodeFiles
|
||||
{
|
||||
@@ -16,24 +15,21 @@ namespace NzbDrone.Api.EpisodeFiles
|
||||
IHandle<EpisodeFileAddedEvent>
|
||||
{
|
||||
private readonly IMediaFileService _mediaFileService;
|
||||
private readonly IRecycleBinProvider _recycleBinProvider;
|
||||
private readonly IDeleteMediaFiles _mediaFileDeletionService;
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IQualityUpgradableSpecification _qualityUpgradableSpecification;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public EpisodeFileModule(IBroadcastSignalRMessage signalRBroadcaster,
|
||||
IMediaFileService mediaFileService,
|
||||
IRecycleBinProvider recycleBinProvider,
|
||||
IDeleteMediaFiles mediaFileDeletionService,
|
||||
ISeriesService seriesService,
|
||||
IQualityUpgradableSpecification qualityUpgradableSpecification,
|
||||
Logger logger)
|
||||
IQualityUpgradableSpecification qualityUpgradableSpecification)
|
||||
: base(signalRBroadcaster)
|
||||
{
|
||||
_mediaFileService = mediaFileService;
|
||||
_recycleBinProvider = recycleBinProvider;
|
||||
_mediaFileDeletionService = mediaFileDeletionService;
|
||||
_seriesService = seriesService;
|
||||
_qualityUpgradableSpecification = qualityUpgradableSpecification;
|
||||
_logger = logger;
|
||||
GetResourceById = GetEpisodeFile;
|
||||
GetResourceAll = GetEpisodeFiles;
|
||||
UpdateResource = SetQuality;
|
||||
@@ -72,12 +68,15 @@ namespace NzbDrone.Api.EpisodeFiles
|
||||
private void DeleteEpisodeFile(int id)
|
||||
{
|
||||
var episodeFile = _mediaFileService.Get(id);
|
||||
var series = _seriesService.GetSeries(episodeFile.SeriesId);
|
||||
var fullPath = Path.Combine(series.Path, episodeFile.RelativePath);
|
||||
|
||||
_logger.Info("Deleting episode file: {0}", fullPath);
|
||||
_recycleBinProvider.DeleteFile(fullPath);
|
||||
_mediaFileService.Delete(episodeFile, DeleteMediaFileReason.Manual);
|
||||
if (episodeFile == null)
|
||||
{
|
||||
throw new NzbDroneClientException(HttpStatusCode.NotFound, "Episode file not found");
|
||||
}
|
||||
|
||||
var series = _seriesService.GetSeries(episodeFile.SeriesId);
|
||||
|
||||
_mediaFileDeletionService.DeleteEpisodeFile(series, episodeFile);
|
||||
}
|
||||
|
||||
public void Handle(EpisodeFileAddedEvent message)
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace NzbDrone.Api.Episodes
|
||||
{
|
||||
public abstract class EpisodeModuleWithSignalR : NzbDroneRestModuleWithSignalR<EpisodeResource, Episode>,
|
||||
IHandle<EpisodeGrabbedEvent>,
|
||||
IHandle<EpisodeDownloadedEvent>
|
||||
IHandle<EpisodeImportedEvent>
|
||||
{
|
||||
protected readonly IEpisodeService _episodeService;
|
||||
protected readonly ISeriesService _seriesService;
|
||||
@@ -115,9 +115,14 @@ namespace NzbDrone.Api.Episodes
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(EpisodeDownloadedEvent message)
|
||||
public void Handle(EpisodeImportedEvent message)
|
||||
{
|
||||
foreach (var episode in message.Episode.Episodes)
|
||||
if (!message.NewDownload)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var episode in message.EpisodeInfo.Episodes)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Updated, episode.Id);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace NzbDrone.Api.Extensions.Pipelines
|
||||
context.Items["ApiRequestStartTime"] = DateTime.UtcNow;
|
||||
|
||||
var reqPath = GetRequestPathAndQuery(context.Request);
|
||||
|
||||
|
||||
_loggerHttp.Trace("Req: {0} [{1}] {2}", id, context.Request.Method, reqPath);
|
||||
|
||||
return null;
|
||||
@@ -80,7 +80,7 @@ namespace NzbDrone.Api.Extensions.Pipelines
|
||||
{
|
||||
if (request.Url.Query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return string.Concat(request.Url.Path, "?", request.Url.Query);
|
||||
return string.Concat(request.Url.Path, request.Url.Query);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -88,4 +88,4 @@ namespace NzbDrone.Api.Extensions.Pipelines
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
46
src/NzbDrone.Api/Extensions/Pipelines/UrlBasePipeline.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using Nancy;
|
||||
using Nancy.Bootstrapper;
|
||||
using Nancy.Responses;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
|
||||
namespace NzbDrone.Api.Extensions.Pipelines
|
||||
{
|
||||
public class UrlBasePipeline : IRegisterNancyPipeline
|
||||
{
|
||||
private readonly string _urlBase;
|
||||
|
||||
public UrlBasePipeline(IConfigFileProvider configFileProvider)
|
||||
{
|
||||
_urlBase = configFileProvider.UrlBase;
|
||||
}
|
||||
|
||||
public int Order => 99;
|
||||
|
||||
public void Register(IPipelines pipelines)
|
||||
{
|
||||
if (_urlBase.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
pipelines.BeforeRequest.AddItemToStartOfPipeline((Func<NancyContext, Response>) Handle);
|
||||
}
|
||||
}
|
||||
|
||||
private Response Handle(NancyContext context)
|
||||
{
|
||||
var basePath = context.Request.Url.BasePath;
|
||||
|
||||
if (basePath.IsNullOrWhiteSpace())
|
||||
{
|
||||
return new RedirectResponse($"{_urlBase}{context.Request.Path}{context.Request.Url.Query}");
|
||||
}
|
||||
|
||||
if (_urlBase != basePath)
|
||||
{
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Nancy;
|
||||
@@ -17,7 +17,7 @@ namespace NzbDrone.Api.Frontend.Mappers
|
||||
private readonly IAnalyticsService _analyticsService;
|
||||
private readonly Func<ICacheBreakerProvider> _cacheBreakProviderFactory;
|
||||
private readonly string _indexPath;
|
||||
private static readonly Regex ReplaceRegex = new Regex(@"(?:(?<attribute>href|src)=\"")(?<path>.*?(?<extension>css|js|png|ico|ics))(?:\"")(?:\s(?<nohash>data-no-hash))?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
private static readonly Regex ReplaceRegex = new Regex(@"(?:(?<attribute>href|src)=\"")(?<path>.*?(?<extension>css|js|png|ico|ics|svg))(?:\"")(?:\s(?<nohash>data-no-hash))?", RegexOptions.Compiled | RegexOptions.IgnoreCase);
|
||||
|
||||
private static string API_KEY;
|
||||
private static string URL_BASE;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.IO;
|
||||
using NLog;
|
||||
using Nancy;
|
||||
@@ -38,7 +38,7 @@ namespace NzbDrone.Api.Frontend.Mappers
|
||||
if (_diskProvider.FileExists(filePath, _caseSensitive))
|
||||
{
|
||||
var response = new StreamResponse(() => GetContentStream(filePath), MimeTypes.GetMimeType(filePath));
|
||||
return response;
|
||||
return new MaterialisingResponse(response);
|
||||
}
|
||||
|
||||
_logger.Warn("File {0} not found", filePath);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Nancy.Responses;
|
||||
@@ -38,20 +38,6 @@ namespace NzbDrone.Api.Frontend
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
//Redirect to the subfolder if the request went to the base URL
|
||||
if (path.Equals("/"))
|
||||
{
|
||||
var urlBase = _configFileProvider.UrlBase;
|
||||
|
||||
if (!string.IsNullOrEmpty(urlBase))
|
||||
{
|
||||
if (Request.Url.BasePath != urlBase)
|
||||
{
|
||||
return new RedirectResponse(urlBase + "/");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mapper = _requestMappers.SingleOrDefault(m => m.CanHandle(path));
|
||||
|
||||
if (mapper != null)
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace NzbDrone.Api.Indexers
|
||||
|
||||
private Response DownloadRelease(ReleaseResource release)
|
||||
{
|
||||
var remoteEpisode = _remoteEpisodeCache.Find(release.Guid);
|
||||
var remoteEpisode = _remoteEpisodeCache.Find(GetCacheKey(release));
|
||||
|
||||
if (remoteEpisode == null)
|
||||
{
|
||||
@@ -68,7 +68,7 @@ namespace NzbDrone.Api.Indexers
|
||||
}
|
||||
catch (ReleaseDownloadException ex)
|
||||
{
|
||||
_logger.Error(ex);
|
||||
_logger.Error(ex, ex.Message);
|
||||
throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed");
|
||||
}
|
||||
|
||||
@@ -113,8 +113,14 @@ namespace NzbDrone.Api.Indexers
|
||||
|
||||
protected override ReleaseResource MapDecision(DownloadDecision decision, int initialWeight)
|
||||
{
|
||||
_remoteEpisodeCache.Set(decision.RemoteEpisode.Release.Guid, decision.RemoteEpisode, TimeSpan.FromMinutes(30));
|
||||
return base.MapDecision(decision, initialWeight);
|
||||
var resource = base.MapDecision(decision, initialWeight);
|
||||
_remoteEpisodeCache.Set(GetCacheKey(resource), decision.RemoteEpisode, TimeSpan.FromMinutes(30));
|
||||
return resource;
|
||||
}
|
||||
|
||||
private string GetCacheKey(ReleaseResource resource)
|
||||
{
|
||||
return string.Concat(resource.IndexerId, "_", resource.Guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,20 +41,17 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="antlr.runtime, Version=2.7.6.2, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ical.Net.2.2.25\lib\net40\antlr.runtime.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Ical.Net.2.2.32\lib\net40\antlr.runtime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentValidation, Version=6.2.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentValidation.6.2.1.0\lib\portable-net40+sl50+wp80+win8+wpa81\FluentValidation.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Ical.Net, Version=2.1.0.30332, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ical.Net.2.2.25\lib\net40\Ical.Net.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="Ical.Net, Version=2.1.0.18776, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ical.Net.2.2.32\lib\net40\Ical.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Ical.Net.Collections, Version=2.1.0.30331, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ical.Net.2.2.25\lib\net40\Ical.Net.Collections.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="Ical.Net.Collections, Version=2.1.0.18775, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ical.Net.2.2.32\lib\net40\Ical.Net.Collections.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nancy, Version=1.4.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Nancy.1.4.3\lib\net40\Nancy.dll</HintPath>
|
||||
@@ -73,12 +70,10 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.3\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NodaTime, Version=1.3.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Ical.Net.2.2.25\lib\net40\NodaTime.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Ical.Net.2.2.32\lib\net40\NodaTime.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -111,6 +106,7 @@
|
||||
<Compile Include="Commands\CommandResource.cs" />
|
||||
<Compile Include="Extensions\AccessControlHeaders.cs" />
|
||||
<Compile Include="Extensions\Pipelines\CorsPipeline.cs" />
|
||||
<Compile Include="Extensions\Pipelines\UrlBasePipeline.cs" />
|
||||
<Compile Include="Extensions\Pipelines\RequestLoggingPipeline.cs" />
|
||||
<Compile Include="Frontend\Mappers\LoginHtmlMapper.cs" />
|
||||
<Compile Include="Frontend\Mappers\RobotsTxtMapper.cs" />
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace NzbDrone.Api.Series
|
||||
|
||||
public static List<Season> ToModel(this IEnumerable<SeasonResource> resources)
|
||||
{
|
||||
return resources.Select(ToModel).ToList();
|
||||
return resources?.Select(ToModel).ToList() ?? new List<Season>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,14 @@ namespace NzbDrone.Api.Series
|
||||
|
||||
{
|
||||
private readonly ISeriesService _seriesService;
|
||||
private readonly IAddSeriesService _addSeriesService;
|
||||
private readonly ISeriesStatisticsService _seriesStatisticsService;
|
||||
private readonly ISceneMappingService _sceneMappingService;
|
||||
private readonly IMapCoversToLocal _coverMapper;
|
||||
|
||||
public SeriesModule(IBroadcastSignalRMessage signalRBroadcaster,
|
||||
ISeriesService seriesService,
|
||||
IAddSeriesService addSeriesService,
|
||||
ISeriesStatisticsService seriesStatisticsService,
|
||||
ISceneMappingService sceneMappingService,
|
||||
IMapCoversToLocal coverMapper,
|
||||
@@ -48,6 +50,7 @@ namespace NzbDrone.Api.Series
|
||||
: base(signalRBroadcaster)
|
||||
{
|
||||
_seriesService = seriesService;
|
||||
_addSeriesService = addSeriesService;
|
||||
_seriesStatisticsService = seriesStatisticsService;
|
||||
_sceneMappingService = sceneMappingService;
|
||||
|
||||
@@ -74,7 +77,6 @@ namespace NzbDrone.Api.Series
|
||||
|
||||
PostValidator.RuleFor(s => s.Path).IsValidPath().When(s => s.RootFolderPath.IsNullOrWhiteSpace());
|
||||
PostValidator.RuleFor(s => s.RootFolderPath).IsValidPath().When(s => s.Path.IsNullOrWhiteSpace());
|
||||
PostValidator.RuleFor(s => s.Title).NotEmpty();
|
||||
PostValidator.RuleFor(s => s.TvdbId).GreaterThan(0).SetValidator(seriesExistsValidator);
|
||||
|
||||
PutValidator.RuleFor(s => s.Path).IsValidPath();
|
||||
@@ -114,7 +116,7 @@ namespace NzbDrone.Api.Series
|
||||
{
|
||||
var model = seriesResource.ToModel();
|
||||
|
||||
return _seriesService.AddSeries(model).Id;
|
||||
return _addSeriesService.AddSeries(model).Id;
|
||||
}
|
||||
|
||||
private void UpdateSeries(SeriesResource seriesResource)
|
||||
|
||||
@@ -207,19 +207,9 @@ namespace NzbDrone.Api.Series
|
||||
|
||||
public static Core.Tv.Series ToModel(this SeriesResource resource, Core.Tv.Series series)
|
||||
{
|
||||
series.TvdbId = resource.TvdbId;
|
||||
var updatedSeries = resource.ToModel();
|
||||
|
||||
series.Seasons = resource.Seasons.ToModel();
|
||||
series.Path = resource.Path;
|
||||
series.ProfileId = resource.ProfileId;
|
||||
|
||||
series.SeasonFolder = resource.SeasonFolder;
|
||||
series.Monitored = resource.Monitored;
|
||||
|
||||
series.SeriesType = resource.SeriesType;
|
||||
series.RootFolderPath = resource.RootFolderPath;
|
||||
series.Tags = resource.Tags;
|
||||
series.AddOptions = resource.AddOptions;
|
||||
series.ApplyChanges(updatedSeries);
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentValidation" version="6.2.1.0" targetFramework="net40" />
|
||||
<package id="Ical.Net" version="2.2.25" targetFramework="net40" />
|
||||
<package id="Ical.Net" version="2.2.32" targetFramework="net40" />
|
||||
<package id="Nancy" version="1.4.3" targetFramework="net40" />
|
||||
<package id="Nancy.Authentication.Basic" version="1.4.1" targetFramework="net40" />
|
||||
<package id="Nancy.Authentication.Forms" version="1.4.1" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.1" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.3" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -41,21 +41,17 @@
|
||||
<HintPath>..\packages\NBuilder.4.0.0\lib\net40\FizzWare.NBuilder.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.3\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.5.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="4.18.0" targetFramework="net40" />
|
||||
<package id="FluentAssertions" version="4.19.0" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NBuilder" version="4.0.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.1" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.5.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.3" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.6.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -38,21 +38,17 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FluentAssertions, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.3\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.5.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -62,13 +58,11 @@
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="WebDriver, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Selenium.WebDriver.3.0.1\lib\net40\WebDriver.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="WebDriver, Version=3.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Selenium.WebDriver.3.2.0\lib\net40\WebDriver.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="WebDriver.Support, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Selenium.Support.3.0.1\lib\net40\WebDriver.Support.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="WebDriver.Support, Version=3.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Selenium.Support.3.2.0\lib\net40\WebDriver.Support.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="4.18.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.1" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.5.0" targetFramework="net40" />
|
||||
<package id="Selenium.Support" version="3.0.1" targetFramework="net40" />
|
||||
<package id="Selenium.WebDriver" version="3.0.1" targetFramework="net40" />
|
||||
<package id="FluentAssertions" version="4.19.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.3" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.6.0" targetFramework="net40" />
|
||||
<package id="Selenium.Support" version="3.2.0" targetFramework="net40" />
|
||||
<package id="Selenium.WebDriver" version="3.2.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -16,6 +16,7 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
private readonly string _targetPath = @"C:\target\my.video.mkv".AsOsAgnostic();
|
||||
private readonly string _backupPath = @"C:\source\my.video.mkv.backup~".AsOsAgnostic();
|
||||
private readonly string _tempTargetPath = @"C:\target\my.video.mkv.partial~".AsOsAgnostic();
|
||||
private readonly string _nfsFile = ".nfs01231232";
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@@ -642,6 +643,21 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
VerifyCopyFolder(source.FullName, destination.FullName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopyFolder_should_ignore_nfs_temp_file()
|
||||
{
|
||||
WithRealDiskProvider();
|
||||
|
||||
var source = GetFilledTempFolder();
|
||||
|
||||
File.WriteAllText(Path.Combine(source.FullName, _nfsFile), "SubFile1");
|
||||
|
||||
var destination = new DirectoryInfo(GetTempFilePath());
|
||||
|
||||
Subject.TransferFolder(source.FullName, destination.FullName, TransferMode.Copy);
|
||||
|
||||
File.Exists(Path.Combine(destination.FullName, _nfsFile)).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MoveFolder_should_move_folder()
|
||||
@@ -704,6 +720,26 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
destination.GetFileSystemInfos().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MirrorFolder_should_not_remove_nfs_files()
|
||||
{
|
||||
WithRealDiskProvider();
|
||||
|
||||
var original = GetFilledTempFolder();
|
||||
var source = new DirectoryInfo(GetTempFilePath());
|
||||
var destination = new DirectoryInfo(GetTempFilePath());
|
||||
|
||||
source.Create();
|
||||
Subject.TransferFolder(original.FullName, destination.FullName, TransferMode.Copy);
|
||||
|
||||
File.WriteAllText(Path.Combine(destination.FullName, _nfsFile), "SubFile1");
|
||||
|
||||
var count = Subject.MirrorFolder(source.FullName, destination.FullName);
|
||||
|
||||
count.Should().Equals(0);
|
||||
destination.GetFileSystemInfos().Should().HaveCount(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MirrorFolder_should_add_new_files()
|
||||
{
|
||||
@@ -721,6 +757,24 @@ namespace NzbDrone.Common.Test.DiskTests
|
||||
VerifyCopyFolder(original.FullName, destination.FullName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MirrorFolder_should_ignore_nfs_temp_file()
|
||||
{
|
||||
WithRealDiskProvider();
|
||||
|
||||
var source = GetFilledTempFolder();
|
||||
|
||||
File.WriteAllText(Path.Combine(source.FullName, _nfsFile), "SubFile1");
|
||||
|
||||
var destination = new DirectoryInfo(GetTempFilePath());
|
||||
|
||||
var count = Subject.MirrorFolder(source.FullName, destination.FullName);
|
||||
|
||||
count.Should().Equals(3);
|
||||
|
||||
File.Exists(Path.Combine(destination.FullName, _nfsFile)).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MirrorFolder_should_not_touch_equivalent_files()
|
||||
{
|
||||
|
||||
21
src/NzbDrone.Common.Test/HashUtilFixture.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class HashUtilFixture
|
||||
{
|
||||
[Test]
|
||||
public void should_create_anon_id()
|
||||
{
|
||||
HashUtil.AnonymousToken().Should().NotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_create_the_same_id()
|
||||
{
|
||||
HashUtil.AnonymousToken().Should().Be(HashUtil.AnonymousToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.Http;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Test.Http
|
||||
{
|
||||
@@ -36,5 +37,17 @@ namespace NzbDrone.Common.Test.Http
|
||||
Action action = () => httpheader.GetEncodingFromContentType();
|
||||
action.ShouldThrow<ArgumentException>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_parse_cookie_with_trailing_semi_colon()
|
||||
{
|
||||
var cookies = HttpHeader.ParseCookies("uid=123456; pass=123456b2f3abcde42ac3a123f3f1fc9f;");
|
||||
|
||||
cookies.Count.Should().Be(2);
|
||||
cookies.First().Key.Should().Be("uid");
|
||||
cookies.First().Value.Should().Be("123456");
|
||||
cookies.Last().Key.Should().Be("pass");
|
||||
cookies.Last().Value.Should().Be("123456b2f3abcde42ac3a123f3f1fc9f");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,21 +37,17 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FluentAssertions, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.18.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.18.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="FluentAssertions.Core, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.3\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.5.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.6.0\lib\net40\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@@ -84,6 +80,7 @@
|
||||
<Compile Include="ExtensionTests\IEnumerableExtensionTests\ExceptByFixture.cs" />
|
||||
<Compile Include="ExtensionTests\IEnumerableExtensionTests\IntersectByFixture.cs" />
|
||||
<Compile Include="ExtensionTests\Int64ExtensionFixture.cs" />
|
||||
<Compile Include="HashUtilFixture.cs" />
|
||||
<Compile Include="Http\HttpClientFixture.cs" />
|
||||
<Compile Include="Http\HttpHeaderFixture.cs" />
|
||||
<Compile Include="Http\HttpRequestBuilderFixture.cs" />
|
||||
|
||||
@@ -86,7 +86,7 @@ namespace NzbDrone.Common.Test
|
||||
{
|
||||
first.AsOsAgnostic().PathEquals(second.AsOsAgnostic()).Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_not_a_child()
|
||||
{
|
||||
@@ -113,6 +113,7 @@ namespace NzbDrone.Common.Test
|
||||
[TestCase(@"C:\Test\", @"C:\Test\mydir")]
|
||||
[TestCase(@"C:\Test\", @"C:\Test\mydir\")]
|
||||
[TestCase(@"C:\Test", @"C:\Test\30.Rock.S01E01.Pilot.avi")]
|
||||
[TestCase(@"C:\", @"C:\Test\30.Rock.S01E01.Pilot.avi")]
|
||||
public void path_should_be_parent(string parentPath, string childPath)
|
||||
{
|
||||
parentPath.AsOsAgnostic().IsParentPath(childPath.AsOsAgnostic()).Should().BeTrue();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="4.18.0" targetFramework="net40" />
|
||||
<package id="FluentAssertions" version="4.19.0" targetFramework="net40" />
|
||||
<package id="Moq" version="4.0.10827" />
|
||||
<package id="NLog" version="4.4.1" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.5.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.3" targetFramework="net40" />
|
||||
<package id="NUnit" version="3.6.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -64,11 +64,15 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
foreach (var subDir in _diskProvider.GetDirectoryInfos(sourcePath))
|
||||
{
|
||||
if (ShouldIgnore(subDir)) continue;
|
||||
|
||||
result &= TransferFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name), mode, verificationMode);
|
||||
}
|
||||
|
||||
foreach (var sourceFile in _diskProvider.GetFileInfos(sourcePath))
|
||||
{
|
||||
if (ShouldIgnore(sourceFile)) continue;
|
||||
|
||||
var destFile = Path.Combine(targetPath, sourceFile.Name);
|
||||
|
||||
result &= TransferFile(sourceFile.FullName, destFile, mode, true, verificationMode);
|
||||
@@ -101,11 +105,15 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
foreach (var subDir in targetFolders.Where(v => !sourceFolders.Any(d => d.Name == v.Name)))
|
||||
{
|
||||
if (ShouldIgnore(subDir)) continue;
|
||||
|
||||
_diskProvider.DeleteFolder(subDir.FullName, true);
|
||||
}
|
||||
|
||||
foreach (var subDir in sourceFolders)
|
||||
{
|
||||
if (ShouldIgnore(subDir)) continue;
|
||||
|
||||
filesCopied += MirrorFolder(subDir.FullName, Path.Combine(targetPath, subDir.Name));
|
||||
}
|
||||
|
||||
@@ -114,11 +122,15 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
foreach (var targetFile in targetFiles.Where(v => !sourceFiles.Any(d => d.Name == v.Name)))
|
||||
{
|
||||
if (ShouldIgnore(targetFile)) continue;
|
||||
|
||||
_diskProvider.DeleteFile(targetFile.FullName);
|
||||
}
|
||||
|
||||
foreach (var sourceFile in sourceFiles)
|
||||
{
|
||||
if (ShouldIgnore(sourceFile)) continue;
|
||||
|
||||
var targetFile = Path.Combine(targetPath, sourceFile.Name);
|
||||
|
||||
if (CompareFiles(sourceFile.FullName, targetFile))
|
||||
@@ -564,5 +576,27 @@ namespace NzbDrone.Common.Disk
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldIgnore(DirectoryInfo folder)
|
||||
{
|
||||
if (folder.Name.StartsWith(".nfs"))
|
||||
{
|
||||
_logger.Trace("Ignoring folder {0}", folder.FullName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ShouldIgnore(FileInfo file)
|
||||
{
|
||||
if (file.Name.StartsWith(".nfs") || file.Name == "debug.log" || file.Name.EndsWith(".socket"))
|
||||
{
|
||||
_logger.Trace("Ignoring file {0}", file.FullName);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
namespace NzbDrone.Common.Disk
|
||||
@@ -8,10 +9,11 @@ namespace NzbDrone.Common.Disk
|
||||
private readonly DriveInfo _driveInfo;
|
||||
private readonly DriveType _driveType;
|
||||
|
||||
public DriveInfoMount(DriveInfo driveInfo, DriveType driveType = DriveType.Unknown)
|
||||
public DriveInfoMount(DriveInfo driveInfo, DriveType driveType = DriveType.Unknown, MountOptions mountOptions = null)
|
||||
{
|
||||
_driveInfo = driveInfo;
|
||||
_driveType = driveType;
|
||||
MountOptions = mountOptions;
|
||||
}
|
||||
|
||||
public long AvailableFreeSpace => _driveInfo.AvailableFreeSpace;
|
||||
@@ -33,6 +35,8 @@ namespace NzbDrone.Common.Disk
|
||||
|
||||
public bool IsReady => _driveInfo.IsReady;
|
||||
|
||||
public MountOptions MountOptions { get; private set; }
|
||||
|
||||
public string Name => _driveInfo.Name;
|
||||
|
||||
public string RootDirectory => _driveInfo.RootDirectory.FullName;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace NzbDrone.Common.Disk
|
||||
@@ -8,6 +9,7 @@ namespace NzbDrone.Common.Disk
|
||||
string DriveFormat { get; }
|
||||
DriveType DriveType { get; }
|
||||
bool IsReady { get; }
|
||||
MountOptions MountOptions { get; }
|
||||
string Name { get; }
|
||||
string RootDirectory { get; }
|
||||
long TotalFreeSpace { get; }
|
||||
|
||||
16
src/NzbDrone.Common/Disk/MountOptions.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Common.Disk
|
||||
{
|
||||
public class MountOptions
|
||||
{
|
||||
private readonly Dictionary<string, string> _options;
|
||||
|
||||
public MountOptions(Dictionary<string, string> options)
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
|
||||
public bool IsReadOnly => _options.ContainsKey("ro");
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,19 @@ namespace NzbDrone.Common.EnvironmentInfo
|
||||
public static bool IsMono => Platform == PlatformType.Mono;
|
||||
public static bool IsDotNet => Platform == PlatformType.DotNet;
|
||||
|
||||
public static string PlatformName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsDotNet)
|
||||
{
|
||||
return ".NET";
|
||||
}
|
||||
|
||||
return "Mono";
|
||||
}
|
||||
}
|
||||
|
||||
public abstract Version Version { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ using System;
|
||||
|
||||
namespace NzbDrone.Common.Extensions
|
||||
{
|
||||
public static class Base64Extentions
|
||||
public static class Base64Extensions
|
||||
{
|
||||
public static string ToBase64(this byte[] bytes)
|
||||
{
|
||||
@@ -14,4 +14,4 @@ namespace NzbDrone.Common.Extensions
|
||||
return BitConverter.GetBytes(input).ToBase64();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ namespace NzbDrone.Common.Extensions
|
||||
|
||||
public static Dictionary<T1, T2> Merge<T1, T2>(this Dictionary<T1, T2> first, Dictionary<T1, T2> second)
|
||||
{
|
||||
if (first == null) throw new ArgumentNullException("first");
|
||||
if (second == null) throw new ArgumentNullException("second");
|
||||
if (first == null) throw new ArgumentNullException(nameof(first));
|
||||
if (second == null) throw new ArgumentNullException(nameof(second));
|
||||
|
||||
var merged = new Dictionary<T1, T2>();
|
||||
first.ToList().ForEach(kv => merged[kv.Key] = kv.Value);
|
||||
|
||||
55
src/NzbDrone.Common/Extensions/ExceptionExtensions.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Common.Extensions
|
||||
{
|
||||
public static class ExceptionExtensions
|
||||
{
|
||||
public static T WithData<T>(this T ex, string key, string value) where T : Exception
|
||||
{
|
||||
ex.AddData(key, value);
|
||||
|
||||
return ex;
|
||||
}
|
||||
public static T WithData<T>(this T ex, string key, int value) where T : Exception
|
||||
{
|
||||
ex.AddData(key, value.ToString());
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
public static T WithData<T>(this T ex, string key, Http.HttpUri value) where T : Exception
|
||||
{
|
||||
ex.AddData(key, value.ToString());
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
|
||||
public static T WithData<T>(this T ex, Http.HttpResponse response, int maxSampleLength = 512) where T : Exception
|
||||
{
|
||||
if (response == null || response.Content == null) return ex;
|
||||
|
||||
var contentSample = response.Content.Substring(0, Math.Min(response.Content.Length, 512));
|
||||
|
||||
if (response.Headers != null)
|
||||
{
|
||||
ex.AddData("ContentType", response.Headers.ContentType ?? string.Empty);
|
||||
}
|
||||
ex.AddData("ContentLength", response.Content.Length.ToString());
|
||||
ex.AddData("ContentSample", contentSample);
|
||||
|
||||
return ex;
|
||||
}
|
||||
|
||||
|
||||
private static void AddData(this Exception ex, string key, string value)
|
||||
{
|
||||
if (value.IsNullOrWhiteSpace()) return;
|
||||
|
||||
ex.Data[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,11 +80,11 @@ namespace NzbDrone.Common.Extensions
|
||||
|
||||
public static bool IsParentPath(this string parentPath, string childPath)
|
||||
{
|
||||
if (parentPath != "/")
|
||||
if (parentPath != "/" && !parentPath.EndsWith(":\\"))
|
||||
{
|
||||
parentPath = parentPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||
}
|
||||
if (childPath != "/")
|
||||
if (childPath != "/" && !parentPath.EndsWith(":\\"))
|
||||
{
|
||||
childPath = childPath.TrimEnd(Path.DirectorySeparatorChar);
|
||||
}
|
||||
@@ -276,4 +276,4 @@ namespace NzbDrone.Common.Extensions
|
||||
return Path.Combine(appFolderInfo.StartUpFolder, NLOG_CONFIG_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ using System.Xml.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Extensions
|
||||
{
|
||||
public static class XmlExtentions
|
||||
public static class XmlExtensions
|
||||
{
|
||||
public static IEnumerable<XElement> FindDecendants(this XContainer container, string localName)
|
||||
{
|
||||
return container.Descendants().Where(c => c.Name.LocalName.Equals(localName, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,13 @@ namespace NzbDrone.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
return string.Format("{0:x8}", mCrc);
|
||||
return $"{mCrc:x8}";
|
||||
}
|
||||
|
||||
public static string AnonymousToken()
|
||||
{
|
||||
var seed = $"{Environment.ProcessorCount}_{Environment.OSVersion.Platform}_{Environment.MachineName}_{Environment.UserName}";
|
||||
return HashUtil.CalculateCrc(seed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
@@ -169,7 +169,7 @@ namespace NzbDrone.Common.Http
|
||||
|
||||
public static List<KeyValuePair<string, string>> ParseCookies(string cookies)
|
||||
{
|
||||
return cookies.Split(';')
|
||||
return cookies.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(v => v.Trim().Split('='))
|
||||
.Select(v => new KeyValuePair<string, string>(v[0], v[1]))
|
||||
.ToList();
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
namespace NzbDrone.Common.Http
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
public enum HttpMethod
|
||||
{
|
||||
GET,
|
||||
PUT,
|
||||
POST,
|
||||
HEAD,
|
||||
PUT,
|
||||
DELETE,
|
||||
HEAD,
|
||||
OPTIONS,
|
||||
PATCH,
|
||||
OPTIONS
|
||||
MERGE
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace NzbDrone.Common.Http
|
||||
public class JsonRpcRequestBuilder : HttpRequestBuilder
|
||||
{
|
||||
public static HttpAccept JsonRpcHttpAccept = new HttpAccept("application/json-rpc, application/json");
|
||||
public static string JsonRpcContentType = "application/json-rpc";
|
||||
public static string JsonRpcContentType = "application/json";
|
||||
|
||||
public string JsonMethod { get; private set; }
|
||||
public List<object> JsonParameters { get; private set; }
|
||||
|
||||
47
src/NzbDrone.Common/Instrumentation/CleansingJsonVisitor.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NzbDrone.Common.Serializer;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation
|
||||
{
|
||||
public class CleansingJsonVisitor : JsonVisitor
|
||||
{
|
||||
public override void Visit(JArray json)
|
||||
{
|
||||
for (var i = 0; i < json.Count; i++)
|
||||
{
|
||||
if (json[i].Type == JTokenType.String)
|
||||
{
|
||||
var text = json[i].Value<string>();
|
||||
json[i] = new JValue(CleanseLogMessage.Cleanse(text));
|
||||
}
|
||||
}
|
||||
foreach (JToken token in json)
|
||||
{
|
||||
Visit(token);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Visit(JProperty property)
|
||||
{
|
||||
if (property.Value.Type == JTokenType.String)
|
||||
{
|
||||
property.Value = CleanseValue(property.Value as JValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
base.Visit(property);
|
||||
}
|
||||
}
|
||||
|
||||
private JValue CleanseValue(JValue value)
|
||||
{
|
||||
var text = value.Value<string>();
|
||||
var cleansed = CleanseLogMessage.Cleanse(text);
|
||||
return new JValue(cleansed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using SharpRaven.Data;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
@@ -7,7 +6,7 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
{
|
||||
public SentryUser Create()
|
||||
{
|
||||
return new SentryUser(Environment.MachineName);
|
||||
return new SentryUser(HashUtil.AnonymousToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
{
|
||||
public class SentryPacketCleanser
|
||||
{
|
||||
public void CleansePacket(SonarrSentryPacket packet)
|
||||
{
|
||||
packet.Message = CleanseLogMessage.Cleanse(packet.Message);
|
||||
|
||||
if (packet.Fingerprint != null)
|
||||
{
|
||||
for (var i = 0; i < packet.Fingerprint.Length; i++)
|
||||
{
|
||||
packet.Fingerprint[i] = CleanseLogMessage.Cleanse(packet.Fingerprint[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (packet.Extra != null)
|
||||
{
|
||||
var target = JObject.FromObject(packet.Extra);
|
||||
new CleansingJsonVisitor().Visit(target);
|
||||
packet.Extra = target;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,13 +37,13 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
{
|
||||
Compression = true,
|
||||
Environment = RuntimeInfo.IsProduction ? "production" : "development",
|
||||
Release = BuildInfo.Release
|
||||
Release = BuildInfo.Release,
|
||||
ErrorOnCapture = OnError
|
||||
};
|
||||
|
||||
_client.ErrorOnCapture = OnError;
|
||||
|
||||
_client.Tags.Add("osfamily", OsInfo.Os.ToString());
|
||||
_client.Tags.Add("runtime", PlatformInfo.Platform.ToString().ToLower());
|
||||
_client.Tags.Add("runtime", PlatformInfo.PlatformName);
|
||||
_client.Tags.Add("culture", Thread.CurrentThread.CurrentCulture.Name);
|
||||
_client.Tags.Add("branch", BuildInfo.Branch);
|
||||
_client.Tags.Add("version", BuildInfo.Version.ToString());
|
||||
@@ -114,7 +114,6 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
var extras = logEvent.Properties.ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());
|
||||
_client.Logger = logEvent.LoggerName;
|
||||
|
||||
|
||||
var sentryMessage = new SentryMessage(logEvent.Message, logEvent.Parameters);
|
||||
|
||||
var sentryEvent = new SentryEvent(logEvent.Exception)
|
||||
@@ -135,10 +134,14 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
sentryEvent.Fingerprint.Add(logEvent.Exception.GetType().FullName);
|
||||
}
|
||||
|
||||
var osName = Environment.GetEnvironmentVariable("OS_NAME");
|
||||
var osVersion = Environment.GetEnvironmentVariable("OS_VERSION");
|
||||
var runTimeVersion = Environment.GetEnvironmentVariable("RUNTIME_VERSION");
|
||||
|
||||
sentryEvent.Tags.Add("os_name", Environment.GetEnvironmentVariable("OS_NAME"));
|
||||
sentryEvent.Tags.Add("os_version", Environment.GetEnvironmentVariable("OS_VERSION"));
|
||||
sentryEvent.Tags.Add("runtime_version", Environment.GetEnvironmentVariable("RUNTIME_VERSION"));
|
||||
|
||||
sentryEvent.Tags.Add("os_name", osName);
|
||||
sentryEvent.Tags.Add("os_version", $"{osName} {osVersion}");
|
||||
sentryEvent.Tags.Add("runtime_version", $"{PlatformInfo.PlatformName} {runTimeVersion}");
|
||||
|
||||
_client.Capture(sentryEvent);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,13 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
{
|
||||
public class SonarrJsonPacketFactory : IJsonPacketFactory
|
||||
{
|
||||
private readonly SentryPacketCleanser _cleanser;
|
||||
|
||||
public SonarrJsonPacketFactory()
|
||||
{
|
||||
_cleanser = new SentryPacketCleanser();
|
||||
}
|
||||
|
||||
private static string ShortenPath(string path)
|
||||
{
|
||||
|
||||
@@ -37,6 +44,8 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
frame.Filename = ShortenPath(frame.Filename);
|
||||
}
|
||||
}
|
||||
|
||||
_cleanser.CleansePacket(packet);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@@ -46,7 +55,6 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
||||
[Obsolete]
|
||||
public JsonPacket Create(string project, SentryMessage message, ErrorLevel level = ErrorLevel.Info, IDictionary<string, string> tags = null,
|
||||
string[] fingerprint = null, object extra = null)
|
||||
@@ -61,4 +69,4 @@ namespace NzbDrone.Common.Instrumentation.Sentry
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,20 +44,16 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.3\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Org.Mentalis, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DotNet4.SocksProxy.1.3.2.0\lib\net40\Org.Mentalis.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="Org.Mentalis, Version=1.0.0.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DotNet4.SocksProxy.1.3.4.0\lib\net40\Org.Mentalis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpRaven, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpRaven.2.1.0\lib\net40\SharpRaven.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="SharpRaven, Version=2.2.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpRaven.2.2.0\lib\net40\SharpRaven.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SocksWebProxy, Version=1.3.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DotNet4.SocksProxy.1.3.2.0\lib\net40\SocksWebProxy.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<Reference Include="SocksWebProxy, Version=1.3.4.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\DotNet4.SocksProxy.1.3.4.0\lib\net40\SocksWebProxy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
@@ -89,6 +85,7 @@
|
||||
<Compile Include="Disk\FileSystemLookupService.cs" />
|
||||
<Compile Include="Disk\DriveInfoMount.cs" />
|
||||
<Compile Include="Disk\IMount.cs" />
|
||||
<Compile Include="Disk\MountOptions.cs" />
|
||||
<Compile Include="Disk\RelativeFileSystemModel.cs" />
|
||||
<Compile Include="Disk\FileSystemModel.cs" />
|
||||
<Compile Include="Disk\FileSystemResult.cs" />
|
||||
@@ -135,14 +132,15 @@
|
||||
<Compile Include="Expansive\Tree.cs" />
|
||||
<Compile Include="Expansive\TreeNode.cs" />
|
||||
<Compile Include="Expansive\TreeNodeList.cs" />
|
||||
<Compile Include="Extensions\Base64Extentions.cs" />
|
||||
<Compile Include="Extensions\Base64Extensions.cs" />
|
||||
<Compile Include="Extensions\DateTimeExtensions.cs" />
|
||||
<Compile Include="Crypto\HashConverter.cs" />
|
||||
<Compile Include="Extensions\ExceptionExtensions.cs" />
|
||||
<Compile Include="Extensions\Int64Extensions.cs" />
|
||||
<Compile Include="Extensions\ObjectExtensions.cs" />
|
||||
<Compile Include="Extensions\StreamExtensions.cs" />
|
||||
<Compile Include="Extensions\UrlExtensions.cs" />
|
||||
<Compile Include="Extensions\XmlExtentions.cs" />
|
||||
<Compile Include="Extensions\XmlExtensions.cs" />
|
||||
<Compile Include="HashUtil.cs" />
|
||||
<Compile Include="Http\Dispatchers\CurlHttpDispatcher.cs" />
|
||||
<Compile Include="Http\Dispatchers\FallbackHttpDispatcher.cs" />
|
||||
@@ -177,12 +175,14 @@
|
||||
<Compile Include="Extensions\IEnumerableExtensions.cs" />
|
||||
<Compile Include="Http\UserAgentBuilder.cs" />
|
||||
<Compile Include="Instrumentation\CleanseLogMessage.cs" />
|
||||
<Compile Include="Instrumentation\CleansingJsonVisitor.cs" />
|
||||
<Compile Include="Instrumentation\Extensions\LoggerProgressExtensions.cs" />
|
||||
<Compile Include="Instrumentation\GlobalExceptionHandlers.cs" />
|
||||
<Compile Include="Instrumentation\LogEventExtensions.cs" />
|
||||
<Compile Include="Instrumentation\NzbDroneFileTarget.cs" />
|
||||
<Compile Include="Instrumentation\NzbDroneLogger.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\SentryDebounce.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\SentryPacketCleanser.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\SentryTarget.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\MachineNameUserFactory.cs" />
|
||||
<Compile Include="Instrumentation\Sentry\SonarrJsonPacketFactory.cs" />
|
||||
@@ -207,6 +207,7 @@
|
||||
<Compile Include="Serializer\HttpUriConverter.cs" />
|
||||
<Compile Include="Serializer\IntConverter.cs" />
|
||||
<Compile Include="Serializer\Json.cs" />
|
||||
<Compile Include="Serializer\JsonVisitor.cs" />
|
||||
<Compile Include="ServiceFactory.cs" />
|
||||
<Compile Include="ServiceProvider.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Model;
|
||||
|
||||
namespace NzbDrone.Common.Processes
|
||||
@@ -129,7 +130,25 @@ namespace NzbDrone.Common.Processes
|
||||
{
|
||||
foreach (DictionaryEntry environmentVariable in environmentVariables)
|
||||
{
|
||||
startInfo.EnvironmentVariables.Add(environmentVariable.Key.ToString(), environmentVariable.Value.ToString());
|
||||
try
|
||||
{
|
||||
_logger.Trace("Setting environment variable '{0}' to '{1}'", environmentVariable.Key, environmentVariable.Value);
|
||||
startInfo.EnvironmentVariables.Add(environmentVariable.Key.ToString(), environmentVariable.Value.ToString());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (environmentVariable.Value == null)
|
||||
{
|
||||
_logger.Error(e, "Unable to set environment variable '{0}', value is null", environmentVariable.Key);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
_logger.Error(e, "Unable to set environment variable '{0}'", environmentVariable.Key);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,11 @@ namespace NzbDrone.Common.Reflection
|
||||
return (T)attribute;
|
||||
}
|
||||
|
||||
public static T[] GetAttributes<T>(this MemberInfo member) where T : Attribute
|
||||
{
|
||||
return member.GetCustomAttributes(typeof(T), false).OfType<T>().ToArray();
|
||||
}
|
||||
|
||||
public static Type FindTypeByName(this Assembly assembly, string name)
|
||||
{
|
||||
return assembly.GetTypes().SingleOrDefault(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
|
||||
@@ -70,4 +75,4 @@ namespace NzbDrone.Common.Reflection
|
||||
return type.GetCustomAttributes(typeof(TAttribute), true).Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
|
||||
namespace NzbDrone.Common.Security
|
||||
@@ -14,6 +15,12 @@ namespace NzbDrone.Common.Security
|
||||
|
||||
public static void Register()
|
||||
{
|
||||
if (OsInfo.IsNotWindows)
|
||||
{
|
||||
// This was never meant to be used on mono, and will cause issues with mono 5 and higher if btls is enabled.
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// TODO: In v3 we should drop support for SSL3 because its very insecure. Only leaving it enabled because some people might rely on it.
|
||||
|
||||
95
src/NzbDrone.Common/Serializer/JsonVisitor.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Serializer
|
||||
{
|
||||
|
||||
public class JsonVisitor
|
||||
{
|
||||
protected void Dispatch(JToken json)
|
||||
{
|
||||
switch (json.Type)
|
||||
{
|
||||
case JTokenType.Object:
|
||||
Visit(json as JObject);
|
||||
break;
|
||||
|
||||
case JTokenType.Array:
|
||||
Visit(json as JArray);
|
||||
break;
|
||||
|
||||
case JTokenType.Raw:
|
||||
Visit(json as JRaw);
|
||||
break;
|
||||
|
||||
case JTokenType.Constructor:
|
||||
Visit(json as JConstructor);
|
||||
break;
|
||||
|
||||
case JTokenType.Property:
|
||||
Visit(json as JProperty);
|
||||
break;
|
||||
|
||||
case JTokenType.Comment:
|
||||
case JTokenType.Integer:
|
||||
case JTokenType.Float:
|
||||
case JTokenType.String:
|
||||
case JTokenType.Boolean:
|
||||
case JTokenType.Null:
|
||||
case JTokenType.Undefined:
|
||||
case JTokenType.Date:
|
||||
case JTokenType.Bytes:
|
||||
case JTokenType.Guid:
|
||||
case JTokenType.Uri:
|
||||
case JTokenType.TimeSpan:
|
||||
Visit(json as JValue);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Visit(JToken json)
|
||||
{
|
||||
Dispatch(json);
|
||||
}
|
||||
|
||||
public virtual void Visit(JContainer json)
|
||||
{
|
||||
Dispatch(json);
|
||||
}
|
||||
|
||||
public virtual void Visit(JArray json)
|
||||
{
|
||||
foreach (JToken token in json)
|
||||
{
|
||||
Visit(token);
|
||||
}
|
||||
}
|
||||
public virtual void Visit(JConstructor json)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Visit(JObject json)
|
||||
{
|
||||
foreach (JProperty property in json.Properties())
|
||||
{
|
||||
Visit(property);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Visit(JProperty property)
|
||||
{
|
||||
Visit(property.Value);
|
||||
}
|
||||
|
||||
public virtual void Visit(JValue value)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace NzbDrone.Common.TPL
|
||||
/// <param name="maxDegreeOfParallelism">The maximum degree of parallelism provided by this scheduler.</param>
|
||||
public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism)
|
||||
{
|
||||
if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException("maxDegreeOfParallelism");
|
||||
if (maxDegreeOfParallelism < 1) throw new ArgumentOutOfRangeException(nameof(maxDegreeOfParallelism));
|
||||
_maxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="DotNet4.SocksProxy" version="1.3.2.0" targetFramework="net40" />
|
||||
<package id="DotNet4.SocksProxy" version="1.3.4.0" targetFramework="net40" />
|
||||
<package id="ICSharpCode.SharpZipLib.Patched" version="0.86.5" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.1" targetFramework="net40" />
|
||||
<package id="SharpRaven" version="2.1.0" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.3" targetFramework="net40" />
|
||||
<package id="SharpRaven" version="2.2.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -79,8 +79,7 @@
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.4.1\lib\net40\NLog.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\NLog.4.4.3\lib\net40\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
<package id="Microsoft.Owin" version="2.1.0" targetFramework="net40" />
|
||||
<package id="Microsoft.Owin.Hosting" version="2.1.0" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.1" targetFramework="net40" />
|
||||
<package id="NLog" version="4.4.3" targetFramework="net40" />
|
||||
<package id="Owin" version="1.0" targetFramework="net40" />
|
||||
</packages>
|
||||
@@ -20,11 +20,14 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
|
||||
private Mock<ISceneMappingProvider> _provider1;
|
||||
private Mock<ISceneMappingProvider> _provider2;
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_fakeMappings = Builder<SceneMapping>.CreateListOfSize(5).BuildListOfNew();
|
||||
_fakeMappings = Builder<SceneMapping>.CreateListOfSize(5)
|
||||
.All()
|
||||
.With(v => v.FilterRegex = null)
|
||||
.BuildListOfNew();
|
||||
|
||||
_fakeMappings[0].SearchTerm = "Words";
|
||||
_fakeMappings[1].SearchTerm = "That";
|
||||
@@ -193,7 +196,7 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
||||
|
||||
var tvdbId = Subject.FindTvdbId(parseTitle);
|
||||
var seasonNumber = Subject.GetSceneSeasonNumber(parseTitle);
|
||||
var seasonNumber = Subject.GetSceneSeasonNumber(parseTitle, null);
|
||||
|
||||
tvdbId.Should().Be(100);
|
||||
seasonNumber.Should().Be(expectedSeasonNumber);
|
||||
@@ -314,6 +317,49 @@ namespace NzbDrone.Core.Test.DataAugmentation.Scene
|
||||
Subject.GetSceneNames(100, new List<int> { 4 }, new List<int> { 4 }).Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_filter_by_regex()
|
||||
{
|
||||
var mappings = new List<SceneMapping>
|
||||
{
|
||||
new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 100 },
|
||||
new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 101, FilterRegex="-Viva$" }
|
||||
};
|
||||
|
||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
||||
|
||||
Subject.FindTvdbId("Amareto", "Amareto.S01E01.720p.WEB-DL-Viva").Should().Be(101);
|
||||
Subject.FindTvdbId("Amareto", "Amareto.S01E01.720p.WEB-DL-DMO").Should().Be(100);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_multiple_mappings()
|
||||
{
|
||||
var mappings = new List<SceneMapping>
|
||||
{
|
||||
new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 100 },
|
||||
new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 101 }
|
||||
};
|
||||
|
||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
||||
|
||||
Assert.Throws<InvalidSceneMappingException>(() => Subject.FindTvdbId("Amareto", "Amareto.S01E01.720p.WEB-DL-Viva"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_throw_if_multiple_mappings_with_same_tvdbid()
|
||||
{
|
||||
var mappings = new List<SceneMapping>
|
||||
{
|
||||
new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 100 },
|
||||
new SceneMapping { Title = "Amareto", ParseTerm = "amareto", SearchTerm = "Amareto", TvdbId = 100 }
|
||||
};
|
||||
|
||||
Mocker.GetMock<ISceneMappingRepository>().Setup(c => c.All()).Returns(mappings);
|
||||
|
||||
Subject.FindTvdbId("Amareto", "Amareto.S01E01.720p.WEB-DL-Viva").Should().Be(100);
|
||||
}
|
||||
|
||||
private void AssertNoUpdate()
|
||||
{
|
||||
_provider1.Verify(c => c.GetSceneMappings(), Times.Once());
|
||||
|
||||
@@ -5,6 +5,7 @@ using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.DataAugmentation.Xem;
|
||||
using NzbDrone.Core.DataAugmentation.Xem.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
@@ -98,7 +99,6 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_not_fetch_scenenumbering_if_not_listed()
|
||||
{
|
||||
@@ -308,5 +308,19 @@ namespace NzbDrone.Core.Test.DataAugmentation.SceneNumbering
|
||||
episode.SceneSeasonNumber.Should().NotHaveValue();
|
||||
episode.SceneEpisodeNumber.Should().NotHaveValue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_skip_mapping_when_scene_information_is_all_zero()
|
||||
{
|
||||
GivenTvdbMappings();
|
||||
|
||||
AddTvdbMapping(0, 0, 0, 8, 3, 1); // 3x01 -> 3x01
|
||||
AddTvdbMapping(0, 0, 0, 9, 3, 2); // 3x02 -> 3x02
|
||||
|
||||
Subject.Handle(new SeriesUpdatedEvent(_series));
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(v => v.UpdateEpisodes(It.Is<List<Episode>>(e => e.Any(c => c.SceneAbsoluteEpisodeNumber == 0 && c.SceneSeasonNumber == 0 && c.SceneEpisodeNumber == 0))), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class update_btn_url_migration_fixture : MigrationTest<update_btn_url>
|
||||
{
|
||||
[TestCase("http://api.btnapps.net")]
|
||||
[TestCase("https://api.btnapps.net")]
|
||||
[TestCase("http://api.btnapps.net/")]
|
||||
[TestCase("https://api.btnapps.net/")]
|
||||
public void should_replace_old_url(string oldUrl)
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Indexers").Row(new
|
||||
{
|
||||
Name = "btn_old_url",
|
||||
Implementation = "BroadcastheNet",
|
||||
Settings = new BroadcastheNetSettings106
|
||||
{
|
||||
BaseUrl = oldUrl
|
||||
}.ToJson(),
|
||||
ConfigContract = "BroadcastheNetSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query<IndexerDefinition90>("SELECT * FROM Indexers");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().Settings.ToObject<BroadcastheNetSettings106>().BaseUrl.Should().Contain("api.broadcasthe.net");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_replace_other_indexers()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Indexers").Row(new
|
||||
{
|
||||
Name = "not_btn",
|
||||
Implementation = "NotBroadcastheNet",
|
||||
Settings = new BroadcastheNetSettings106
|
||||
{
|
||||
BaseUrl = "http://api.btnapps.net",
|
||||
}.ToJson(),
|
||||
ConfigContract = "BroadcastheNetSettings"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query<IndexerDefinition90>("SELECT * FROM Indexers");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().Settings.ToObject<BroadcastheNetSettings106>().BaseUrl.Should().Be("http://api.btnapps.net");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class fix_extra_file_extensionsFixture : MigrationTest<fix_extra_file_extension>
|
||||
{
|
||||
[Test]
|
||||
public void should_extra_files_that_do_not_have_an_extension()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("ExtraFiles").Row(new
|
||||
{
|
||||
SeriesId = 1,
|
||||
SeasonNumber = 1,
|
||||
EpisodeFileId = 1,
|
||||
RelativePath = "Series.Title.S01E01",
|
||||
Added = "2016-05-30 20:23:02.3725923",
|
||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
||||
Extension = ""
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query("Select * from ExtraFiles");
|
||||
|
||||
items.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fix_double_extension()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("SubtitleFiles").Row(new
|
||||
{
|
||||
SeriesId = 1,
|
||||
SeasonNumber = 1,
|
||||
EpisodeFileId = 1,
|
||||
RelativePath = "Series.Title.S01E01.en.srt",
|
||||
Added = "2016-05-30 20:23:02.3725923",
|
||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
||||
Language = Language.English,
|
||||
Extension = "en.srt"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query("Select * from SubtitleFiles");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First()["Extension"].Should().Be(".srt");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fix_extension_missing_a_leading_period()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("ExtraFiles").Row(new
|
||||
{
|
||||
SeriesId = 1,
|
||||
SeasonNumber = 1,
|
||||
EpisodeFileId = 1,
|
||||
RelativePath = "Series.Title.S01E01.nfo-orig",
|
||||
Added = "2016-05-30 20:23:02.3725923",
|
||||
LastUpdated = "2016-05-30 20:23:02.3725923",
|
||||
Extension = "nfo-orig"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.Query("Select * from ExtraFiles");
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First()["Extension"].Should().Be(".nfo-orig");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class import_extra_files_configFixture : MigrationTest<import_extra_files>
|
||||
{
|
||||
[Test]
|
||||
public void should_not_insert_if_missing()
|
||||
{
|
||||
var db = WithMigrationTestDb();
|
||||
|
||||
var items = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
items.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_insert_if_empty()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "extrafileextensions",
|
||||
Value = ""
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
items.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_insert_True_if_configured()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "extrafileextensions",
|
||||
Value = "srt"
|
||||
});
|
||||
});
|
||||
|
||||
var items = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
items.Should().Be("True");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore.Migration;
|
||||
using NzbDrone.Core.Parser;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Datastore.Migration
|
||||
{
|
||||
[TestFixture]
|
||||
public class fix_extra_files_configFixture : MigrationTest<fix_extra_files_config>
|
||||
{
|
||||
[Test]
|
||||
public void should_not_update_importextrafiles_disabled()
|
||||
{
|
||||
var db = WithMigrationTestDb();
|
||||
|
||||
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
itemEnabled.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fix_importextrafiles_if_wrong()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "importextrafiles",
|
||||
Value = 1
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
itemEnabled.Should().Be("True");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_fill_in_default_extensions()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "importextrafiles",
|
||||
Value = "False"
|
||||
});
|
||||
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "extrafileextensions",
|
||||
Value = ""
|
||||
});
|
||||
});
|
||||
|
||||
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
itemEnabled.Should().Be("False");
|
||||
|
||||
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||
itemExtensions.Should().Be("srt");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_fill_in_default_extensions()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "importextrafiles",
|
||||
Value = "True"
|
||||
});
|
||||
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "extrafileextensions",
|
||||
Value = ""
|
||||
});
|
||||
});
|
||||
|
||||
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
itemEnabled.Should().Be("True");
|
||||
|
||||
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||
itemExtensions.Should().Be("");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_fill_in_default_extensions_if_not_defined()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "importextrafiles",
|
||||
Value = "False"
|
||||
});
|
||||
});
|
||||
|
||||
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
itemEnabled.Should().Be("False");
|
||||
|
||||
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||
itemExtensions.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_fill_in_default_extensions_if_already_defined()
|
||||
{
|
||||
var db = WithMigrationTestDb(c =>
|
||||
{
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "importextrafiles",
|
||||
Value = "False"
|
||||
});
|
||||
|
||||
c.Insert.IntoTable("Config").Row(new
|
||||
{
|
||||
Key = "extrafileextensions",
|
||||
Value = "sub"
|
||||
});
|
||||
});
|
||||
|
||||
var itemEnabled = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'importextrafiles'");
|
||||
itemEnabled.Should().Be("False");
|
||||
|
||||
var itemExtensions = db.QueryScalar<string>("SELECT Value FROM Config WHERE Key = 'extrafileextensions'");
|
||||
itemExtensions.Should().Be("sub");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class BlockedIndexerSpecificationFixture : CoreTest<BlockedIndexerSpecification>
|
||||
{
|
||||
private RemoteEpisode _remoteEpisode;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_remoteEpisode = new RemoteEpisode
|
||||
{
|
||||
Release = new ReleaseInfo { IndexerId = 1 }
|
||||
};
|
||||
|
||||
Mocker.GetMock<IIndexerStatusService>()
|
||||
.Setup(v => v.GetBlockedProviders())
|
||||
.Returns(new List<IndexerStatus>());
|
||||
}
|
||||
|
||||
private void WithBlockedIndexer()
|
||||
{
|
||||
Mocker.GetMock<IIndexerStatusService>()
|
||||
.Setup(v => v.GetBlockedProviders())
|
||||
.Returns(new List<IndexerStatus> { new IndexerStatus { ProviderId = 1, DisabledTill = DateTime.UtcNow } });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_no_blocked_indexer()
|
||||
{
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_blocked_indexer()
|
||||
{
|
||||
WithBlockedIndexer();
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
||||
Subject.Type.Should().Be(RejectionType.Temporary);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
private Mock<IDecisionEngineSpecification> _fail2;
|
||||
private Mock<IDecisionEngineSpecification> _fail3;
|
||||
|
||||
private Mock<IDecisionEngineSpecification> _failDelayed1;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
@@ -39,14 +41,19 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
_fail2 = new Mock<IDecisionEngineSpecification>();
|
||||
_fail3 = new Mock<IDecisionEngineSpecification>();
|
||||
|
||||
_failDelayed1 = new Mock<IDecisionEngineSpecification>();
|
||||
|
||||
_pass1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(Decision.Accept);
|
||||
_pass2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(Decision.Accept);
|
||||
_pass3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(Decision.Accept);
|
||||
|
||||
|
||||
_fail1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(Decision.Reject("fail1"));
|
||||
_fail2.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(Decision.Reject("fail2"));
|
||||
_fail3.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(Decision.Reject("fail3"));
|
||||
|
||||
_failDelayed1.Setup(c => c.IsSatisfiedBy(It.IsAny<RemoteEpisode>(), null)).Returns(Decision.Reject("failDelayed1"));
|
||||
_failDelayed1.SetupGet(c => c.Priority).Returns(SpecificationPriority.Disk);
|
||||
|
||||
_reports = new List<ReleaseInfo> { new ReleaseInfo { Title = "The.Office.S03E115.DVDRip.XviD-OSiTV" } };
|
||||
_remoteEpisode = new RemoteEpisode {
|
||||
Series = new Series(),
|
||||
@@ -78,6 +85,25 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
_pass3.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_delayed_specifications_if_non_delayed_passed()
|
||||
{
|
||||
GivenSpecifications(_pass1, _failDelayed1);
|
||||
|
||||
Subject.GetRssDecision(_reports).ToList();
|
||||
_failDelayed1.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_call_delayed_specifications_if_non_delayed_failed()
|
||||
{
|
||||
GivenSpecifications(_fail1, _failDelayed1);
|
||||
|
||||
Subject.GetRssDecision(_reports).ToList();
|
||||
|
||||
_failDelayed1.Verify(c => c.IsSatisfiedBy(_remoteEpisode, null), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_rejected_if_single_specs_fail()
|
||||
{
|
||||
@@ -214,10 +240,10 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
|
||||
var criteria = new SeasonSearchCriteria { Episodes = episodes.Take(1).ToList(), SeasonNumber = 1 };
|
||||
|
||||
var reports = episodes.Select(v =>
|
||||
new ReleaseInfo()
|
||||
{
|
||||
Title = string.Format("{0}.S{1:00}E{2:00}.720p.WEB-DL-DRONE", series.Title, v.SceneSeasonNumber, v.SceneEpisodeNumber)
|
||||
var reports = episodes.Select(v =>
|
||||
new ReleaseInfo()
|
||||
{
|
||||
Title = string.Format("{0}.S{1:00}E{2:00}.720p.WEB-DL-DRONE", series.Title, v.SceneSeasonNumber, v.SceneEpisodeNumber)
|
||||
}).ToList();
|
||||
|
||||
Mocker.GetMock<IParsingService>()
|
||||
@@ -289,4 +315,4 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,5 +137,17 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
WithFirstEpisodeUnmonitored();
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultSingle, new SingleEpisodeSearchCriteria{ MonitoredEpisodesOnly = true}).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_all_episodes_are_not_monitored_for_season_pack_release()
|
||||
{
|
||||
WithSecondEpisodeUnmonitored();
|
||||
_parseResultMulti.ParsedEpisodeInfo = new ParsedEpisodeInfo
|
||||
{
|
||||
FullSeason = true
|
||||
};
|
||||
|
||||
_monitoredEpisodeSpecification.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,6 +217,37 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
qualifiedReports.First().RemoteEpisode.ParsedEpisodeInfo.FullSeason.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_multiepisode_over_single_episode_for_anime()
|
||||
{
|
||||
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1), GivenEpisode(2) }, new QualityModel(Quality.HDTV720p));
|
||||
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
||||
|
||||
remoteEpisode1.Series.SeriesType = SeriesTypes.Anime;
|
||||
remoteEpisode2.Series.SeriesType = SeriesTypes.Anime;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisode1));
|
||||
decisions.Add(new DownloadDecision(remoteEpisode2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteEpisode.Episodes.Count.Should().Be(remoteEpisode1.Episodes.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_single_episode_over_multi_episode_for_non_anime()
|
||||
{
|
||||
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1), GivenEpisode(2) }, new QualityModel(Quality.HDTV720p));
|
||||
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.HDTV720p));
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisode1));
|
||||
decisions.Add(new DownloadDecision(remoteEpisode2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteEpisode.Episodes.Count.Should().Be(remoteEpisode2.Episodes.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_releases_with_more_seeders()
|
||||
{
|
||||
@@ -348,5 +379,34 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
qualifiedReports.First().RemoteEpisode.Release.Should().Be(remoteEpisode1.Release);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_quality_over_the_number_of_peers()
|
||||
{
|
||||
var remoteEpisode1 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.Bluray1080p));
|
||||
var remoteEpisode2 = GivenRemoteEpisode(new List<Episode> { GivenEpisode(1) }, new QualityModel(Quality.SDTV));
|
||||
|
||||
var torrentInfo1 = new TorrentInfo();
|
||||
torrentInfo1.PublishDate = DateTime.Now;
|
||||
torrentInfo1.DownloadProtocol = DownloadProtocol.Torrent;
|
||||
torrentInfo1.Seeders = 100;
|
||||
torrentInfo1.Peers = 10;
|
||||
torrentInfo1.Size = 200.Megabytes();
|
||||
|
||||
var torrentInfo2 = torrentInfo1.JsonClone();
|
||||
torrentInfo2.Seeders = 1100;
|
||||
torrentInfo2.Peers = 10;
|
||||
torrentInfo1.Size = 250.Megabytes();
|
||||
|
||||
remoteEpisode1.Release = torrentInfo1;
|
||||
remoteEpisode2.Release = torrentInfo2;
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisode1));
|
||||
decisions.Add(new DownloadDecision(remoteEpisode2));
|
||||
|
||||
var qualifiedReports = Subject.PrioritizeDecisions(decisions);
|
||||
((TorrentInfo)qualifiedReports.First().RemoteEpisode.Release).Should().Be(torrentInfo1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
};
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("AllowedTestCases")]
|
||||
[Test, TestCaseSource(nameof(AllowedTestCases))]
|
||||
public void should_allow_if_quality_is_defined_in_profile(Quality qualityType)
|
||||
{
|
||||
remoteEpisode.ParsedEpisodeInfo.Quality.Quality = qualityType;
|
||||
@@ -54,7 +54,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
Subject.IsSatisfiedBy(remoteEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("DeniedTestCases")]
|
||||
[Test, TestCaseSource(nameof(DeniedTestCases))]
|
||||
public void should_not_allow_if_quality_is_not_defined_in_profile(Quality qualityType)
|
||||
{
|
||||
remoteEpisode.ParsedEpisodeInfo.Quality.Quality = qualityType;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
|
||||
.Returns(autoDownloadPropers);
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("IsUpgradeTestCases")]
|
||||
[Test, TestCaseSource(nameof(IsUpgradeTestCases))]
|
||||
public void IsUpgradeTest(Quality current, int currentVersion, Quality newQuality, int newVersion, Quality cutoff, bool expected)
|
||||
{
|
||||
GivenAutoDownloadPropers(true);
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.RssSync;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using Moq;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.IO;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests.RssSync
|
||||
{
|
||||
[TestFixture]
|
||||
public class DeletedEpisodeFileSpecificationFixture : CoreTest<DeletedEpisodeFileSpecification>
|
||||
{
|
||||
private RemoteEpisode _parseResultMulti;
|
||||
private RemoteEpisode _parseResultSingle;
|
||||
private EpisodeFile _firstFile;
|
||||
private EpisodeFile _secondFile;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_firstFile = new EpisodeFile
|
||||
{
|
||||
Id = 1,
|
||||
RelativePath = "My.Series.S01E01.mkv",
|
||||
Quality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1)),
|
||||
DateAdded = DateTime.Now
|
||||
};
|
||||
_secondFile = new EpisodeFile
|
||||
{
|
||||
Id = 2,
|
||||
RelativePath = "My.Series.S01E02.mkv",
|
||||
Quality = new QualityModel(Quality.Bluray1080p, new Revision(version: 1)),
|
||||
DateAdded = DateTime.Now
|
||||
};
|
||||
|
||||
var singleEpisodeList = new List<Episode> { new Episode { EpisodeFile = _firstFile, EpisodeFileId = 1 } };
|
||||
var doubleEpisodeList = new List<Episode> {
|
||||
new Episode { EpisodeFile = _firstFile, EpisodeFileId = 1 },
|
||||
new Episode { EpisodeFile = _secondFile, EpisodeFileId = 2 }
|
||||
};
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateNew()
|
||||
.With(c => c.Profile = new Profile { Cutoff = Quality.Bluray1080p })
|
||||
.With(c => c.Path = @"C:\Series\My.Series".AsOsAgnostic())
|
||||
.Build();
|
||||
|
||||
_parseResultMulti = new RemoteEpisode
|
||||
{
|
||||
Series = fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, new Revision(version: 2)) },
|
||||
Episodes = doubleEpisodeList
|
||||
};
|
||||
|
||||
_parseResultSingle = new RemoteEpisode
|
||||
{
|
||||
Series = fakeSeries,
|
||||
ParsedEpisodeInfo = new ParsedEpisodeInfo { Quality = new QualityModel(Quality.DVD, new Revision(version: 2)) },
|
||||
Episodes = singleEpisodeList
|
||||
};
|
||||
|
||||
GivenUnmonitorDeletedEpisodes(true);
|
||||
}
|
||||
|
||||
private void GivenUnmonitorDeletedEpisodes(bool enabled)
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(v => v.AutoUnmonitorPreviouslyDownloadedEpisodes)
|
||||
.Returns(enabled);
|
||||
}
|
||||
|
||||
private void WithExistingFile(EpisodeFile episodeFile)
|
||||
{
|
||||
var path = Path.Combine(@"C:\Series\My.Series".AsOsAgnostic(), episodeFile.RelativePath);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.FileExists(path))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_unmonitor_deleted_episdes_is_off()
|
||||
{
|
||||
GivenUnmonitorDeletedEpisodes(false);
|
||||
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_when_searching()
|
||||
{
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, new SeasonSearchCriteria()).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_file_exists()
|
||||
{
|
||||
WithExistingFile(_firstFile);
|
||||
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_file_is_missing()
|
||||
{
|
||||
Subject.IsSatisfiedBy(_parseResultSingle, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_both_of_multiple_episode_exist()
|
||||
{
|
||||
WithExistingFile(_firstFile);
|
||||
WithExistingFile(_secondFile);
|
||||
|
||||
Subject.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_one_of_multiple_episode_is_missing()
|
||||
{
|
||||
WithExistingFile(_firstFile);
|
||||
|
||||
Subject.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.DecisionEngine.Specifications.Search;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Indexers.TorrentRss;
|
||||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.DecisionEngineTests.Search
|
||||
{
|
||||
[TestFixture]
|
||||
public class TorrentSeedingSpecificationFixture : TestBase<TorrentSeedingSpecification>
|
||||
{
|
||||
private Series _series;
|
||||
private RemoteEpisode _remoteEpisode;
|
||||
private IndexerDefinition _indexerDefinition;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew().With(s => s.Id = 1).Build();
|
||||
|
||||
_remoteEpisode = new RemoteEpisode
|
||||
{
|
||||
Series = _series,
|
||||
Release = new TorrentInfo
|
||||
{
|
||||
IndexerId = 1,
|
||||
Title = "Series.Title.S01.720p.BluRay.X264-RlsGrp",
|
||||
Seeders = 0
|
||||
}
|
||||
};
|
||||
|
||||
_indexerDefinition = new IndexerDefinition
|
||||
{
|
||||
Settings = new TorrentRssIndexerSettings { MinimumSeeders = 5 }
|
||||
};
|
||||
|
||||
Mocker.GetMock<IIndexerFactory>()
|
||||
.Setup(v => v.Get(1))
|
||||
.Returns(_indexerDefinition);
|
||||
|
||||
}
|
||||
|
||||
private void GivenReleaseSeeders(int? seeders)
|
||||
{
|
||||
(_remoteEpisode.Release as TorrentInfo).Seeders = seeders;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_not_torrent()
|
||||
{
|
||||
_remoteEpisode.Release = new ReleaseInfo
|
||||
{
|
||||
IndexerId = 1,
|
||||
Title = "Series.Title.S01.720p.BluRay.X264-RlsGrp"
|
||||
};
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_indexer_not_specified()
|
||||
{
|
||||
_remoteEpisode.Release.IndexerId = 0;
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_indexer_no_longer_exists()
|
||||
{
|
||||
Mocker.GetMock<IIndexerFactory>()
|
||||
.Setup(v => v.Get(It.IsAny<int>()))
|
||||
.Callback<int>(i => { throw new ModelNotFoundException(typeof(IndexerDefinition), i); });
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_seeds_unknown()
|
||||
{
|
||||
GivenReleaseSeeders(null);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[TestCase(5)]
|
||||
[TestCase(6)]
|
||||
public void should_return_true_if_seeds_above_or_equal_to_limit(int seeders)
|
||||
{
|
||||
GivenReleaseSeeders(seeders);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[TestCase(0)]
|
||||
[TestCase(4)]
|
||||
public void should_return_false_if_seeds_belove_limit(int seeders)
|
||||
{
|
||||
GivenReleaseSeeders(seeders);
|
||||
|
||||
Subject.IsSatisfiedBy(_remoteEpisode, null).Accepted.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
134
src/NzbDrone.Core.Test/DiskSpace/DiskSpaceServiceFixture.cs
Normal file
@@ -0,0 +1,134 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Configuration;
|
||||
using NzbDrone.Core.DiskSpace;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.DiskSpace
|
||||
{
|
||||
[TestFixture]
|
||||
public class DiskSpaceServiceFixture : CoreTest<DiskSpaceService>
|
||||
{
|
||||
private string _seriesFolder;
|
||||
private string _seriesFolder2;
|
||||
private string _droneFactoryFolder;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_seriesFolder = @"G:\fasdlfsdf\series".AsOsAgnostic();
|
||||
_seriesFolder2 = @"G:\fasdlfsdf\series2".AsOsAgnostic();
|
||||
_droneFactoryFolder = @"G:\dronefactory".AsOsAgnostic();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetMounts())
|
||||
.Returns(new List<IMount>());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetPathRoot(It.IsAny<string>()))
|
||||
.Returns(@"G:\".AsOsAgnostic());
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetAvailableSpace(It.IsAny<string>()))
|
||||
.Returns(0);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.GetTotalSize(It.IsAny<string>()))
|
||||
.Returns(0);
|
||||
|
||||
GivenSeries();
|
||||
}
|
||||
|
||||
private void GivenSeries(params Series[] series)
|
||||
{
|
||||
Mocker.GetMock<ISeriesService>()
|
||||
.Setup(v => v.GetAllSeries())
|
||||
.Returns(series.ToList());
|
||||
}
|
||||
|
||||
private void GivenExistingFolder(string folder)
|
||||
{
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Setup(v => v.FolderExists(folder))
|
||||
.Returns(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_check_diskspace_for_series_folders()
|
||||
{
|
||||
GivenSeries(new Series { Path = _seriesFolder });
|
||||
|
||||
GivenExistingFolder(_seriesFolder);
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
freeSpace.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_check_diskspace_for_same_root_folder_only_once()
|
||||
{
|
||||
GivenSeries(new Series { Path = _seriesFolder }, new Series { Path = _seriesFolder2 });
|
||||
|
||||
GivenExistingFolder(_seriesFolder);
|
||||
GivenExistingFolder(_seriesFolder2);
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
freeSpace.Should().HaveCount(1);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetAvailableSpace(It.IsAny<string>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_check_diskspace_for_missing_series_folders()
|
||||
{
|
||||
GivenSeries(new Series { Path = _seriesFolder });
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
freeSpace.Should().BeEmpty();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetAvailableSpace(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_check_diskspace_for_dronefactory_folder()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(v => v.DownloadedEpisodesFolder)
|
||||
.Returns(_droneFactoryFolder);
|
||||
|
||||
GivenExistingFolder(_droneFactoryFolder);
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
freeSpace.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_check_diskspace_for_missing_dronefactory_folder()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>()
|
||||
.SetupGet(v => v.DownloadedEpisodesFolder)
|
||||
.Returns(_droneFactoryFolder);
|
||||
|
||||
var freeSpace = Subject.GetFreeSpace();
|
||||
|
||||
freeSpace.Should().BeEmpty();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>()
|
||||
.Verify(v => v.GetAvailableSpace(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,9 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.DecisionEngine;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.Download.Pending;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Core.Profiles;
|
||||
using NzbDrone.Core.Qualities;
|
||||
@@ -35,7 +37,7 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
|
||||
.Build();
|
||||
}
|
||||
|
||||
private RemoteEpisode GetRemoteEpisode(List<Episode> episodes, QualityModel quality)
|
||||
private RemoteEpisode GetRemoteEpisode(List<Episode> episodes, QualityModel quality, DownloadProtocol downloadProtocol = DownloadProtocol.Usenet)
|
||||
{
|
||||
var remoteEpisode = new RemoteEpisode();
|
||||
remoteEpisode.ParsedEpisodeInfo = new ParsedEpisodeInfo();
|
||||
@@ -45,6 +47,7 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
|
||||
remoteEpisode.Episodes.AddRange(episodes);
|
||||
|
||||
remoteEpisode.Release = new ReleaseInfo();
|
||||
remoteEpisode.Release.DownloadProtocol = downloadProtocol;
|
||||
remoteEpisode.Release.PublishDate = DateTime.UtcNow;
|
||||
|
||||
remoteEpisode.Series = Builder<Series>.CreateNew()
|
||||
@@ -192,7 +195,6 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
|
||||
decisions.Add(new DownloadDecision(remoteEpisode));
|
||||
|
||||
Subject.ProcessDecisions(decisions);
|
||||
Mocker.GetMock<IDownloadService>().Verify(v => v.DownloadReport(It.IsAny<RemoteEpisode>()), Times.Never());
|
||||
@@ -209,7 +211,7 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
|
||||
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
|
||||
|
||||
Subject.ProcessDecisions(decisions);
|
||||
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.Add(It.IsAny<DownloadDecision>()), Times.Never());
|
||||
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.Add(It.IsAny<DownloadDecision>(), It.IsAny<PendingReleaseReason>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -223,7 +225,43 @@ namespace NzbDrone.Core.Test.Download.DownloadApprovedReportsTests
|
||||
decisions.Add(new DownloadDecision(remoteEpisode, new Rejection("Failure!", RejectionType.Temporary)));
|
||||
|
||||
Subject.ProcessDecisions(decisions);
|
||||
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.Add(It.IsAny<DownloadDecision>()), Times.Exactly(2));
|
||||
Mocker.GetMock<IPendingReleaseService>().Verify(v => v.Add(It.IsAny<DownloadDecision>(), It.IsAny<PendingReleaseReason>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_add_to_failed_if_already_failed_for_that_protocol()
|
||||
{
|
||||
var episodes = new List<Episode> { GetEpisode(1) };
|
||||
var remoteEpisode = GetRemoteEpisode(episodes, new QualityModel(Quality.HDTV720p));
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisode));
|
||||
decisions.Add(new DownloadDecision(remoteEpisode));
|
||||
|
||||
Mocker.GetMock<IDownloadService>().Setup(s => s.DownloadReport(It.IsAny<RemoteEpisode>()))
|
||||
.Throws(new DownloadClientUnavailableException("Download client failed"));
|
||||
|
||||
Subject.ProcessDecisions(decisions);
|
||||
Mocker.GetMock<IDownloadService>().Verify(v => v.DownloadReport(It.IsAny<RemoteEpisode>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_add_to_failed_if_failed_for_a_different_protocol()
|
||||
{
|
||||
var episodes = new List<Episode> { GetEpisode(1) };
|
||||
var remoteEpisode = GetRemoteEpisode(episodes, new QualityModel(Quality.HDTV720p), DownloadProtocol.Usenet);
|
||||
var remoteEpisode2 = GetRemoteEpisode(episodes, new QualityModel(Quality.HDTV720p), DownloadProtocol.Torrent);
|
||||
|
||||
var decisions = new List<DownloadDecision>();
|
||||
decisions.Add(new DownloadDecision(remoteEpisode));
|
||||
decisions.Add(new DownloadDecision(remoteEpisode2));
|
||||
|
||||
Mocker.GetMock<IDownloadService>().Setup(s => s.DownloadReport(It.Is<RemoteEpisode>(r => r.Release.DownloadProtocol == DownloadProtocol.Usenet)))
|
||||
.Throws(new DownloadClientUnavailableException("Download client failed"));
|
||||
|
||||
Subject.ProcessDecisions(decisions);
|
||||
Mocker.GetMock<IDownloadService>().Verify(v => v.DownloadReport(It.Is<RemoteEpisode>(r => r.Release.DownloadProtocol == DownloadProtocol.Usenet)), Times.Once());
|
||||
Mocker.GetMock<IDownloadService>().Verify(v => v.DownloadReport(It.Is<RemoteEpisode>(r => r.Release.DownloadProtocol == DownloadProtocol.Torrent)), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download
|
||||
{
|
||||
public class DownloadClientStatusServiceFixture : CoreTest<DownloadClientStatusService>
|
||||
{
|
||||
private DateTime _epoch;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_epoch = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
private DownloadClientStatus WithStatus(DownloadClientStatus status)
|
||||
{
|
||||
Mocker.GetMock<IDownloadClientStatusRepository>()
|
||||
.Setup(v => v.FindByProviderId(1))
|
||||
.Returns(status);
|
||||
|
||||
Mocker.GetMock<IDownloadClientStatusRepository>()
|
||||
.Setup(v => v.All())
|
||||
.Returns(new[] { status });
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
private void VerifyUpdate()
|
||||
{
|
||||
Mocker.GetMock<IDownloadClientStatusRepository>()
|
||||
.Verify(v => v.Upsert(It.IsAny<DownloadClientStatus>()), Times.Once());
|
||||
}
|
||||
|
||||
private void VerifyNoUpdate()
|
||||
{
|
||||
Mocker.GetMock<IDownloadClientStatusRepository>()
|
||||
.Verify(v => v.Upsert(It.IsAny<DownloadClientStatus>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_consider_blocked_within_5_minutes_since_initial_failure()
|
||||
{
|
||||
WithStatus(new DownloadClientStatus
|
||||
{
|
||||
InitialFailure = _epoch - TimeSpan.FromMinutes(4),
|
||||
MostRecentFailure = _epoch - TimeSpan.FromSeconds(4),
|
||||
EscalationLevel = 3
|
||||
});
|
||||
|
||||
Subject.RecordFailure(1);
|
||||
|
||||
VerifyUpdate();
|
||||
|
||||
var status = Subject.GetBlockedProviders().FirstOrDefault();
|
||||
status.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_consider_blocked_after_5_minutes_since_initial_failure()
|
||||
{
|
||||
WithStatus(new DownloadClientStatus
|
||||
{
|
||||
InitialFailure = _epoch - TimeSpan.FromMinutes(6),
|
||||
MostRecentFailure = _epoch - TimeSpan.FromSeconds(120),
|
||||
EscalationLevel = 3
|
||||
});
|
||||
|
||||
Subject.RecordFailure(1);
|
||||
|
||||
VerifyUpdate();
|
||||
|
||||
var status = Subject.GetBlockedProviders().FirstOrDefault();
|
||||
status.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_escalate_further_till_after_5_minutes_since_initial_failure()
|
||||
{
|
||||
var origStatus = WithStatus(new DownloadClientStatus
|
||||
{
|
||||
InitialFailure = _epoch - TimeSpan.FromMinutes(4),
|
||||
MostRecentFailure = _epoch - TimeSpan.FromSeconds(4),
|
||||
EscalationLevel = 3
|
||||
});
|
||||
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
|
||||
var status = Subject.GetBlockedProviders().FirstOrDefault();
|
||||
status.Should().BeNull();
|
||||
|
||||
origStatus.EscalationLevel.Should().Be(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_escalate_further_after_5_minutes_since_initial_failure()
|
||||
{
|
||||
WithStatus(new DownloadClientStatus
|
||||
{
|
||||
InitialFailure = _epoch - TimeSpan.FromMinutes(6),
|
||||
MostRecentFailure = _epoch - TimeSpan.FromSeconds(120),
|
||||
EscalationLevel = 3
|
||||
});
|
||||
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
|
||||
var status = Subject.GetBlockedProviders().FirstOrDefault();
|
||||
status.Should().NotBeNull();
|
||||
|
||||
status.EscalationLevel.Should().BeGreaterThan(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_escalate_beyond_3_hours()
|
||||
{
|
||||
WithStatus(new DownloadClientStatus
|
||||
{
|
||||
InitialFailure = _epoch - TimeSpan.FromMinutes(6),
|
||||
MostRecentFailure = _epoch - TimeSpan.FromSeconds(120),
|
||||
EscalationLevel = 3
|
||||
});
|
||||
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
Subject.RecordFailure(1);
|
||||
|
||||
var status = Subject.GetBlockedProviders().FirstOrDefault();
|
||||
status.Should().NotBeNull();
|
||||
status.DisabledTill.Should().HaveValue();
|
||||
status.DisabledTill.Should().NotBeAfter(_epoch + TimeSpan.FromHours(3.1));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyCompleted(result);
|
||||
|
||||
result.CanBeRemoved.Should().BeFalse();
|
||||
result.CanMoveFiles.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -77,6 +77,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole
|
||||
var result = Subject.GetItems().Single();
|
||||
|
||||
VerifyCompleted(result);
|
||||
|
||||
result.CanBeRemoved.Should().BeTrue();
|
||||
result.CanMoveFiles.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
protected DelugeTorrent _downloading;
|
||||
protected DelugeTorrent _failed;
|
||||
protected DelugeTorrent _completed;
|
||||
protected DelugeTorrent _seeding;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
@@ -75,7 +76,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
Size = 1000,
|
||||
BytesDownloaded = 1000,
|
||||
Progress = 100.0,
|
||||
DownloadPath = "somepath"
|
||||
DownloadPath = "somepath",
|
||||
IsAutoManaged = true,
|
||||
StopAtRatio = true,
|
||||
StopRatio = 1.0,
|
||||
Ratio = 1.5
|
||||
};
|
||||
|
||||
Mocker.GetMock<ITorrentFileInfoReader>()
|
||||
@@ -114,7 +119,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
.Returns("CBC2F069FE8BB2F544EAE707D75BCD3DE9DCF951".ToLower())
|
||||
.Callback(PrepareClientToReturnQueuedItem);
|
||||
}
|
||||
|
||||
|
||||
protected virtual void GivenTorrents(List<DelugeTorrent> torrents)
|
||||
{
|
||||
if (torrents == null)
|
||||
@@ -129,7 +134,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
|
||||
protected void PrepareClientToReturnQueuedItem()
|
||||
{
|
||||
GivenTorrents(new List<DelugeTorrent>
|
||||
GivenTorrents(new List<DelugeTorrent>
|
||||
{
|
||||
_queued
|
||||
});
|
||||
@@ -137,7 +142,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
|
||||
protected void PrepareClientToReturnDownloadingItem()
|
||||
{
|
||||
GivenTorrents(new List<DelugeTorrent>
|
||||
GivenTorrents(new List<DelugeTorrent>
|
||||
{
|
||||
_downloading
|
||||
});
|
||||
@@ -145,7 +150,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
|
||||
protected void PrepareClientToReturnFailedItem()
|
||||
{
|
||||
GivenTorrents(new List<DelugeTorrent>
|
||||
GivenTorrents(new List<DelugeTorrent>
|
||||
{
|
||||
_failed
|
||||
});
|
||||
@@ -189,6 +194,9 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
PrepareClientToReturnCompletedItem();
|
||||
var item = Subject.GetItems().Single();
|
||||
VerifyCompleted(item);
|
||||
|
||||
item.CanBeRemoved.Should().BeTrue();
|
||||
item.CanMoveFiles.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -248,11 +256,11 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
item.Status.Should().Be(expectedItemStatus);
|
||||
}
|
||||
|
||||
[TestCase(DelugeTorrentStatus.Paused, DownloadItemStatus.Completed, true)]
|
||||
[TestCase(DelugeTorrentStatus.Checking, DownloadItemStatus.Downloading, true)]
|
||||
[TestCase(DelugeTorrentStatus.Queued, DownloadItemStatus.Completed, true)]
|
||||
[TestCase(DelugeTorrentStatus.Seeding, DownloadItemStatus.Completed, true)]
|
||||
public void GetItems_should_return_completed_item_as_downloadItemStatus(string apiStatus, DownloadItemStatus expectedItemStatus, bool expectedReadOnly)
|
||||
[TestCase(DelugeTorrentStatus.Paused, DownloadItemStatus.Completed)]
|
||||
[TestCase(DelugeTorrentStatus.Checking, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DelugeTorrentStatus.Queued, DownloadItemStatus.Completed)]
|
||||
[TestCase(DelugeTorrentStatus.Seeding, DownloadItemStatus.Completed)]
|
||||
public void GetItems_should_return_completed_item_as_downloadItemStatus(string apiStatus, DownloadItemStatus expectedItemStatus)
|
||||
{
|
||||
_completed.State = apiStatus;
|
||||
|
||||
@@ -261,24 +269,25 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.DelugeTests
|
||||
var item = Subject.GetItems().Single();
|
||||
|
||||
item.Status.Should().Be(expectedItemStatus);
|
||||
item.IsReadOnly.Should().Be(expectedReadOnly);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_check_share_ratio_for_readonly()
|
||||
[TestCase(0.5, false)]
|
||||
[TestCase(1.01, true)]
|
||||
public void GetItems_should_check_share_ratio_for_moveFiles_and_remove(double ratio, bool canBeRemoved)
|
||||
{
|
||||
_completed.State = DelugeTorrentStatus.Paused;
|
||||
_completed.IsAutoManaged = true;
|
||||
_completed.StopAtRatio = true;
|
||||
_completed.StopRatio = 1.0;
|
||||
_completed.Ratio = 1.01;
|
||||
_completed.Ratio = ratio;
|
||||
|
||||
PrepareClientToReturnCompletedItem();
|
||||
|
||||
var item = Subject.GetItems().Single();
|
||||
|
||||
item.Status.Should().Be(DownloadItemStatus.Completed);
|
||||
item.IsReadOnly.Should().BeFalse();
|
||||
item.CanMoveFiles.Should().Be(canBeRemoved);
|
||||
item.CanBeRemoved.Should().Be(canBeRemoved);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SerialNumberProviderFixture : CoreTest<SerialNumberProvider>
|
||||
{
|
||||
protected DownloadStationSettings _settings;
|
||||
|
||||
[SetUp]
|
||||
protected void Setup()
|
||||
{
|
||||
_settings = new DownloadStationSettings();
|
||||
}
|
||||
|
||||
private void GivenValidResponse()
|
||||
{
|
||||
Mocker.GetMock<IDSMInfoProxy>()
|
||||
.Setup(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns("serial");
|
||||
}
|
||||
|
||||
private void GivenInvalidResponse()
|
||||
{
|
||||
Mocker.GetMock<IDSMInfoProxy>()
|
||||
.Setup(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
|
||||
.Throws(new DownloadClientException("Serial response invalid"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_hashedserialnumber()
|
||||
{
|
||||
GivenValidResponse();
|
||||
|
||||
var serial = Subject.GetSerialNumber(_settings);
|
||||
|
||||
// This hash should remain the same for 'serial', so don't update the test if you change HashConverter, fix the code instead.
|
||||
serial.Should().Be("50DE66B735D30738618568294742FCF1DFA52A47");
|
||||
|
||||
Mocker.GetMock<IDSMInfoProxy>()
|
||||
.Verify(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_cache_serialnumber()
|
||||
{
|
||||
GivenValidResponse();
|
||||
|
||||
var serial1 = Subject.GetSerialNumber(_settings);
|
||||
var serial2 = Subject.GetSerialNumber(_settings);
|
||||
|
||||
serial2.Should().Be(serial1);
|
||||
|
||||
Mocker.GetMock<IDSMInfoProxy>()
|
||||
.Verify(d => d.GetSerialNumber(It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_serial_number_unavailable()
|
||||
{
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.GetSerialNumber(_settings));
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Core.Download.Clients;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SharedFolderResolverFixture : CoreTest<SharedFolderResolver>
|
||||
{
|
||||
protected string _serialNumber = "SERIALNUMBER";
|
||||
protected OsPath _sharedFolder;
|
||||
protected OsPath _physicalPath;
|
||||
protected DownloadStationSettings _settings;
|
||||
|
||||
[SetUp]
|
||||
protected void Setup()
|
||||
{
|
||||
_sharedFolder = new OsPath("/myFolder");
|
||||
_physicalPath = new OsPath("/mnt/sda1/folder");
|
||||
_settings = new DownloadStationSettings();
|
||||
|
||||
Mocker.GetMock<IFileStationProxy>()
|
||||
.Setup(f => f.GetSharedFolderMapping(It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Throws(new DownloadClientException("There is no shared folder"));
|
||||
|
||||
Mocker.GetMock<IFileStationProxy>()
|
||||
.Setup(f => f.GetSharedFolderMapping(_sharedFolder.FullPath, It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(new SharedFolderMapping(_sharedFolder.FullPath, _physicalPath.FullPath));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_throw_when_cannot_resolve_shared_folder()
|
||||
{
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.RemapToFullPath(new OsPath("/unknownFolder"), _settings, _serialNumber));
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_valid_sharedfolder()
|
||||
{
|
||||
var mapping = Subject.RemapToFullPath(_sharedFolder, _settings, "abc");
|
||||
|
||||
mapping.Should().Be(_physicalPath);
|
||||
|
||||
Mocker.GetMock<IFileStationProxy>()
|
||||
.Verify(f => f.GetSharedFolderMapping(It.IsAny<string>(), It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_cache_mapping()
|
||||
{
|
||||
Subject.RemapToFullPath(_sharedFolder, _settings, "abc");
|
||||
Subject.RemapToFullPath(_sharedFolder, _settings, "abc");
|
||||
|
||||
Mocker.GetMock<IFileStationProxy>()
|
||||
.Verify(f => f.GetSharedFolderMapping(It.IsAny<string>(), It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_remap_subfolder()
|
||||
{
|
||||
var mapping = Subject.RemapToFullPath(_sharedFolder + "sub", _settings, "abc");
|
||||
|
||||
mapping.Should().Be(_physicalPath + "sub");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,626 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Core.Download;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation;
|
||||
using NzbDrone.Core.Download.Clients.DownloadStation.Proxies;
|
||||
using NzbDrone.Core.MediaFiles.TorrentInfo;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.Download.DownloadClientTests.DownloadStationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class TorrentDownloadStationFixture : DownloadClientFixtureBase<TorrentDownloadStation>
|
||||
{
|
||||
protected DownloadStationSettings _settings;
|
||||
|
||||
protected DownloadStationTask _queued;
|
||||
protected DownloadStationTask _downloading;
|
||||
protected DownloadStationTask _failed;
|
||||
protected DownloadStationTask _completed;
|
||||
protected DownloadStationTask _seeding;
|
||||
protected DownloadStationTask _magnet;
|
||||
protected DownloadStationTask _singleFile;
|
||||
protected DownloadStationTask _multipleFiles;
|
||||
protected DownloadStationTask _singleFileCompleted;
|
||||
protected DownloadStationTask _multipleFilesCompleted;
|
||||
|
||||
protected string _serialNumber = "SERIALNUMBER";
|
||||
protected string _category = "sonarr";
|
||||
protected string _tvDirectory = @"video/Series";
|
||||
protected string _defaultDestination = "somepath";
|
||||
protected OsPath _physicalPath = new OsPath("/mnt/sdb1/mydata");
|
||||
|
||||
protected Dictionary<string, object> _downloadStationConfigItems;
|
||||
|
||||
protected string DownloadURL => "magnet:?xt=urn:btih:5dee65101db281ac9c46344cd6b175cdcad53426&dn=download";
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_settings = new DownloadStationSettings()
|
||||
{
|
||||
Host = "127.0.0.1",
|
||||
Port = 5000,
|
||||
Username = "admin",
|
||||
Password = "pass"
|
||||
};
|
||||
|
||||
Subject.Definition = new DownloadClientDefinition();
|
||||
Subject.Definition.Settings = _settings;
|
||||
|
||||
_queued = new DownloadStationTask()
|
||||
{
|
||||
Id = "id1",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Waiting,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "0"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_completed = new DownloadStationTask()
|
||||
{
|
||||
Id = "id2",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Finished,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
_seeding = new DownloadStationTask()
|
||||
{
|
||||
Id = "id2",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Seeding,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_downloading = new DownloadStationTask()
|
||||
{
|
||||
Id = "id3",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Downloading,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "100"},
|
||||
{ "speed_download", "50" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_failed = new DownloadStationTask()
|
||||
{
|
||||
Id = "id4",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Error,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "10"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_singleFile = new DownloadStationTask()
|
||||
{
|
||||
Id = "id5",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Seeding,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "a.mkv",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_multipleFiles = new DownloadStationTask()
|
||||
{
|
||||
Id = "id6",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Seeding,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_singleFileCompleted = new DownloadStationTask()
|
||||
{
|
||||
Id = "id6",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Finished,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "a.mkv",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
_multipleFilesCompleted = new DownloadStationTask()
|
||||
{
|
||||
Id = "id6",
|
||||
Size = 1000,
|
||||
Status = DownloadStationTaskStatus.Finished,
|
||||
Type = DownloadStationTaskType.BT.ToString(),
|
||||
Username = "admin",
|
||||
Title = "title",
|
||||
Additional = new DownloadStationTaskAdditional
|
||||
{
|
||||
Detail = new Dictionary<string, string>
|
||||
{
|
||||
{ "destination","shared/folder" },
|
||||
{ "uri", DownloadURL }
|
||||
},
|
||||
Transfer = new Dictionary<string, string>
|
||||
{
|
||||
{ "size_downloaded", "1000"},
|
||||
{ "speed_download", "0" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Mocker.GetMock<ITorrentFileInfoReader>()
|
||||
.Setup(s => s.GetHashFromTorrentFile(It.IsAny<byte[]>()))
|
||||
.Returns("CBC2F069FE8BB2F544EAE707D75BCD3DE9DCF951");
|
||||
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
|
||||
|
||||
_downloadStationConfigItems = new Dictionary<string, object>
|
||||
{
|
||||
{ "default_destination", _defaultDestination },
|
||||
};
|
||||
|
||||
Mocker.GetMock<IDownloadStationInfoProxy>()
|
||||
.Setup(v => v.GetConfig(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(_downloadStationConfigItems);
|
||||
}
|
||||
|
||||
protected void GivenSharedFolder()
|
||||
{
|
||||
Mocker.GetMock<ISharedFolderResolver>()
|
||||
.Setup(s => s.RemapToFullPath(It.IsAny<OsPath>(), It.IsAny<DownloadStationSettings>(), It.IsAny<string>()))
|
||||
.Returns<OsPath, DownloadStationSettings, string>((path, setttings, serial) => _physicalPath);
|
||||
}
|
||||
|
||||
protected void GivenSerialNumber()
|
||||
{
|
||||
Mocker.GetMock<ISerialNumberProvider>()
|
||||
.Setup(s => s.GetSerialNumber(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(_serialNumber);
|
||||
}
|
||||
|
||||
protected void GivenTvCategory()
|
||||
{
|
||||
_settings.TvCategory = _category;
|
||||
}
|
||||
|
||||
protected void GivenTvDirectory()
|
||||
{
|
||||
_settings.TvDirectory = _tvDirectory;
|
||||
}
|
||||
|
||||
protected virtual void GivenTasks(List<DownloadStationTask> torrents)
|
||||
{
|
||||
if (torrents == null)
|
||||
{
|
||||
torrents = new List<DownloadStationTask>();
|
||||
}
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Setup(s => s.GetTasks(It.IsAny<DownloadStationSettings>()))
|
||||
.Returns(torrents);
|
||||
}
|
||||
|
||||
protected void PrepareClientToReturnQueuedItem()
|
||||
{
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_queued
|
||||
});
|
||||
}
|
||||
|
||||
protected void GivenSuccessfulDownload()
|
||||
{
|
||||
Mocker.GetMock<IHttpClient>()
|
||||
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
|
||||
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[1000]));
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Setup(s => s.AddTaskFromUrl(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Callback(PrepareClientToReturnQueuedItem);
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Setup(s => s.AddTaskFromData(It.IsAny<byte[]>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<DownloadStationSettings>()))
|
||||
.Callback(PrepareClientToReturnQueuedItem);
|
||||
}
|
||||
|
||||
protected override RemoteEpisode CreateRemoteEpisode()
|
||||
{
|
||||
var episode = base.CreateRemoteEpisode();
|
||||
|
||||
episode.Release.DownloadUrl = DownloadURL;
|
||||
|
||||
return episode;
|
||||
}
|
||||
|
||||
protected int GivenAllKindOfTasks()
|
||||
{
|
||||
var tasks = new List<DownloadStationTask>() { _queued, _completed, _failed, _downloading, _seeding };
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Setup(d => d.GetTasks(_settings))
|
||||
.Returns(tasks);
|
||||
|
||||
return tasks.Count;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_with_TvDirectory_should_force_directory()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenTvDirectory();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), _tvDirectory, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_with_category_should_force_directory()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenTvCategory();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), $"{_defaultDestination}/{_category}", It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_without_TvDirectory_and_Category_should_use_default()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSuccessfulDownload();
|
||||
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
var id = Subject.Download(remoteEpisode);
|
||||
|
||||
id.Should().NotBeNullOrEmpty();
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, It.IsAny<DownloadStationSettings>()), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_return_empty_list_if_no_tasks_available()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTasks(new List<DownloadStationTask>());
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_return_ignore_tasks_of_unknown_type()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTasks(new List<DownloadStationTask> { _completed });
|
||||
|
||||
_completed.Type = "ipfs";
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_ignore_downloads_in_wrong_folder()
|
||||
{
|
||||
_settings.TvDirectory = @"/shared/folder/sub";
|
||||
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
GivenTasks(new List<DownloadStationTask> { _completed });
|
||||
|
||||
Subject.GetItems().Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_throw_if_shared_folder_resolve_fails()
|
||||
{
|
||||
Mocker.GetMock<ISharedFolderResolver>()
|
||||
.Setup(s => s.RemapToFullPath(It.IsAny<OsPath>(), It.IsAny<DownloadStationSettings>(), It.IsAny<string>()))
|
||||
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
|
||||
|
||||
GivenSerialNumber();
|
||||
GivenAllKindOfTasks();
|
||||
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.GetItems());
|
||||
ExceptionVerification.ExpectedErrors(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_throw_if_serial_number_unavailable()
|
||||
{
|
||||
Mocker.GetMock<ISerialNumberProvider>()
|
||||
.Setup(s => s.GetSerialNumber(_settings))
|
||||
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
|
||||
|
||||
GivenSharedFolder();
|
||||
GivenAllKindOfTasks();
|
||||
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.GetItems());
|
||||
ExceptionVerification.ExpectedErrors(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Download_should_throw_and_not_add_task_if_cannot_get_serial_number()
|
||||
{
|
||||
var remoteEpisode = CreateRemoteEpisode();
|
||||
|
||||
Mocker.GetMock<ISerialNumberProvider>()
|
||||
.Setup(s => s.GetSerialNumber(_settings))
|
||||
.Throws(new ApplicationException("Some unknown exception, HttpException or DownloadClientException"));
|
||||
|
||||
Assert.Throws(Is.InstanceOf<Exception>(), () => Subject.Download(remoteEpisode));
|
||||
|
||||
Mocker.GetMock<IDownloadStationTaskProxy>()
|
||||
.Verify(v => v.AddTaskFromUrl(It.IsAny<string>(), null, _settings), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_base_folder_when_single_file_non_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>() { _singleFile });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().OutputPath.Should().Be(_physicalPath + _singleFile.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files_non_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>() { _multipleFiles });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().OutputPath.Should().Be(_physicalPath + _multipleFiles.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_base_folder_when_single_file_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>() { _singleFileCompleted });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().OutputPath.Should().Be(_physicalPath + _singleFileCompleted.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_set_outputPath_to_torrent_folder_when_multiple_files_finished_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>() { _multipleFilesCompleted });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
items.First().OutputPath.Should().Be($"{_physicalPath}/{_multipleFiles.Title}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_not_map_outputpath_for_queued_or_downloading_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_queued, _downloading
|
||||
});
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(2);
|
||||
items.Should().OnlyContain(v => v.OutputPath.IsEmpty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetItems_should_map_outputpath_for_completed_or_failed_tasks()
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>
|
||||
{
|
||||
_completed, _failed, _seeding
|
||||
});
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(3);
|
||||
items.Should().OnlyContain(v => !v.OutputPath.IsEmpty);
|
||||
}
|
||||
|
||||
[TestCase(DownloadStationTaskStatus.Downloading, false, false)]
|
||||
[TestCase(DownloadStationTaskStatus.Finished, true, true)]
|
||||
[TestCase(DownloadStationTaskStatus.Seeding, true, false)]
|
||||
[TestCase(DownloadStationTaskStatus.Waiting, false, false)]
|
||||
public void GetItems_should_return_canBeMoved_and_canBeDeleted_as_expected(DownloadStationTaskStatus apiStatus, bool canMoveFilesExpected, bool canBeRemovedExpected)
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
var item = items.First();
|
||||
|
||||
item.CanBeRemoved.Should().Be(canBeRemovedExpected);
|
||||
item.CanMoveFiles.Should().Be(canMoveFilesExpected);
|
||||
}
|
||||
|
||||
[TestCase(DownloadStationTaskStatus.Downloading, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.Error, DownloadItemStatus.Failed)]
|
||||
[TestCase(DownloadStationTaskStatus.Extracting, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.Finished, DownloadItemStatus.Completed)]
|
||||
[TestCase(DownloadStationTaskStatus.Finishing, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.HashChecking, DownloadItemStatus.Downloading)]
|
||||
[TestCase(DownloadStationTaskStatus.Paused, DownloadItemStatus.Paused)]
|
||||
[TestCase(DownloadStationTaskStatus.Seeding, DownloadItemStatus.Completed)]
|
||||
[TestCase(DownloadStationTaskStatus.Waiting, DownloadItemStatus.Queued)]
|
||||
public void GetItems_should_return_item_as_downloadItemStatus(DownloadStationTaskStatus apiStatus, DownloadItemStatus expectedItemStatus)
|
||||
{
|
||||
GivenSerialNumber();
|
||||
GivenSharedFolder();
|
||||
|
||||
_queued.Status = apiStatus;
|
||||
|
||||
GivenTasks(new List<DownloadStationTask>() { _queued });
|
||||
|
||||
var items = Subject.GetItems();
|
||||
items.Should().HaveCount(1);
|
||||
|
||||
items.First().Status.Should().Be(expectedItemStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||