@ -65,11 +65,13 @@ namespace NzbDrone.Core.Test
mocker . GetMock < ConfigProvider > ( )
. Setup ( c = > c . UseSeasonFolder ) . Returns ( useSeasonFolder ) ;
mocker . SetConstant ( MockLib . GetEmptyDatabase ( ) ) ;
var db = MockLib . GetEmptyDatabase ( ) ;
mocker . SetConstant ( db ) ;
var fakeProfiles = Builder < QualityProfile > . CreateListOfSize ( 2 ) . Build ( ) ;
db . InsertMany ( fakeProfiles ) ;
const string path = "C:\\Test\\" ;
const int tvDbId = 1234 ;
const int qualityProfileId = 2 ;
@ -78,8 +80,6 @@ namespace NzbDrone.Core.Test
var seriesProvider = mocker . Resolve < SeriesProvider > ( ) ;
seriesProvider . AddSeries ( path , tvDbId , qualityProfileId ) ;
//Assert
var series = seriesProvider . GetAllSeries ( ) ;
series . Should ( ) . HaveCount ( 1 ) ;
@ -104,7 +104,6 @@ namespace NzbDrone.Core.Test
Assert . IsNull ( series ) ;
}
[Test]
[ExpectedException(typeof(InvalidOperationException), ExpectedMessage = "Sequence contains no elements")]
public void Get_series_invalid_series_id_should_return_null ( )
@ -233,6 +232,7 @@ namespace NzbDrone.Core.Test
. With ( c = > c . SeriesId = 11 )
. Build ( ) ) ;
db . InsertMany ( Builder < QualityProfile > . CreateListOfSize ( 3 ) . Build ( ) ) ;
//Act, Assert
var provider = mocker . Resolve < SeriesProvider > ( ) ;
@ -240,5 +240,134 @@ namespace NzbDrone.Core.Test
Assert . IsFalse ( provider . IsMonitored ( 11 ) ) ;
Assert . IsFalse ( provider . IsMonitored ( 1 ) ) ;
}
[Test]
public void Get_Series_With_Count ( )
{
var mocker = new AutoMoqer ( MockBehavior . Strict ) ;
var db = MockLib . GetEmptyDatabase ( ) ;
mocker . SetConstant ( db ) ;
var fakeQuality = Builder < QualityProfile > . CreateNew ( ) . Build ( ) ;
var fakeSeries = Builder < Series > . CreateNew ( ) . With ( e = > e . QualityProfileId = fakeQuality . QualityProfileId ) . Build ( ) ;
var fakeEpisodes = Builder < Episode > . CreateListOfSize ( 10 ) . WhereAll ( ) . Have ( e = > e . SeriesId = fakeSeries . SeriesId ) . Have ( e = > e . Ignored = false ) . WhereRandom ( 5 ) . Have ( e = > e . EpisodeFileId = 0 ) . Build ( ) ;
db . Insert ( fakeSeries ) ;
db . Insert ( fakeQuality ) ;
db . InsertMany ( fakeEpisodes ) ;
//Act
mocker . Resolve < QualityProvider > ( ) ;
var series = mocker . Resolve < SeriesProvider > ( ) . GetAllSeriesWithEpisodeCount ( true ) ;
//Assert
series . Should ( ) . HaveCount ( 1 ) ;
Assert . AreEqual ( 10 , series [ 0 ] . EpisodeCount ) ;
Assert . AreEqual ( 5 , series [ 0 ] . EpisodeFileCount ) ;
}
[Test]
public void Get_Series_With_Count_AllIgnored ( )
{
var mocker = new AutoMoqer ( MockBehavior . Strict ) ;
var db = MockLib . GetEmptyDatabase ( ) ;
mocker . SetConstant ( db ) ;
var fakeQuality = Builder < QualityProfile > . CreateNew ( ) . Build ( ) ;
var fakeSeries = Builder < Series > . CreateNew ( ) . With ( e = > e . QualityProfileId = fakeQuality . QualityProfileId ) . Build ( ) ;
var fakeEpisodes = Builder < Episode > . CreateListOfSize ( 10 ) . WhereAll ( ) . Have ( e = > e . SeriesId = fakeSeries . SeriesId ) . Have ( e = > e . Ignored = true ) . WhereRandom ( 5 ) . Have ( e = > e . EpisodeFileId = 0 ) . Build ( ) ;
db . Insert ( fakeSeries ) ;
db . Insert ( fakeQuality ) ;
db . InsertMany ( fakeEpisodes ) ;
//Act
mocker . Resolve < QualityProvider > ( ) ;
var series = mocker . Resolve < SeriesProvider > ( ) . GetAllSeriesWithEpisodeCount ( true ) ;
//Assert
series . Should ( ) . HaveCount ( 1 ) ;
Assert . AreEqual ( 0 , series [ 0 ] . EpisodeCount ) ;
Assert . AreEqual ( 0 , series [ 0 ] . EpisodeFileCount ) ;
}
[Test]
public void Get_Series_With_Count_AllDownloaded ( )
{
var mocker = new AutoMoqer ( MockBehavior . Strict ) ;
var db = MockLib . GetEmptyDatabase ( ) ;
mocker . SetConstant ( db ) ;
var fakeQuality = Builder < QualityProfile > . CreateNew ( ) . Build ( ) ;
var fakeSeries = Builder < Series > . CreateNew ( ) . With ( e = > e . QualityProfileId = fakeQuality . QualityProfileId ) . Build ( ) ;
var fakeEpisodes = Builder < Episode > . CreateListOfSize ( 10 ) . WhereAll ( ) . Have ( e = > e . SeriesId = fakeSeries . SeriesId ) . Have ( e = > e . Ignored = false ) . Build ( ) ;
db . Insert ( fakeSeries ) ;
db . Insert ( fakeQuality ) ;
db . InsertMany ( fakeEpisodes ) ;
//Act
mocker . Resolve < QualityProvider > ( ) ;
var series = mocker . Resolve < SeriesProvider > ( ) . GetAllSeriesWithEpisodeCount ( true ) ;
//Assert
series . Should ( ) . HaveCount ( 1 ) ;
Assert . AreEqual ( 10 , series [ 0 ] . EpisodeCount ) ;
Assert . AreEqual ( 10 , series [ 0 ] . EpisodeFileCount ) ;
}
[Test]
public void Get_Series_With_Count_Half_Ignored ( )
{
var mocker = new AutoMoqer ( MockBehavior . Strict ) ;
var db = MockLib . GetEmptyDatabase ( ) ;
mocker . SetConstant ( db ) ;
var fakeQuality = Builder < QualityProfile > . CreateNew ( ) . Build ( ) ;
var fakeSeries = Builder < Series > . CreateNew ( ) . With ( e = > e . QualityProfileId = fakeQuality . QualityProfileId ) . Build ( ) ;
var fakeEpisodes = Builder < Episode > . CreateListOfSize ( 10 )
. WhereAll ( ) . Have ( e = > e . SeriesId = fakeSeries . SeriesId )
. WhereTheFirst ( 5 ) . Have ( e = > e . Ignored = false )
. WhereTheLast ( 5 ) . Have ( e = > e . Ignored = true )
. Build ( ) ;
db . Insert ( fakeSeries ) ;
db . Insert ( fakeQuality ) ;
db . InsertMany ( fakeEpisodes ) ;
//Act
mocker . Resolve < QualityProvider > ( ) ;
var series = mocker . Resolve < SeriesProvider > ( ) . GetAllSeriesWithEpisodeCount ( true ) ;
//Assert
series . Should ( ) . HaveCount ( 1 ) ;
Assert . AreEqual ( 5 , series [ 0 ] . EpisodeCount ) ;
Assert . AreEqual ( 5 , series [ 0 ] . EpisodeFileCount ) ;
}
[Test]
public void Get_Single_Series ( )
{
var mocker = new AutoMoqer ( MockBehavior . Strict ) ;
var db = MockLib . GetEmptyDatabase ( ) ;
mocker . SetConstant ( db ) ;
var fakeQuality = Builder < QualityProfile > . CreateNew ( ) . Build ( ) ;
var fakeSeries = Builder < Series > . CreateNew ( )
. With ( e = > e . QualityProfileId = fakeQuality . QualityProfileId )
. With ( e = > e . SeriesId = 1 )
. Build ( ) ;
db . Insert ( fakeSeries ) ;
db . Insert ( fakeQuality ) ;
//Act
mocker . Resolve < QualityProvider > ( ) ;
var series = mocker . Resolve < SeriesProvider > ( ) . GetSeries ( 1 ) ;
//Assert
series . QualityProfile . Should ( ) . NotBeNull ( ) ;
series . QualityProfileId . Should ( ) . Be ( fakeQuality . QualityProfileId ) ;
}
}
}