fixed more tests.

pull/4/head
kay.one 12 years ago
parent 48880e4964
commit 048162a0ef

@ -11,9 +11,9 @@ namespace NzbDrone.Api.Calendar
{
public class CalendarModule : NzbDroneApiModule
{
private readonly EpisodeService _episodeService;
private readonly IEpisodeService _episodeService;
public CalendarModule(EpisodeService episodeService)
public CalendarModule(IEpisodeService episodeService)
: base("/calendar")
{
_episodeService = episodeService;

@ -9,9 +9,9 @@ namespace NzbDrone.Api.Episodes
{
public class EpisodeModule : NzbDroneApiModule
{
private readonly EpisodeService _episodeService;
private readonly IEpisodeService _episodeService;
public EpisodeModule(EpisodeService episodeService)
public EpisodeModule(IEpisodeService episodeService)
: base("/episodes")
{
_episodeService = episodeService;

@ -10,9 +10,9 @@ namespace NzbDrone.Api.Missing
{
public class MissingModule : NzbDroneApiModule
{
private readonly EpisodeService _episodeService;
private readonly IEpisodeService _episodeService;
public MissingModule(EpisodeService episodeService)
public MissingModule(IEpisodeService episodeService)
: base("/missing")
{
_episodeService = episodeService;

@ -117,7 +117,7 @@ namespace NzbDrone.Api.Series
{
RuleSet("POST", () =>
{
RuleFor(s => ((ModelBase)s).Id).GreaterThan(0);
RuleFor(s => s.Id).GreaterThan(0);
RuleFor(s => s.Path).NotEmpty().Must(_diskProvider.FolderExists);
RuleFor(s => s.QualityProfileId).GreaterThan(0);
});

@ -56,8 +56,8 @@ namespace NzbDrone.Common
}
else
{
header[6] = (byte)(((ushort)PacketType.Blob & 0xff00) >> 8);
header[7] = (byte)((ushort)PacketType.Blob & 0x00ff);
header[6] = ((ushort)PacketType.Blob & 0xff00) >> 8;
header[7] = (ushort)PacketType.Blob & 0x00ff;
}
header[8] = (byte)((currentPacket & 0xff000000) >> 24);

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration />

@ -35,8 +35,8 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
Mocker.Resolve<QualityUpgradableSpecification>();
_upgradeDisk = Mocker.Resolve<UpgradeDiskSpecification>();
firstFile = new EpisodeFile { Quality = Quality.Bluray1080p, Proper = true, DateAdded = DateTime.Now };
secondFile = new EpisodeFile { Quality = Quality.Bluray1080p, Proper = true, DateAdded = DateTime.Now };
firstFile = new EpisodeFile { Quality = new QualityModel(Quality.Bluray1080p, true), DateAdded = DateTime.Now };
secondFile = new EpisodeFile { Quality = new QualityModel(Quality.Bluray1080p, true), DateAdded = DateTime.Now };
var singleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = null } };
var doubleEpisodeList = new List<Episode> { new Episode { EpisodeFile = firstFile }, new Episode { EpisodeFile = secondFile }, new Episode { EpisodeFile = null } };
@ -66,12 +66,12 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
private void WithFirstFileUpgradable()
{
firstFile.Quality = Quality.SDTV;
firstFile.Quality = new QualityModel(Quality.SDTV);
}
private void WithSecondFileUpgradable()
{
secondFile.Quality = Quality.SDTV;
secondFile.Quality = new QualityModel(Quality.SDTV);
}
[Test]
@ -120,8 +120,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
[Test]
public void should_not_be_upgradable_if_qualities_are_the_same()
{
firstFile.Quality = Quality.WEBDL1080p;
firstFile.Proper = false;
firstFile.Quality = new QualityModel(Quality.WEBDL1080p);
parseResultSingle.Quality = new QualityModel(Quality.WEBDL1080p, false);
_upgradeDisk.IsSatisfiedBy(parseResultSingle).Should().BeFalse();
}

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using FluentAssertions;
using Moq;
using NUnit.Framework;
@ -13,7 +9,7 @@ using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests
namespace NzbDrone.Core.Test.Download.DownloadClientTests
{
[TestFixture]
public class BlackholeProviderFixture : CoreTest

@ -1,19 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetProviderTests
{
public class DownloadNzbFixture : CoreTest
{

@ -1,19 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.NzbgetProviderTests
namespace NzbDrone.Core.Test.Download.DownloadClientTests.NzbgetProviderTests
{
public class QueueFixture : CoreTest
{

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using FluentAssertions;
using Moq;
using NUnit.Framework;
@ -13,7 +9,7 @@ using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests
namespace NzbDrone.Core.Test.Download.DownloadClientTests
{
[TestFixture]
public class PneumaticProviderFixture : CoreTest

@ -1,24 +1,19 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabProviderTests
{
[TestFixture]

@ -1,24 +1,15 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Model;
using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.ProviderTests.DownloadClientTests.SabProviderTests
namespace NzbDrone.Core.Test.Download.DownloadClientTests.SabProviderTests
{
[TestFixture]

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.Model;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.Download
{
[TestFixture]
public class DownloadServiceFixture : CoreTest<DownloadService>
{
private EpisodeParseResult _parseResult;
[SetUp]
public void Setup()
{
Mocker.GetMock<IProvideDownloadClient>()
.Setup(c => c.GetDownloadClient()).Returns(Mocker.GetMock<IDownloadClient>().Object);
var episodes = Builder<Episode>.CreateListOfSize(2)
.TheFirst(1).With(s => s.Id = 12)
.TheNext(1).With(s => s.Id = 99)
.All().With(s => s.SeriesId = 5)
.Build().ToList();
_parseResult = Builder<EpisodeParseResult>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.DVD, false))
.With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c => c.EpisodeNumbers = new List<int> { 2 })
.With(c => c.Episodes = episodes)
.Build();
}
private void WithSuccessfulAdd()
{
Mocker.GetMock<IDownloadClient>()
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<bool>()))
.Returns(true);
}
private void WithFailedAdd()
{
Mocker.GetMock<IDownloadClient>()
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<bool>()))
.Returns(false);
}
[Test]
public void Download_report_should_publish_on_grab_event()
{
WithSuccessfulAdd();
Subject.DownloadReport(_parseResult);
VerifyEventPublished<EpisodeGrabbedEvent>();
}
[Test]
public void Download_report_should_grab_using_client()
{
WithSuccessfulAdd();
Subject.DownloadReport(_parseResult);
Mocker.GetMock<IDownloadClient>()
.Verify(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), true), Times.Once());
}
[Test]
public void Download_report_should_not_publish_on_failed_grab_event()
{
WithFailedAdd();
Subject.DownloadReport(_parseResult);
VerifyEventNotPublished<EpisodeGrabbedEvent>();
}
}
}

@ -18,10 +18,10 @@ namespace NzbDrone.Core.Test.IndexerSearchTests
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public TestSearch(IEpisodeService episodeService, IDownloadProvider downloadProvider,
public TestSearch(IEpisodeService episodeService, IDownloadService downloadService,
IIndexerService indexerService, ISceneMappingService sceneMappingService,
IDownloadDirector downloadDirector, ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
: base(seriesRepository, episodeService, downloadService, indexerService, sceneMappingService,
downloadDirector)
{
}

@ -85,8 +85,7 @@ namespace NzbDrone.Core.Test.MediaFileTests
var file = Builder<EpisodeFile>.CreateNew()
.With(f => f.SeriesId = fakeSeries.Id)
.With(f => f.Path = currentFilename)
.With(f => f.Quality = Quality.WEBDL720p)
.With(f => f.Proper = false)
.With(f => f.Quality = new QualityModel(Quality.WEBDL720p))
.Build();
Mocker.GetMock<ISeriesRepository>()
@ -137,8 +136,7 @@ namespace NzbDrone.Core.Test.MediaFileTests
var file = Builder<EpisodeFile>.CreateNew()
.With(f => f.SeriesId = fakeSeries.Id)
.With(f => f.Path = currentFilename)
.With(f => f.Quality = Quality.WEBDL720p)
.With(f => f.Proper = false)
.With(f => f.Quality = new QualityModel(Quality.WEBDL720p))
.Build();
Mocker.GetMock<ISeriesRepository>()

@ -4,7 +4,9 @@ using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.MediaFileTests
{
@ -17,9 +19,10 @@ namespace NzbDrone.Core.Test.MediaFileTests
var files = Builder<EpisodeFile>.CreateListOfSize(10)
.All()
.With(c => c.Id = 0)
.With(c => c.Quality =new QualityModel(Quality.Bluray720p))
.Random(4)
.With(s => s.SeriesId = 12)
.Build();
.BuildListOfNew();
Db.InsertMany(files);

@ -135,6 +135,13 @@
<Compile Include="Datastore\DatabaseRelationshipFixture.cs" />
<Compile Include="Datastore\MappingExtentionFixture.cs" />
<Compile Include="Datastore\ObjectDatabaseFixture.cs" />
<Compile Include="Download\DownloadClientTests\BlackholeProviderFixture.cs" />
<Compile Include="Download\DownloadClientTests\NzbgetProviderTests\DownloadNzbFixture.cs" />
<Compile Include="Download\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" />
<Compile Include="Download\DownloadClientTests\PneumaticProviderFixture.cs" />
<Compile Include="Download\DownloadClientTests\SabProviderTests\QueueFixture.cs" />
<Compile Include="Download\DownloadClientTests\SabProviderTests\SabProviderFixture.cs" />
<Compile Include="Download\DownloadServiceFixture.cs" />
<Compile Include="Framework\CoreTest.cs" />
<Compile Include="Framework\DbTest.cs" />
<Compile Include="Framework\NBuilderExtensions.cs" />
@ -158,9 +165,6 @@
<Compile Include="MediaFileTests\MediaFileRepositoryFixture.cs" />
<Compile Include="MediaFileTests\EpisodeFileMoverFixture.cs" />
<Compile Include="MetadataSourceTests\TracktProxyFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\DownloadNzbFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\NzbgetProviderTests\QueueFixture.cs" />
<Compile Include="ProviderTests\DownloadProviderTests\ContainsRecentEpisode.cs" />
<Compile Include="RootFolderTests\FreeSpaceOnDrivesFixture.cs" />
<Compile Include="HelperTests\XElementHelperTests\ConvertToDayOfWeekFixture.cs" />
<Compile Include="Qualities\QualityFixture.cs" />
@ -176,8 +180,6 @@
<Compile Include="ProviderTests\DiskScanProviderTests\CleanUpDropFolderFixture.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\GetVideoFilesFixture.cs" />
<Compile Include="ProviderTests\DiskScanProviderTests\ScanFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\PneumaticProviderFixture.cs" />
<Compile Include="TvTests\EpisodeProviderTests\GetEpisodeBySceneNumberFixture.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessDropDirectoryFixture.cs" />
<Compile Include="ProviderTests\PostDownloadProviderTests\ProcessVideoFileFixture.cs" />
<Compile Include="ProviderTests\RecycleBinProviderTests\CleanupFixture.cs" />
@ -192,9 +194,7 @@
<Compile Include="DecisionEngineTests\UpgradeDiskSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\QualityUpgradeSpecificationFixture.cs" />
<Compile Include="DecisionEngineTests\QualityUpgradableSpecificationFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\BlackholeProviderFixture.cs" />
<Compile Include="ProviderTests\NotificationProviderTests\NotificationProviderFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\SabProviderTests\QueueFixture.cs" />
<Compile Include="Indexers\NewznabServiceTest.cs" />
<Compile Include="ProviderTests\DiskProviderTests\FreeDiskSpaceTest.cs" />
<Compile Include="ProviderTests\ProwlProviderTest.cs" />
@ -223,7 +223,6 @@
<Compile Include="InstrumentationTests\DatabaseTargetFixture.cs" />
<Compile Include="OrganizerTests\GetNewFilenameFixture.cs" />
<Compile Include="DecisionEngineTests\MonitoredEpisodeSpecificationFixture.cs" />
<Compile Include="ProviderTests\DownloadProviderTests\DownloadProviderFixture.cs" />
<Compile Include="EpisodeStatusTest.cs" />
<Compile Include="JobTests\DiskScanJobTest.cs" />
<Compile Include="IndexerTests\IndexerFixture.cs" />
@ -240,7 +239,6 @@
<Compile Include="ParserTests\ParserFixture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Qualities\QualityProfileFixture.cs" />
<Compile Include="ProviderTests\DownloadClientTests\SabProviderTests\SabProviderFixture.cs" />
<Compile Include="TvTests\SeriesProviderTest.cs" />
<Compile Include="XbmcVersionTests.cs" />
</ItemGroup>

@ -63,7 +63,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("South Park - S15E06 - City Sushi [HDTV-720p]", result);
@ -90,7 +90,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("15x06 - City Sushi [HDTV-720p]", result);
@ -117,7 +117,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("South Park 05x06 [HDTV-720p]", result);
@ -145,7 +145,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("South Park s05e06", result);
@ -172,7 +172,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("South.Park.s05e06.City.Sushi", result);
@ -199,7 +199,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("South.Park.-.s05e06.-.City.Sushi.[HDTV-720p]", result);
@ -227,7 +227,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("S15E06", result);
@ -261,7 +261,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("The Mentalist - S03E23-E24 - Strawberries and Cream [HDTV-720p]", result);
@ -295,7 +295,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("3x23x24 - Strawberries and Cream [HDTV-720p]", result);
@ -329,7 +329,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("3x23x24 Strawberries and Cream [HDTV-720p]", result);
@ -363,7 +363,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("The.Mentalist.s03e23.s03e24.Strawberries.and.Cream", result);
@ -397,7 +397,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("The.Mentalist.-.S03E23-24", result);
@ -431,7 +431,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episodeOne, episodeTwo }, new Series { Title = "The Mentalist" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("3x23x24", result);
@ -456,7 +456,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = true });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p, true) });
result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p] [Proper]");
@ -481,7 +481,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("South Park - S15E06 - City Sushi [HDTV-720p]");
@ -506,7 +506,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = true });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p, true) });
result.Should().Be("South Park - S15E06 - City Sushi");
@ -538,7 +538,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
@ -565,7 +565,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("South Park.S15E06.City Sushi [HDTV-720p]", result);
@ -592,7 +592,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode }, _series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
Assert.AreEqual("15x06.City Sushi [HDTV-720p]", result);
@ -686,7 +686,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("30 Rock - S06E06-E07 - Hey, Baby, What's Wrong!");
@ -718,7 +718,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode2, episode }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("30 Rock - S06E06-E07 - Hello + World");
@ -756,7 +756,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
string result = Subject.BuildFilename(new List<Episode> { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
string result = Subject.BuildFilename(new List<Episode> { episode, episode2, episode3 }, new Series { Title = "30 Rock" }, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("30 Rock - S06E06-E07-E08 - Hello + World");
@ -787,7 +787,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
var result = Subject
.BuildFilename(episodes, series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
.BuildFilename(episodes, series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13 - Kristen Stewart [HDTV-720p]");
}
@ -816,7 +816,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
var result = Subject
.BuildFilename(episodes, series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
.BuildFilename(episodes, series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("The Daily Show with Jon Stewart - 2012-12-13");
}
@ -845,7 +845,7 @@ namespace NzbDrone.Core.Test.OrganizerTests
.Build();
var result = Subject
.BuildFilename(episodes, series, new EpisodeFile { Quality = Quality.HDTV720p, Proper = false });
.BuildFilename(episodes, series, new EpisodeFile { Quality = new QualityModel(Quality.HDTV720p) });
result.Should().Be("The Daily Show with Jon Stewart - Unknown - Kristen Stewart");
}
}

@ -87,8 +87,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
.With(g => g.Quality = (Quality)currentFileQuality)
.And(g => g.Proper = currentFileProper).Build()
.With(g => g.Quality = new QualityModel(currentFileQuality, currentFileProper))
.Build()
).Build();
@ -113,7 +113,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(c => c.EpisodeFile = Builder<EpisodeFile>.CreateNew()
.With(e => e.Quality = Quality.Bluray720p).Build()
.With(e => e.Quality = new QualityModel(Quality.Bluray720p)).Build()
)
.Build();
@ -214,7 +214,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(c => c.EpisodeFile = Builder<EpisodeFile>.CreateNew()
.With(e => e.Quality = Quality.SDTV).Build()
.With(e => e.Quality = new QualityModel(Quality.SDTV)).Build()
)
.Build();
@ -247,7 +247,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
.With(f => f.Quality = Quality.SDTV)
.With(f => f.Quality = new QualityModel(Quality.SDTV))
.Build())
.Build().ToList();
@ -278,7 +278,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var fakeEpisodes = Builder<Episode>.CreateListOfSize(2)
.All()
.With(e => e.EpisodeFile = Builder<EpisodeFile>.CreateNew()
.With(f => f.Quality = Quality.Bluray720p)
.With(f => f.Quality = new QualityModel(Quality.Bluray720p))
.Build())
.Build().ToList();
@ -310,7 +310,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
var fakeEpisodeFiles = Builder<EpisodeFile>.CreateListOfSize(2)
.All()
.With(e => e.Quality = Quality.SDTV)
.With(e => e.Quality = new QualityModel(Quality.SDTV))
.Build();
var fakeEpisode1 = Builder<Episode>.CreateNew()
@ -358,7 +358,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests
.Returns(false);
Mocker.GetMock<IEpisodeService>()
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode});
.Setup(e => e.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(new List<Episode> { fakeEpisode });
var result = Mocker.Resolve<DiskScanProvider>().ImportFile(fakeSeries, fileName);

@ -1,92 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
{
[TestFixture]
public class ContainsRecentEpisode : CoreTest
{
private Episode _recentEpisode;
private Episode _oldEpisode;
[SetUp]
public void Setup()
{
_recentEpisode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today)
.Build();
_oldEpisode = Builder<Episode>
.CreateNew()
.With(e => e.AirDate = DateTime.Today.AddDays(-365))
.Build();
}
[Test]
public void should_return_true_if_episode_aired_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_recentEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeTrue();
}
[Test]
public void should_return_true_if_one_episode_aired_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_recentEpisode,
_oldEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeTrue();
}
[Test]
public void should_return_false_if_episode_did_not_air_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_oldEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeFalse();
}
[Test]
public void should_return_false_if_no_episode_aired_recently()
{
var epr = Builder<EpisodeParseResult>
.CreateNew()
.With(p => p.Episodes = new List<Episode>
{
_oldEpisode,
_oldEpisode
})
.Build();
Mocker.Resolve<DownloadProvider>().ContainsRecentEpisode(epr).Should().BeFalse();
}
}
}

@ -1,128 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.ProviderTests.DownloadProviderTests
{
[TestFixture]
public class DownloadProviderFixture : CoreTest<DownloadProvider>
{
private void SetDownloadClient(DownloadClientType clientType)
{
Mocker.GetMock<IConfigService>()
.Setup(c => c.DownloadClient)
.Returns(clientType);
}
private EpisodeParseResult SetupParseResult()
{
var episodes = Builder<Episode>.CreateListOfSize(2)
.TheFirst(1).With(s => s.Id = 12)
.TheNext(1).With(s => s.Id = 99)
.All().With(s => s.SeriesId = 5)
.Build().ToList();
Mocker.GetMock<IEpisodeService>()
.Setup(c => c.GetEpisodesByParseResult(It.IsAny<EpisodeParseResult>())).Returns(episodes);
return Builder<EpisodeParseResult>.CreateNew()
.With(c => c.Quality = new QualityModel(Quality.DVD, false))
.With(c => c.Series = Builder<Series>.CreateNew().Build())
.With(c => c.EpisodeNumbers = new List<int> { 2 })
.With(c => c.Episodes = episodes)
.Build();
}
private void WithSuccessfullAdd()
{
Mocker.GetMock<SabProvider>()
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<bool>()))
.Returns(true);
Mocker.GetMock<BlackholeProvider>()
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<bool>()))
.Returns(true);
}
private void WithFailedAdd()
{
Mocker.GetMock<SabProvider>()
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), false))
.Returns(false);
Mocker.GetMock<BlackholeProvider>()
.Setup(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), false))
.Returns(false);
}
[Test]
public void Download_report_should_publish_on_grab_event()
{
WithSuccessfullAdd();
SetDownloadClient(DownloadClientType.Sabnzbd);
var parseResult = SetupParseResult();
Subject.DownloadReport(parseResult);
Mocker.GetMock<SabProvider>()
.Verify(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), true), Times.Once());
Mocker.GetMock<BlackholeProvider>()
.Verify(s => s.DownloadNzb(It.IsAny<String>(), It.IsAny<String>(), true), Times.Never());
VerifyEventPublished<EpisodeGrabbedEvent>();
}
[TestCase(DownloadClientType.Sabnzbd)]
[TestCase(DownloadClientType.Blackhole)]
public void Download_report_should_not_publish_grabbed_event(DownloadClientType clientType)
{
WithFailedAdd();
SetDownloadClient(clientType);
var parseResult = SetupParseResult();
Subject.DownloadReport(parseResult);
VerifyEventNotPublished<EpisodeGrabbedEvent>();
}
[Test]
public void should_return_sab_as_active_client()
{
SetDownloadClient(DownloadClientType.Sabnzbd);
Subject.GetActiveDownloadClient().Should().BeAssignableTo<SabProvider>();
}
[Test]
public void should_return_blackhole_as_active_client()
{
SetDownloadClient(DownloadClientType.Blackhole);
Subject.GetActiveDownloadClient().Should().BeAssignableTo<BlackholeProvider>();
}
}
}

@ -1,75 +0,0 @@

using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.TvTests.EpisodeProviderTests
{
[TestFixture]
public class GetEpisodeBySceneNumberFixture : DbTest
{
private Series _series;
private Episode _episode;
[SetUp]
public void Setup()
{
_series = Builder<Series>
.CreateNew()
.Build();
Db.Insert(_series);
}
public void WithNullSceneNumbering()
{
_episode = Builder<Episode>
.CreateNew()
.With(e => e.SeriesId = _series.Id)
.Build();
Db.Insert(_episode);
}
public void WithSceneNumbering()
{
_episode = Builder<Episode>
.CreateNew()
.With(e => e.SeriesId = _series.Id)
.Build();
Db.Insert(_episode);
}
[Test]
public void should_return_null_if_no_episodes_in_db()
{
Mocker.Resolve<EpisodeService>().GetEpisodeBySceneNumbering(_series.Id, 1, 1).Should().BeNull();
}
[Test]
public void should_return_null_if_no_matching_episode_is_found()
{
WithNullSceneNumbering();
Mocker.Resolve<EpisodeService>().GetEpisodeBySceneNumbering(_series.Id, 1, 1).Should().BeNull();
}
[Test]
public void should_return_episode_if_matching_episode_is_found()
{
WithSceneNumbering();
var result = Mocker.Resolve<EpisodeService>()
.GetEpisodeBySceneNumbering(_series.Id, _episode.SceneSeasonNumber, _episode.SceneEpisodeNumber);
result.Id.Should().Be(_episode.Id);
}
}
}

@ -68,8 +68,7 @@ namespace NzbDrone.Core.Datastore.Migration
Create.TableForModel("EpisodeFiles")
.WithColumn("SeriesId").AsInt32()
.WithColumn("Path").AsString().Unique()
.WithColumn("Quality").AsInt32()
.WithColumn("Proper").AsBoolean()
.WithColumn("Quality").AsString()
.WithColumn("Size").AsInt64()
.WithColumn("DateAdded").AsDateTime()
.WithColumn("SeasonNumber").AsInt32()

@ -6,13 +6,11 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{
public class NotInQueueSpecification : IFetchableSpecification
{
private readonly DownloadProvider _downloadProvider;
private readonly IProvideDownloadClient _downloadClientProvider;
public NotInQueueSpecification(DownloadProvider downloadProvider)
public NotInQueueSpecification(IProvideDownloadClient downloadClientProvider)
{
_downloadProvider = downloadProvider;
_downloadClientProvider = downloadClientProvider;
}
public string RejectionReason
@ -25,7 +23,7 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
public virtual bool IsSatisfiedBy(EpisodeParseResult subject)
{
return !_downloadProvider.GetActiveDownloadClient().IsInQueue(subject);
return !_downloadClientProvider.GetDownloadClient().IsInQueue(subject);
}
}

@ -29,8 +29,8 @@ namespace NzbDrone.Core.DecisionEngine.Specifications
{
foreach (var file in subject.Episodes.Select(c => c.EpisodeFile).Where(c => c != null))
{
_logger.Trace("Comparing file quality with report. Existing file is {0} proper:{1}", file.Quality, file.Proper);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, new QualityModel { Quality = file.Quality, Proper = file.Proper }, subject.Quality))
_logger.Trace("Comparing file quality with report. Existing file is {0}", file.Quality);
if (!_qualityUpgradableSpecification.IsUpgradable(subject.Series.QualityProfile, file.Quality, subject.Quality))
return false;
if (subject.Quality.Proper && file.DateAdded < DateTime.Today.AddDays(-7))

@ -0,0 +1,54 @@
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.Model;
namespace NzbDrone.Core.Download
{
public interface IProvideDownloadClient
{
IDownloadClient GetDownloadClient();
}
public class DownloadClientProvider : IProvideDownloadClient
{
private readonly SabProvider _sabProvider;
private readonly IConfigService _configService;
private readonly BlackholeProvider _blackholeProvider;
private readonly PneumaticProvider _pneumaticProvider;
private readonly NzbgetProvider _nzbgetProvider;
public DownloadClientProvider(SabProvider sabProvider, IConfigService configService,
BlackholeProvider blackholeProvider,
PneumaticProvider pneumaticProvider,
NzbgetProvider nzbgetProvider)
{
_sabProvider = sabProvider;
_configService = configService;
_blackholeProvider = blackholeProvider;
_pneumaticProvider = pneumaticProvider;
_nzbgetProvider = nzbgetProvider;
}
public IDownloadClient GetDownloadClient()
{
switch (_configService.DownloadClient)
{
case DownloadClientType.Blackhole:
return _blackholeProvider;
case DownloadClientType.Pneumatic:
return _pneumaticProvider;
case DownloadClientType.Nzbget:
return _nzbgetProvider;
default:
return _sabProvider;
}
}
}
}

@ -1,92 +0,0 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Clients.Nzbget;
using NzbDrone.Core.Download.Clients.Sabnzbd;
using NzbDrone.Core.Model;
namespace NzbDrone.Core.Download
{
public interface IDownloadProvider
{
bool DownloadReport(EpisodeParseResult parseResult);
IDownloadClient GetActiveDownloadClient();
bool ContainsRecentEpisode(EpisodeParseResult parseResult);
}
public class DownloadProvider : IDownloadProvider
{
private readonly SabProvider _sabProvider;
private readonly IConfigService _configService;
private readonly BlackholeProvider _blackholeProvider;
private readonly PneumaticProvider _pneumaticProvider;
private readonly NzbgetProvider _nzbgetProvider;
private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger;
public DownloadProvider(SabProvider sabProvider, IConfigService configService,
BlackholeProvider blackholeProvider,
PneumaticProvider pneumaticProvider,
NzbgetProvider nzbgetProvider,
IEventAggregator eventAggregator, Logger logger)
{
_sabProvider = sabProvider;
_configService = configService;
_blackholeProvider = blackholeProvider;
_pneumaticProvider = pneumaticProvider;
_nzbgetProvider = nzbgetProvider;
_eventAggregator = eventAggregator;
_logger = logger;
}
public virtual bool DownloadReport(EpisodeParseResult parseResult)
{
var downloadTitle = parseResult.OriginalString;
if (!_configService.DownloadClientUseSceneName)
{
downloadTitle = parseResult.GetDownloadTitle();
}
var provider = GetActiveDownloadClient();
var recentEpisode = ContainsRecentEpisode(parseResult);
bool success = provider.DownloadNzb(parseResult.NzbUrl, downloadTitle, recentEpisode);
if (success)
{
_logger.Trace("Download added to Queue: {0}", downloadTitle);
_eventAggregator.Publish(new EpisodeGrabbedEvent(parseResult));
}
return success;
}
public virtual IDownloadClient GetActiveDownloadClient()
{
switch (_configService.DownloadClient)
{
case DownloadClientType.Blackhole:
return _blackholeProvider;
case DownloadClientType.Pneumatic:
return _pneumaticProvider;
case DownloadClientType.Nzbget:
return _nzbgetProvider;
default:
return _sabProvider;
}
}
public virtual bool ContainsRecentEpisode(EpisodeParseResult parseResult)
{
return parseResult.Episodes.Any(e => e.AirDate >= DateTime.Today.AddDays(-7));
}
}
}

@ -0,0 +1,60 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Model;
namespace NzbDrone.Core.Download
{
public interface IDownloadService
{
bool DownloadReport(EpisodeParseResult parseResult);
}
public class DownloadService : IDownloadService
{
private readonly IProvideDownloadClient _downloadClientProvider;
private readonly IConfigService _configService;
private readonly IEventAggregator _eventAggregator;
private readonly Logger _logger;
public DownloadService(IProvideDownloadClient downloadClientProvider, IConfigService configService,
IEventAggregator eventAggregator, Logger logger)
{
_downloadClientProvider = downloadClientProvider;
_configService = configService;
_eventAggregator = eventAggregator;
_logger = logger;
}
public bool DownloadReport(EpisodeParseResult parseResult)
{
var downloadTitle = parseResult.OriginalString;
if (!_configService.DownloadClientUseSceneName)
{
downloadTitle = parseResult.GetDownloadTitle();
}
var provider = _downloadClientProvider.GetDownloadClient();
var recentEpisode = ContainsRecentEpisode(parseResult);
bool success = provider.DownloadNzb(parseResult.NzbUrl, downloadTitle, recentEpisode);
if (success)
{
_logger.Trace("Download added to Queue: {0}", downloadTitle);
_eventAggregator.Publish(new EpisodeGrabbedEvent(parseResult));
}
return success;
}
private static bool ContainsRecentEpisode(EpisodeParseResult parseResult)
{
return parseResult.Episodes.Any(e => e.AirDate >= DateTime.Today.AddDays(-7));
}
}
}

@ -19,10 +19,10 @@ namespace NzbDrone.Core.IndexerSearch
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public DailyEpisodeSearch(IEpisodeService episodeService, IDownloadProvider downloadProvider, IIndexerService indexerService,
public DailyEpisodeSearch(IEpisodeService episodeService, IDownloadService downloadService, IIndexerService indexerService,
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
: base(seriesRepository, episodeService, downloadService, indexerService, sceneMappingService,
downloadDirector)
{
}

@ -18,10 +18,10 @@ namespace NzbDrone.Core.IndexerSearch
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public EpisodeSearch(IEpisodeService episodeService, IDownloadProvider downloadProvider, IIndexerService indexerService,
public EpisodeSearch(IEpisodeService episodeService, IDownloadService downloadService, IIndexerService indexerService,
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
: base(seriesRepository, episodeService, downloadService, indexerService, sceneMappingService,
downloadDirector)
{
}

@ -18,7 +18,7 @@ namespace NzbDrone.Core.IndexerSearch
{
private readonly ISeriesRepository _seriesRepository;
private readonly IEpisodeService _episodeService;
private readonly IDownloadProvider _downloadProvider;
private readonly IDownloadService _downloadService;
private readonly ISceneMappingService _sceneMappingService;
private readonly IDownloadDirector DownloadDirector;
@ -26,13 +26,13 @@ namespace NzbDrone.Core.IndexerSearch
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
protected IndexerSearchBase(ISeriesRepository seriesRepository, IEpisodeService episodeService, IDownloadProvider downloadProvider,
protected IndexerSearchBase(ISeriesRepository seriesRepository, IEpisodeService episodeService, IDownloadService downloadService,
IIndexerService indexerService, ISceneMappingService sceneMappingService,
IDownloadDirector downloadDirector)
{
_seriesRepository = seriesRepository;
_episodeService = episodeService;
_downloadProvider = downloadProvider;
_downloadService = downloadService;
_indexerService = indexerService;
_sceneMappingService = sceneMappingService;
DownloadDirector = downloadDirector;
@ -117,7 +117,7 @@ namespace NzbDrone.Core.IndexerSearch
logger.Debug("Found '{0}'. Adding to download queue.", episodeParseResult);
try
{
if (_downloadProvider.DownloadReport(episodeParseResult))
if (_downloadService.DownloadReport(episodeParseResult))
{
return true;
}

@ -18,10 +18,10 @@ namespace NzbDrone.Core.IndexerSearch
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public PartialSeasonSearch(IEpisodeService episodeService, IDownloadProvider downloadProvider, IIndexerService indexerService,
public PartialSeasonSearch(IEpisodeService episodeService, IDownloadService downloadService, IIndexerService indexerService,
ISceneMappingService sceneMappingService, IDownloadDirector downloadDirector,
ISeriesRepository seriesRepository)
: base(seriesRepository, episodeService, downloadProvider, indexerService, sceneMappingService,
: base(seriesRepository, episodeService, downloadService, indexerService, sceneMappingService,
downloadDirector)
{
}

@ -54,7 +54,7 @@ namespace NzbDrone.Core.Jobs.Implementations
return;
}
if (!_qualityUpgradableSpecification.IsUpgradable(episode.Series.QualityProfile, episode.EpisodeFile.QualityModel))
if (!_qualityUpgradableSpecification.IsUpgradable(episode.Series.QualityProfile, episode.EpisodeFile.Quality))
{
logger.Info("Search for {0} was aborted, file in disk meets or exceeds Profile's Cutoff", episode);
notification.CurrentMessage = String.Format("Skipping search for {0}, the file you have is already at cutoff", episode);

@ -13,7 +13,7 @@ namespace NzbDrone.Core.Jobs.Implementations
{
public class RssSyncJob : IJob
{
private readonly DownloadProvider _downloadProvider;
private readonly DownloadService _downloadService;
private readonly IIndexerService _indexerService;
private readonly IDownloadDirector DownloadDirector;
private readonly IConfigService _configService;
@ -21,9 +21,9 @@ namespace NzbDrone.Core.Jobs.Implementations
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public RssSyncJob(DownloadProvider downloadProvider, IIndexerService indexerService, IDownloadDirector downloadDirector, IConfigService configService)
public RssSyncJob(DownloadService downloadService, IIndexerService indexerService, IDownloadDirector downloadDirector, IConfigService configService)
{
_downloadProvider = downloadProvider;
_downloadService = downloadService;
_indexerService = indexerService;
DownloadDirector = downloadDirector;
_configService = configService;
@ -71,7 +71,7 @@ namespace NzbDrone.Core.Jobs.Implementations
{
if (DownloadDirector.GetDownloadDecision(episodeParseResult).Approved)
{
_downloadProvider.DownloadReport(episodeParseResult);
_downloadService.DownloadReport(episodeParseResult);
}
}
catch (Exception e)

@ -1,7 +1,5 @@
using System.Linq;
using System;
using System;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Qualities;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.MediaFiles
@ -19,32 +17,17 @@ namespace NzbDrone.Core.MediaFiles
SeriesId = source.SeriesId;
SeasonNumber = source.SeasonNumber;
Path = source.Path;
Quality = source.Quality;
Proper = source.Proper;
Size = source.Size;
}
public int SeriesId { get; set; }
public int SeasonNumber { get; set; }
public string Path { get; set; }
public Quality Quality { get; set; }
public bool Proper { get; set; }
public long Size { get; set; }
public DateTime DateAdded { get; set; }
public string SceneName { get; set; }
public string ReleaseGroup { get; set; }
public QualityModel QualityModel
{
get
{
return new QualityModel(Quality, Proper);
}
set
{
Quality = value.Quality;
Proper = value.Proper;
}
}
public QualityModel Quality { get; set; }
}
}

@ -80,7 +80,7 @@ namespace NzbDrone.Core.MediaFiles
var parseResult = Parser.ParsePath(episodeFile.Path);
parseResult.Series = series;
parseResult.Quality = new QualityModel { Quality = episodeFile.Quality, Proper = episodeFile.Proper };
parseResult.Quality = episodeFile.Quality;
parseResult.Episodes = episodes;

@ -230,6 +230,7 @@
<Compile Include="DecisionEngine\Specifications\UpgradeDiskSpecification.cs" />
<Compile Include="DecisionEngine\Specifications\UpgradeHistorySpecification.cs" />
<Compile Include="Download\Clients\Sabnzbd\SabAutoConfigureService.cs" />
<Compile Include="Download\DownloadClientProvider.cs" />
<Compile Include="Download\EpisodeDownloadedEvent.cs" />
<Compile Include="Download\EpisodeGrabbedEvent.cs" />
<Compile Include="Download\SeriesRenamedEvent.cs" />
@ -402,7 +403,7 @@
<Compile Include="Download\Clients\Sabnzbd\SabProvider.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Download\DownloadProvider.cs">
<Compile Include="Download\DownloadService.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Tv\EpisodeRepository.cs">

@ -118,7 +118,7 @@ namespace NzbDrone.Core.Organizer
{
result += String.Format(" [{0}]", episodeFile.Quality);
if (episodeFile.Proper)
if (episodeFile.Quality.Proper)
result += " [Proper]";
}

@ -133,7 +133,7 @@ namespace NzbDrone.Core.Providers
}
//Make sure this file is an upgrade for ALL episodes already on disk
if (episodes.All(e => e.EpisodeFile == null || e.EpisodeFile.QualityModel <= parseResult.Quality))
if (episodes.All(e => e.EpisodeFile == null || e.EpisodeFile.Quality <= parseResult.Quality))
{
Logger.Debug("Deleting the existing file(s) on disk to upgrade to: {0}", filePath);
//Do the delete for files where there is already an episode on disk
@ -152,8 +152,7 @@ namespace NzbDrone.Core.Providers
episodeFile.SeriesId = series.Id;
episodeFile.Path = filePath.NormalizePath();
episodeFile.Size = size;
episodeFile.Quality = parseResult.Quality.Quality;
episodeFile.Proper = parseResult.Quality.Proper;
episodeFile.Quality = parseResult.Quality;
episodeFile.SeasonNumber = parseResult.SeasonNumber;
episodeFile.SceneName = Path.GetFileNameWithoutExtension(filePath.NormalizePath());
episodeFile.ReleaseGroup = parseResult.ReleaseGroup;

@ -42,7 +42,7 @@ namespace NzbDrone.Core.Providers.Xbmc
payload[offset++] = (byte)iconType;
for (int i = 0; i < 4; i++)
payload[offset++] = (byte)0;
payload[offset++] = 0;
Array.Copy(icon, 0, payload, caption.Length + message.Length + 7, icon.Length);

@ -4,19 +4,16 @@ using System.Linq;
using NLog;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Tv.Events;
namespace NzbDrone.Core.Tv
{
public interface IEpisodeService
{
void AddEpisode(Episode episode);
Episode GetEpisode(int id);
Episode GetEpisode(int seriesId, int seasonNumber, int episodeNumber);
Episode GetEpisode(int seriesId, DateTime date);
@ -33,7 +30,6 @@ namespace NzbDrone.Core.Tv
bool IsFirstOrLastEpisodeOfSeason(int seriesId, int seasonNumber, int episodeNumber);
void SetPostDownloadStatus(List<int> episodeIds, PostDownloadStatusType postDownloadStatus);
void UpdateEpisodes(List<Episode> episodes);
Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
List<Episode> EpisodesBetweenDates(DateTime start, DateTime end);
}
@ -63,11 +59,6 @@ namespace NzbDrone.Core.Tv
_logger = logger;
}
public void AddEpisode(Episode episode)
{
episode.Ignored = _seasonRepository.IsIgnored(episode.SeriesId, episode.SeasonNumber);
_episodeRepository.Insert(episode);
}
public Episode GetEpisode(int id)
{
@ -107,7 +98,7 @@ namespace NzbDrone.Core.Tv
return new List<Episode>();
}
var episodeInfo = GetEpisode(((ModelBase)parseResult.Series).Id, parseResult.AirDate.Value);
var episodeInfo = GetEpisode(parseResult.Series.Id, parseResult.AirDate.Value);
if (episodeInfo != null)
{
@ -129,14 +120,14 @@ namespace NzbDrone.Core.Tv
Episode episodeInfo = null;
if (parseResult.SceneSource && parseResult.Series.UseSceneNumbering)
episodeInfo = GetEpisodeBySceneNumbering(((ModelBase)parseResult.Series).Id, parseResult.SeasonNumber, episodeNumber);
episodeInfo = _episodeRepository.GetEpisodeBySceneNumbering(parseResult.Series.Id, parseResult.SeasonNumber, episodeNumber);
if (episodeInfo == null)
{
episodeInfo = GetEpisode(((ModelBase)parseResult.Series).Id, parseResult.SeasonNumber, episodeNumber);
episodeInfo = GetEpisode(parseResult.Series.Id, parseResult.SeasonNumber, episodeNumber);
if (episodeInfo == null && parseResult.AirDate != null)
{
episodeInfo = GetEpisode(((ModelBase)parseResult.Series).Id, parseResult.AirDate.Value);
episodeInfo = GetEpisode(parseResult.Series.Id, parseResult.AirDate.Value);
}
}
@ -362,11 +353,6 @@ namespace NzbDrone.Core.Tv
_episodeRepository.UpdateMany(episodes);
}
public Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber)
{
return _episodeRepository.GetEpisodeBySceneNumbering(seriesId, seasonNumber, episodeNumber);
}
public List<Episode> EpisodesBetweenDates(DateTime start, DateTime end)
{
return _episodeRepository.EpisodesBetweenDates(start.ToUniversalTime(), end.ToUniversalTime());

@ -11,12 +11,13 @@ namespace NzbDrone.Core.Tv
public Boolean Proper { get; set; }
public QualityModel():this(Quality.Unknown, false)
public QualityModel()
: this(Quality.Unknown)
{
}
public QualityModel(Quality quality, Boolean proper)
public QualityModel(Quality quality, Boolean proper = false)
{
Quality = quality;
Proper = proper;
@ -113,8 +114,8 @@ namespace NzbDrone.Core.Tv
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != typeof (QualityModel)) return false;
return Equals((QualityModel) obj);
if (obj.GetType() != typeof(QualityModel)) return false;
return Equals((QualityModel)obj);
}
}
}

@ -120,7 +120,7 @@ namespace NzbDrone.Core.Tv
foreach (var series in allSeries)
{
//Only update parameters that can be changed in MassEdit
var edited = editedSeries.Single(s => ((ModelBase)s).Id == series.Id);
var edited = editedSeries.Single(s => s.Id == series.Id);
series.QualityProfileId = edited.QualityProfileId;
series.Monitored = edited.Monitored;
series.SeasonFolder = edited.SeasonFolder;

Loading…
Cancel
Save