mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-25 11:13:39 +02:00
Merge branch 'markus101'
This commit is contained in:
commit
eaaf464d38
@ -55,10 +55,12 @@ namespace NzbDrone.Core.Test
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.MarkEpisodeAsFetched(12));
|
||||
|
||||
|
||||
mocker.GetMock<EpisodeProvider>()
|
||||
.Setup(c => c.MarkEpisodeAsFetched(99));
|
||||
|
||||
mocker.GetMock<ExternalNotificationProvider>()
|
||||
.Setup(c => c.OnGrab(It.IsAny<string>()));
|
||||
|
||||
mocker.Resolve<DownloadProvider>().DownloadReport(parseResult);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
|
@ -991,5 +991,246 @@ namespace NzbDrone.Core.Test
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IgnoreEpisode_Ignore()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.Have(c => c.Ignored = false)
|
||||
.Build().ToList();
|
||||
|
||||
episodes.ForEach(c => db.Insert(c));
|
||||
|
||||
//Act
|
||||
mocker.Resolve<EpisodeProvider>().SetEpisodeIgnore(1, true);
|
||||
|
||||
//Assert
|
||||
var episodesInDb = db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
||||
|
||||
episodesInDb.Should().HaveCount(4);
|
||||
episodesInDb.Where(e => e.Ignored).Should().HaveCount(1);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IgnoreEpisode_RemoveIgnore()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.Have(c => c.Ignored = true)
|
||||
.Build().ToList();
|
||||
|
||||
episodes.ForEach(c => db.Insert(c));
|
||||
|
||||
//Act
|
||||
mocker.Resolve<EpisodeProvider>().SetEpisodeIgnore(1, false);
|
||||
|
||||
//Assert
|
||||
var episodesInDb = db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
||||
|
||||
episodesInDb.Should().HaveCount(4);
|
||||
episodesInDb.Where(e => !e.Ignored).Should().HaveCount(1);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IgnoreSeason_Ignore()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.Have(c => c.Ignored = false)
|
||||
.Build().ToList();
|
||||
|
||||
episodes.ForEach(c => db.Insert(c));
|
||||
|
||||
//Act
|
||||
mocker.Resolve<EpisodeProvider>().SetSeasonIgnore(10, 1, true);
|
||||
|
||||
//Assert
|
||||
var episodesInDb = db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
||||
|
||||
episodesInDb.Should().HaveCount(4);
|
||||
episodesInDb.Where(e => e.Ignored).Should().HaveCount(4);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IgnoreSeason_RemoveIgnore()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.Have(c => c.Ignored = true)
|
||||
.Build().ToList();
|
||||
|
||||
episodes.ForEach(c => db.Insert(c));
|
||||
|
||||
//Act
|
||||
mocker.Resolve<EpisodeProvider>().SetSeasonIgnore(10, 1, false);
|
||||
|
||||
//Assert
|
||||
var episodesInDb = db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
||||
|
||||
episodesInDb.Should().HaveCount(4);
|
||||
episodesInDb.Where(e => !e.Ignored).Should().HaveCount(4);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IgnoreSeason_Ignore_Half()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.WhereTheFirst(2)
|
||||
.Have(c => c.Ignored = false)
|
||||
.AndTheRemaining()
|
||||
.Have(c => c.Ignored = true)
|
||||
.Build().ToList();
|
||||
|
||||
episodes.ForEach(c => db.Insert(c));
|
||||
|
||||
//Act
|
||||
mocker.Resolve<EpisodeProvider>().SetSeasonIgnore(10, 1, true);
|
||||
|
||||
//Assert
|
||||
var episodesInDb = db.Fetch<Episode>(@"SELECT * FROM Episodes");
|
||||
|
||||
episodesInDb.Should().HaveCount(4);
|
||||
episodesInDb.Where(e => e.Ignored).Should().HaveCount(4);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EpisodesWithoutFiles_no_specials()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = 10)
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.Have(c => c.AirDate = DateTime.Today.AddDays(-4))
|
||||
.Have(c => c.Ignored = true)
|
||||
.WhereTheFirst(2)
|
||||
.Have(c => c.EpisodeFileId = 0)
|
||||
.WhereSection(1, 2)
|
||||
.Have(c => c.Ignored = false)
|
||||
.Build().ToList();
|
||||
|
||||
var specials = Builder<Episode>.CreateListOfSize(2)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 0)
|
||||
.Have(c => c.AirDate = DateTime.Today.AddDays(-4))
|
||||
.Have(c => c.EpisodeFileId = 0)
|
||||
.WhereTheFirst(1)
|
||||
.Have(c => c.Ignored = true)
|
||||
.AndTheRemaining()
|
||||
.Have(c => c.Ignored = false)
|
||||
.Build().ToList();
|
||||
|
||||
db.Insert(series);
|
||||
db.InsertMany(episodes);
|
||||
db.InsertMany(specials);
|
||||
|
||||
//Act
|
||||
var missingFiles= mocker.Resolve<EpisodeProvider>().EpisodesWithoutFiles(false);
|
||||
|
||||
//Assert
|
||||
missingFiles.Should().HaveCount(1);
|
||||
missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(1);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EpisodesWithoutFiles_with_specials()
|
||||
{
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
var mocker = new AutoMoqer();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var series = Builder<Series>.CreateNew()
|
||||
.With(s => s.SeriesId = 10)
|
||||
.Build();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 1)
|
||||
.Have(c => c.AirDate = DateTime.Today.AddDays(-4))
|
||||
.Have(c => c.Ignored = true)
|
||||
.WhereTheFirst(2)
|
||||
.Have(c => c.EpisodeFileId = 0)
|
||||
.WhereSection(1,2)
|
||||
.Have(c => c.Ignored = false)
|
||||
.Build().ToList();
|
||||
|
||||
var specials = Builder<Episode>.CreateListOfSize(2)
|
||||
.WhereAll()
|
||||
.Have(c => c.SeriesId = 10)
|
||||
.Have(c => c.SeasonNumber = 0)
|
||||
.Have(c => c.AirDate = DateTime.Today.AddDays(-4))
|
||||
.Have(c => c.EpisodeFileId = 0)
|
||||
.WhereTheFirst(1)
|
||||
.Have(c => c.Ignored = true)
|
||||
.AndTheRemaining()
|
||||
.Have(c => c.Ignored = false)
|
||||
.Build().ToList();
|
||||
|
||||
db.Insert(series);
|
||||
db.InsertMany(episodes);
|
||||
db.InsertMany(specials);
|
||||
|
||||
//Act
|
||||
var missingFiles = mocker.Resolve<EpisodeProvider>().EpisodesWithoutFiles(true);
|
||||
|
||||
//Assert
|
||||
missingFiles.Should().HaveCount(2);
|
||||
missingFiles.Where(e => e.EpisodeFileId == 0).Should().HaveCount(2);
|
||||
|
||||
mocker.VerifyAllMocks();
|
||||
}
|
||||
}
|
||||
}
|
@ -41,6 +41,7 @@ namespace NzbDrone.Core.Test
|
||||
[TestCase("Adventure.Inc.S03E19.DVDRip.\"XviD\"-OSiTV", "Adventure.Inc", 3, 19)]
|
||||
[TestCase("Hawaii Five-0 (2010) - 1x05 - Nalowale (Forgotten/Missing)", "Hawaii Five-0 (2010)", 1, 5)]
|
||||
[TestCase("Hawaii Five-0 (2010) - 1x05 - Title", "Hawaii Five-0 (2010)", 1, 5)]
|
||||
[TestCase("House - S06E13 - 5 to 9 [DVD]", "House", 6, 13)]
|
||||
public void ParseTitle_single(string postTitle, string title, int seasonNumber, int episodeNumber)
|
||||
{
|
||||
var result = Parser.ParseTitle(postTitle);
|
||||
@ -131,7 +132,7 @@ namespace NzbDrone.Core.Test
|
||||
[TestCase("Two.and.a.Half.Men.103.104.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Men", 1, new[] { 3, 4 }, 2)]
|
||||
[TestCase("Weeds.S03E01.S03E02.720p.HDTV.X264-DIMENSION", "Weeds", 3, new[] { 1, 2 }, 2)]
|
||||
[TestCase("The Borgias S01e01 e02 ShoHD On Demand 1080i DD5 1 ALANiS", "The Borgias", 1, new[] { 1, 2 }, 2)]
|
||||
[TestCase("Big Time Rush 1x01 to 10 480i DD2 0 Sianto", "Big Time Rush", 1, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 10)]
|
||||
//[TestCase("Big Time Rush 1x01 to 10 480i DD2 0 Sianto", "Big Time Rush", 1, new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 10)]
|
||||
[TestCase("White.Collar.2x04.2x05.720p.BluRay-FUTV", "White.Collar", 2, new[] { 4, 5 }, 2)]
|
||||
[TestCase("Desperate.Housewives.S07E22E23.720p.HDTV.X264-DIMENSION", "Desperate.Housewives", 7, new[] { 22, 23 }, 2)]
|
||||
[TestCase("S07E22 - 7x23 - And Lots of Security.. [HDTV].mkv", "", 7, new[] { 22, 23 }, 2)]
|
||||
@ -203,6 +204,8 @@ namespace NzbDrone.Core.Test
|
||||
[TestCase("peri.od", "period")]
|
||||
[TestCase("this.^&%^**$%@#$!That", "thisthat")]
|
||||
[TestCase("test/test", "testtest")]
|
||||
[TestCase("90210", "90210")]
|
||||
[TestCase("24", "24")]
|
||||
public void Normalize_Title(string dirty, string clean)
|
||||
{
|
||||
var result = Parser.NormalizeTitle(dirty);
|
||||
|
@ -10,6 +10,7 @@ using NzbDrone.Core.Providers.Core;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using PetaPoco;
|
||||
|
||||
// ReSharper disable InconsistentNaming
|
||||
namespace NzbDrone.Core.Test
|
||||
@ -350,5 +351,129 @@ namespace NzbDrone.Core.Test
|
||||
series.QualityProfile.Should().NotBeNull();
|
||||
series.QualityProfileId.Should().Be(fakeQuality.QualityProfileId);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SeriesPathExists_exact_match()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var path = @"C:\Test\TV\30 Rock";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||
.WhereAll()
|
||||
.Have(c => c.QualityProfileId = 1)
|
||||
.WhereTheFirst(1)
|
||||
.Have(c => c.Path = path)
|
||||
.Build();
|
||||
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
||||
|
||||
db.InsertMany(fakeSeries);
|
||||
db.Insert(fakeQuality);
|
||||
|
||||
//Act
|
||||
mocker.Resolve<QualityProvider>();
|
||||
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
||||
//fakeSeries.ToList());
|
||||
|
||||
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(path);
|
||||
|
||||
//Assert
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SeriesPathExists_match()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var path = @"C:\Test\TV\30 Rock";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||
.WhereAll()
|
||||
.Have(c => c.QualityProfileId = 1)
|
||||
.WhereTheFirst(1)
|
||||
.Have(c => c.Path = path)
|
||||
.Build();
|
||||
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
||||
|
||||
db.InsertMany(fakeSeries);
|
||||
db.Insert(fakeQuality);
|
||||
|
||||
//Act
|
||||
mocker.Resolve<QualityProvider>();
|
||||
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
||||
//fakeSeries.ToList());
|
||||
|
||||
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(path.ToUpper());
|
||||
|
||||
//Assert
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SeriesPathExists_match_alt()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var path = @"C:\Test\TV\The Simpsons";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||
.WhereAll()
|
||||
.Have(c => c.QualityProfileId = 1)
|
||||
.WhereTheFirst(1)
|
||||
.Have(c => c.Path = path)
|
||||
.Build();
|
||||
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
||||
|
||||
db.InsertMany(fakeSeries);
|
||||
db.Insert(fakeQuality);
|
||||
|
||||
//Act
|
||||
mocker.Resolve<QualityProvider>();
|
||||
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
||||
//fakeSeries.ToList());
|
||||
|
||||
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(@"c:\Test\Tv\the sIMpsons");
|
||||
|
||||
//Assert
|
||||
result.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SeriesPathExists_match_false()
|
||||
{
|
||||
var mocker = new AutoMoqer(MockBehavior.Strict);
|
||||
var db = MockLib.GetEmptyDatabase();
|
||||
mocker.SetConstant(db);
|
||||
|
||||
var path = @"C:\Test\TV\30 Rock";
|
||||
|
||||
var fakeSeries = Builder<Series>.CreateListOfSize(10)
|
||||
.WhereAll()
|
||||
.Have(c => c.QualityProfileId = 1)
|
||||
.WhereTheFirst(1)
|
||||
.Have(c => c.Path = path)
|
||||
.Build();
|
||||
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
|
||||
|
||||
db.InsertMany(fakeSeries);
|
||||
db.Insert(fakeQuality);
|
||||
|
||||
//Act
|
||||
mocker.Resolve<QualityProvider>();
|
||||
//mocker.GetMock<IDatabase>().Setup(s => s.Fetch<Series, QualityProfile>(It.IsAny<string>())).Returns(
|
||||
//fakeSeries.ToList());
|
||||
|
||||
var result = mocker.Resolve<SeriesProvider>().SeriesPathExists(@"C:\Test\TV\Not A match");
|
||||
|
||||
//Assert
|
||||
result.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
} |