SeasonPass now properly updates episodes

This commit is contained in:
Mark McDowall 2013-08-06 18:25:06 -07:00
parent 9fcd91f2c5
commit 55af8ecb18
5 changed files with 147 additions and 0 deletions

View File

@ -181,6 +181,8 @@
<Compile Include="ProviderTests\DiskProviderTests\ArchiveProviderFixture.cs" />
<Compile Include="MediaFileTests\DropFolderImportServiceFixture.cs" />
<Compile Include="SeriesStatsTests\SeriesStatisticsFixture.cs" />
<Compile Include="TvTests\SeasonServiceTests\SetSeasonPassFixture.cs" />
<Compile Include="TvTests\SeasonServiceTests\SetMonitoredFixture.cs" />
<Compile Include="TvTests\SeriesRepositoryTests\QualityProfileRepositoryFixture.cs" />
<Compile Include="UpdateTests\UpdateServiceFixture.cs" />
<Compile Include="ProviderTests\XemCommunicationProviderTests\GetSceneTvdbMappingsFixture.cs" />

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.TvTests.SeasonServiceTests
{
[TestFixture]
public class SetMonitoredFixture : CoreTest<SeasonService>
{
private Season _season;
[SetUp]
public void Setup()
{
_season = new Season
{
Id = 1,
SeasonNumber = 1,
SeriesId = 1,
Monitored = false
};
Mocker.GetMock<ISeasonRepository>()
.Setup(s => s.Get(It.IsAny<Int32>(), It.IsAny<Int32>()))
.Returns(_season);
}
[TestCase(true)]
[TestCase(false)]
public void should_update_season(bool monitored)
{
Subject.SetMonitored(_season.SeriesId, _season.SeasonNumber, monitored);
Mocker.GetMock<ISeasonRepository>()
.Verify(v => v.Update(_season), Times.Once());
}
[TestCase(true)]
[TestCase(false)]
public void should_update_episodes_in_season(bool monitored)
{
Subject.SetMonitored(_season.SeriesId, _season.SeasonNumber, monitored);
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(_season.SeriesId, _season.SeasonNumber, monitored), Times.Once());
}
}
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv;
namespace NzbDrone.Core.Test.TvTests.SeasonServiceTests
{
[TestFixture]
public class SetSeasonPassFixture : CoreTest<SeasonService>
{
private const Int32 SERIES_ID = 1;
private List<Season> _seasons;
[SetUp]
public void Setup()
{
_seasons = Builder<Season>.CreateListOfSize(5)
.All()
.With(s => s.SeriesId = SERIES_ID)
.Build()
.ToList();
Mocker.GetMock<ISeasonRepository>()
.Setup(s => s.GetSeasonBySeries(It.IsAny<Int32>()))
.Returns(_seasons);
}
[Test]
public void should_updateMany()
{
Subject.SetSeasonPass(SERIES_ID, 1);
Mocker.GetMock<ISeasonRepository>()
.Verify(v => v.UpdateMany(It.IsAny<List<Season>>()), Times.Once());
}
[Test]
public void should_set_lower_seasons_to_false()
{
const int seasonNumber = 3;
var result = Subject.SetSeasonPass(SERIES_ID, seasonNumber);
result.Where(s => s.SeasonNumber < seasonNumber).Should().OnlyContain(s => s.Monitored == false);
}
[Test]
public void should_set_equal_or_higher_seasons_to_false()
{
const int seasonNumber = 3;
var result = Subject.SetSeasonPass(SERIES_ID, seasonNumber);
result.Where(s => s.SeasonNumber >= seasonNumber).Should().OnlyContain(s => s.Monitored == true);
}
[Test]
public void should_set_episodes_in_lower_seasons_to_false()
{
const int seasonNumber = 3;
Subject.SetSeasonPass(SERIES_ID, seasonNumber);
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(SERIES_ID, It.Is<Int32>(i => i < seasonNumber), false), Times.AtLeastOnce());
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(SERIES_ID, It.Is<Int32>(i => i < seasonNumber), true), Times.Never());
}
[Test]
public void should_set_episodes_in_equal_or_higher_seasons_to_false()
{
const int seasonNumber = 3;
Subject.SetSeasonPass(SERIES_ID, seasonNumber);
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(SERIES_ID, It.Is<Int32>(i => i >= seasonNumber), true), Times.AtLeastOnce());
Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(SERIES_ID, It.Is<Int32>(i => i >= seasonNumber), false), Times.Never());
}
}
}

View File

@ -31,6 +31,7 @@ namespace NzbDrone.Core.Tv
void InsertMany(List<Episode> episodes);
void UpdateMany(List<Episode> episodes);
void DeleteMany(List<Episode> episodes);
void SetEpisodeMonitoredBySeason(int seriesId, int seasonNumber, bool monitored);
}
public class EpisodeService : IEpisodeService,

Binary file not shown.