|
|
|
@ -41,7 +41,7 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
|
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
|
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -90,6 +90,35 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
episode.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisode_with_EpisodeFile()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).Build();
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 1).Have(e => e.EpisodeFile = fakeFile).Build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
db.Insert(fakeFile);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetSeries(1))
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
|
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
|
|
|
|
|
episode.EpisodeFile.Should().NotBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")]
|
|
|
|
|
public void GetEpisodes_invalid_series()
|
|
|
|
@ -124,7 +153,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
result.Should().HaveCount(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AttachSeries_list_success()
|
|
|
|
|
{
|
|
|
|
@ -195,7 +223,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
var returnedEpisode = mocker.Resolve<EpisodeProvider>().AttachSeries(fakeEpisodes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisodesBySeason_success()
|
|
|
|
|
{
|
|
|
|
@ -255,7 +282,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void new_episodes_only_calls_Insert()
|
|
|
|
|
{
|
|
|
|
@ -276,7 +302,7 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IDatabase>()
|
|
|
|
|
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -290,7 +316,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void existing_episodes_only_calls_Update()
|
|
|
|
|
{
|
|
|
|
@ -314,7 +339,7 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IDatabase>()
|
|
|
|
|
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
@ -326,7 +351,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
mocker.VerifyAllMocks();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_try_to_get_existing_episode_using_tvdbid_first()
|
|
|
|
|
{
|
|
|
|
@ -345,7 +369,7 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
mocker.GetMock<IDatabase>()
|
|
|
|
|
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Returns(fakeEpisodeList);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<TvDbProvider>()
|
|
|
|
@ -393,7 +417,7 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
.Returns(tvdbSeries);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IDatabase>()
|
|
|
|
|
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Returns(new List<Episode> { localEpisode });
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
@ -404,7 +428,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
mocker.GetMock<IDatabase>().Verify(c => c.Update(localEpisode), Times.Once());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void existing_episodes_keep_their_episodeId_file_id()
|
|
|
|
|
{
|
|
|
|
@ -430,7 +453,7 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
var updatedEpisodes = new List<Episode>();
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IDatabase>()
|
|
|
|
|
.Setup(d => d.Fetch<Episode>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Setup(d => d.Fetch<Episode, EpisodeFile>(It.IsAny<String>(), It.IsAny<Object[]>()))
|
|
|
|
|
.Returns(currentEpisodes);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<IDatabase>()
|
|
|
|
@ -448,7 +471,6 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
updatedEpisodes.Should().OnlyContain(c => c.Ignored == true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsSeasonIgnored_should_return_true_if_all_episodes_ignored()
|
|
|
|
|
{
|
|
|
|
@ -556,6 +578,112 @@ namespace NzbDrone.Core.Test
|
|
|
|
|
episodes.Should().NotBeEmpty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisode_by_Season_Episode_with_EpisodeFile()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).Build();
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 1).Have(e => e.EpisodeFile = fakeFile).Build();
|
|
|
|
|
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
db.Insert(fakeFile);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetSeries(1))
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, 1, 1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
|
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
|
|
|
|
|
episode.EpisodeFile.Should().NotBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisode_by_Season_Episode_without_EpisodeFile()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 0).Build();
|
|
|
|
|
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetSeries(1))
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, 1, 1);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
|
|
|
|
|
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
|
|
|
|
|
episode.EpisodeFile.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisode_by_AirDate_with_EpisodeFile()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeFile = Builder<EpisodeFile>.CreateNew().With(f => f.EpisodeFileId).Build();
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 1).Have(e => e.EpisodeFile = fakeFile).Build();
|
|
|
|
|
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
db.Insert(fakeFile);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetSeries(1))
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, fakeEpisodes[0].AirDate);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series, e => e.EpisodeFile).EqualTo(fakeEpisodes.First());
|
|
|
|
|
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
|
|
|
|
|
episode.EpisodeFile.Should().NotBeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void GetEpisode_by_AirDate_without_EpisodeFile()
|
|
|
|
|
{
|
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
|
var db = MockLib.GetEmptyDatabase();
|
|
|
|
|
mocker.SetConstant(db);
|
|
|
|
|
|
|
|
|
|
var fakeSeries = Builder<Series>.CreateNew().Build();
|
|
|
|
|
var fakeEpisodes = Builder<Episode>.CreateListOfSize(5)
|
|
|
|
|
.WhereAll().Have(e => e.SeriesId = 1).WhereTheFirst(1).Have(e => e.EpisodeFileId = 0).Build();
|
|
|
|
|
|
|
|
|
|
db.InsertMany(fakeEpisodes);
|
|
|
|
|
|
|
|
|
|
mocker.GetMock<SeriesProvider>()
|
|
|
|
|
.Setup(p => p.GetSeries(1))
|
|
|
|
|
.Returns(fakeSeries);
|
|
|
|
|
|
|
|
|
|
//Act
|
|
|
|
|
var episode = mocker.Resolve<EpisodeProvider>().GetEpisode(1, fakeEpisodes[0].AirDate);
|
|
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
|
episode.ShouldHave().AllPropertiesBut(e => e.Series).EqualTo(fakeEpisodes.First());
|
|
|
|
|
episode.Series.ShouldHave().AllProperties().EqualTo(fakeSeries);
|
|
|
|
|
episode.EpisodeFile.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|