@ -1,6 +1,7 @@
// ReSharper disable RedundantUsingDirective
// ReSharper disable RedundantUsingDirective
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Linq ;
using AutoMoq ;
using AutoMoq ;
using FizzWare.NBuilder ;
using FizzWare.NBuilder ;
using FluentAssertions ;
using FluentAssertions ;
@ -15,50 +16,27 @@ namespace NzbDrone.Core.Test
// ReSharper disable InconsistentNaming
// ReSharper disable InconsistentNaming
public class UpcomingEpisodesProviderTest : TestBase
public class UpcomingEpisodesProviderTest : TestBase
{
{
private Episode yesterday ;
private IList < Episode > episodes ;
private Episode today ;
private Episode tomorrow ;
private Episode twoDays ;
private Episode sevenDays ;
private Series series ;
private Series series ;
[SetUp]
[SetUp]
public new void Setup ( )
public new void Setup ( )
{
{
yesterday = Builder < Episode > . CreateNew ( )
episodes = Builder < Episode > . CreateListOfSize ( 6 )
. With ( c = > c . AirDate = DateTime . Today . AddDays ( - 1 ) )
. WhereAll ( )
. With ( c = > c . Title = "Yesterday" )
. Have ( e = > e . SeriesId = 1 )
. With ( c = > c . SeriesId = 1 )
. WhereTheFirst ( 1 )
. Build ( ) ;
. Has ( e = > e . AirDate = DateTime . Today . AddDays ( - 1 ) )
. AndTheNext ( 1 )
today = Builder < Episode > . CreateNew ( )
. Has ( e = > e . AirDate = DateTime . Today )
. With ( c = > c . AirDate = DateTime . Today )
. AndTheNext ( 1 )
. With ( c = > c . Title = "Today" )
. Has ( e = > e . AirDate = DateTime . Today . AddDays ( 1 ) )
. With ( c = > c . SeriesId = 1 )
. AndTheNext ( 1 )
. Build ( ) ;
. Has ( e = > e . AirDate = DateTime . Today . AddDays ( 2 ) )
. AndTheNext ( 1 )
tomorrow = Builder < Episode > . CreateNew ( )
. Has ( e = > e . AirDate = DateTime . Today . AddDays ( 7 ) )
. With ( c = > c . AirDate = DateTime . Today . AddDays ( 1 ) )
. AndTheNext ( 1 )
. With ( c = > c . Title = "Tomorrow" )
. Has ( e = > e . AirDate = DateTime . Today . AddDays ( 9 ) )
. With ( c = > c . SeriesId = 1 )
. Build ( ) ;
twoDays = Builder < Episode > . CreateNew ( )
. With ( c = > c . AirDate = DateTime . Today . AddDays ( 2 ) )
. With ( c = > c . Title = "Two Days" )
. With ( c = > c . SeriesId = 1 )
. Build ( ) ;
sevenDays = Builder < Episode > . CreateNew ( )
. With ( c = > c . AirDate = DateTime . Today . AddDays ( 7 ) )
. With ( c = > c . Title = "Seven Days" )
. With ( c = > c . SeriesId = 1 )
. Build ( ) ;
sevenDays = Builder < Episode > . CreateNew ( )
. With ( c = > c . AirDate = DateTime . Today . AddDays ( 8 ) )
. With ( c = > c . Title = "Eight Days" )
. With ( c = > c . SeriesId = 1 )
. Build ( ) ;
. Build ( ) ;
series = Builder < Series > . CreateNew ( ) . With ( s = > s . SeriesId = 1 ) . Build ( ) ;
series = Builder < Series > . CreateNew ( ) . With ( s = > s . SeriesId = 1 ) . Build ( ) ;
@ -74,21 +52,17 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer ( ) ;
var mocker = new AutoMoqer ( ) ;
mocker . SetConstant ( database ) ;
mocker . SetConstant ( database ) ;
database . Insert ( yesterday ) ;
database . InsertMany ( episodes ) ;
database . Insert ( today ) ;
database . Insert ( tomorrow ) ;
database . Insert ( twoDays ) ;
database . Insert ( sevenDays ) ;
database . Insert ( series ) ;
database . Insert ( series ) ;
//Act
//Act
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Yesterday ( ) ;
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Yesterday ( ) ;
//Assert
//Assert
Assert. AreEqual ( 1 , result . Count ) ;
result. Should ( ) . HaveCount ( 1 ) ;
Assert. AreEqual ( yesterday . Title , result [ 0 ] . Title ) ;
result. First ( ) . Title . Should ( ) . Be ( episodes . Where ( e = > e . AirDate = = DateTime . Today . AddDays ( - 1 ) ) . First ( ) . Title ) ;
result [0 ] . Series . Should ( ) . NotBeNull ( ) ;
result .First ( ) . Series . Should ( ) . NotBeNull ( ) ;
result [0 ] . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
result .First ( ) . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
}
}
[Test]
[Test]
@ -99,21 +73,17 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer ( ) ;
var mocker = new AutoMoqer ( ) ;
mocker . SetConstant ( database ) ;
mocker . SetConstant ( database ) ;
database . Insert ( yesterday ) ;
database . InsertMany ( episodes ) ;
database . Insert ( today ) ;
database . Insert ( tomorrow ) ;
database . Insert ( twoDays ) ;
database . Insert ( sevenDays ) ;
database . Insert ( series ) ;
database . Insert ( series ) ;
//Act
//Act
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Today ( ) ;
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Today ( ) ;
//Assert
//Assert
Assert. AreEqual ( 1 , result . Count ) ;
result. Should ( ) . HaveCount ( 1 ) ;
Assert. AreEqual ( today . Title , result [ 0 ] . Title ) ;
result. First ( ) . Title . Should ( ) . Be ( episodes . Where ( e = > e . AirDate = = DateTime . Today ) . First ( ) . Title ) ;
result [0 ] . Series . Should ( ) . NotBeNull ( ) ;
result .First ( ) . Series . Should ( ) . NotBeNull ( ) ;
result [0 ] . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
result .First ( ) . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
}
}
[Test]
[Test]
@ -124,21 +94,17 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer ( ) ;
var mocker = new AutoMoqer ( ) ;
mocker . SetConstant ( database ) ;
mocker . SetConstant ( database ) ;
database . Insert ( yesterday ) ;
database . InsertMany ( episodes ) ;
database . Insert ( today ) ;
database . Insert ( tomorrow ) ;
database . Insert ( twoDays ) ;
database . Insert ( sevenDays ) ;
database . Insert ( series ) ;
database . Insert ( series ) ;
//Act
//Act
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Tomorrow ( ) ;
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Tomorrow ( ) ;
//Assert
//Assert
Assert. AreEqual ( 1 , result . Count ) ;
result. Should ( ) . HaveCount ( 1 ) ;
Assert. AreEqual ( tomorrow . Title , result [ 0 ] . Title ) ;
result. First ( ) . Title . Should ( ) . Be ( episodes . Where ( e = > e . AirDate = = DateTime . Today . AddDays ( 1 ) ) . First ( ) . Title ) ;
result [0 ] . Series . Should ( ) . NotBeNull ( ) ;
result .First ( ) . Series . Should ( ) . NotBeNull ( ) ;
result [0 ] . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
result .First ( ) . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
}
}
[Test]
[Test]
@ -149,22 +115,18 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer ( ) ;
var mocker = new AutoMoqer ( ) ;
mocker . SetConstant ( database ) ;
mocker . SetConstant ( database ) ;
database . Insert ( yesterday ) ;
database . InsertMany ( episodes ) ;
database . Insert ( today ) ;
database . Insert ( tomorrow ) ;
database . Insert ( twoDays ) ;
database . Insert ( sevenDays ) ;
database . Insert ( series ) ;
database . Insert ( series ) ;
//Act
//Act
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Week ( ) ;
var result = mocker . Resolve < UpcomingEpisodesProvider > ( ) . Week ( ) ;
//Assert
//Assert
Assert. AreEqual ( 2 , result . Count ) ;
result. Should ( ) . HaveCount ( 2 ) ;
result [0 ] . Series . Should ( ) . NotBeNull ( ) ;
result .First ( ) . Series . Should ( ) . NotBeNull ( ) ;
result [0 ] . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
result .First ( ) . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
result [1 ] . Series . Should ( ) . NotBeNull ( ) ;
result .Last ( ) . Series . Should ( ) . NotBeNull ( ) ;
result [1 ] . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
result .Last ( ) . Series . SeriesId . Should ( ) . NotBe ( 0 ) ;
}
}
}
}
}
}