2011-06-17 23:01:09 +00:00
|
|
|
// ReSharper disable RedundantUsingDirective
|
|
|
|
using System;
|
2011-06-20 03:21:54 +00:00
|
|
|
using System.Collections.Generic;
|
2011-09-29 00:20:29 +00:00
|
|
|
using System.Linq;
|
2011-06-17 23:01:09 +00:00
|
|
|
using AutoMoq;
|
|
|
|
using FizzWare.NBuilder;
|
2011-06-20 03:21:54 +00:00
|
|
|
using FluentAssertions;
|
2011-06-17 23:01:09 +00:00
|
|
|
using NUnit.Framework;
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
public class UpcomingEpisodesProviderTest : TestBase
|
|
|
|
{
|
2011-09-29 00:20:29 +00:00
|
|
|
private IList<Episode> episodes;
|
2011-06-20 03:21:54 +00:00
|
|
|
private Series series;
|
2011-06-17 23:01:09 +00:00
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public new void Setup()
|
|
|
|
{
|
2011-09-29 00:20:29 +00:00
|
|
|
episodes = Builder<Episode>.CreateListOfSize(6)
|
|
|
|
.WhereAll()
|
|
|
|
.Have(e => e.SeriesId = 1)
|
2011-10-03 23:53:21 +00:00
|
|
|
.Have(e => e.Ignored = false)
|
2011-09-29 00:20:29 +00:00
|
|
|
.WhereTheFirst(1)
|
|
|
|
.Has(e => e.AirDate = DateTime.Today.AddDays(-1))
|
|
|
|
.AndTheNext(1)
|
|
|
|
.Has(e => e.AirDate = DateTime.Today)
|
|
|
|
.AndTheNext(1)
|
|
|
|
.Has(e => e.AirDate = DateTime.Today.AddDays(1))
|
|
|
|
.AndTheNext(1)
|
|
|
|
.Has(e => e.AirDate = DateTime.Today.AddDays(2))
|
|
|
|
.AndTheNext(1)
|
|
|
|
.Has(e => e.AirDate = DateTime.Today.AddDays(7))
|
|
|
|
.AndTheNext(1)
|
|
|
|
.Has(e => e.AirDate = DateTime.Today.AddDays(9))
|
2011-06-17 23:01:09 +00:00
|
|
|
.Build();
|
|
|
|
|
2011-06-20 03:21:54 +00:00
|
|
|
series = Builder<Series>.CreateNew().With(s => s.SeriesId = 1).Build();
|
|
|
|
|
2011-06-17 23:01:09 +00:00
|
|
|
base.Setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Yesterday()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
2011-09-29 00:20:29 +00:00
|
|
|
database.InsertMany(episodes);
|
2011-06-20 03:21:54 +00:00
|
|
|
database.Insert(series);
|
2011-06-17 23:01:09 +00:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
|
|
|
|
|
|
|
|
//Assert
|
2011-09-29 00:20:29 +00:00
|
|
|
result.Should().HaveCount(1);
|
|
|
|
result.First().Title.Should().Be(episodes.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).First().Title);
|
|
|
|
result.First().Series.Should().NotBeNull();
|
|
|
|
result.First().Series.SeriesId.Should().NotBe(0);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Today()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
2011-09-29 00:20:29 +00:00
|
|
|
database.InsertMany(episodes);
|
2011-06-20 03:21:54 +00:00
|
|
|
database.Insert(series);
|
2011-06-17 23:01:09 +00:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Today();
|
|
|
|
|
|
|
|
//Assert
|
2011-09-29 00:20:29 +00:00
|
|
|
result.Should().HaveCount(1);
|
|
|
|
result.First().Title.Should().Be(episodes.Where(e => e.AirDate == DateTime.Today).First().Title);
|
|
|
|
result.First().Series.Should().NotBeNull();
|
|
|
|
result.First().Series.SeriesId.Should().NotBe(0);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Tomorrow()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
2011-09-29 00:20:29 +00:00
|
|
|
database.InsertMany(episodes);
|
2011-06-20 03:21:54 +00:00
|
|
|
database.Insert(series);
|
2011-06-17 23:01:09 +00:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
|
|
|
|
|
|
|
|
//Assert
|
2011-09-29 00:20:29 +00:00
|
|
|
result.Should().HaveCount(1);
|
|
|
|
result.First().Title.Should().Be(episodes.Where(e => e.AirDate == DateTime.Today.AddDays(1)).First().Title);
|
|
|
|
result.First().Series.Should().NotBeNull();
|
|
|
|
result.First().Series.SeriesId.Should().NotBe(0);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Week()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
2011-09-29 00:20:29 +00:00
|
|
|
database.InsertMany(episodes);
|
2011-06-20 03:21:54 +00:00
|
|
|
database.Insert(series);
|
2011-06-17 23:01:09 +00:00
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Week();
|
|
|
|
|
|
|
|
//Assert
|
2011-09-29 00:20:29 +00:00
|
|
|
result.Should().HaveCount(2);
|
|
|
|
result.First().Series.Should().NotBeNull();
|
|
|
|
result.First().Series.SeriesId.Should().NotBe(0);
|
|
|
|
result.Last().Series.Should().NotBeNull();
|
|
|
|
result.Last().Series.SeriesId.Should().NotBe(0);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
2011-10-03 23:53:21 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Yesterday_skip_ingored()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
|
|
|
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).Single().Ignored = true;
|
|
|
|
|
|
|
|
database.InsertMany(episodes);
|
|
|
|
database.Insert(series);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Today_skip_ingored()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
|
|
|
episodes.Where(e => e.AirDate == DateTime.Today).Single().Ignored = true;
|
|
|
|
|
|
|
|
database.InsertMany(episodes);
|
|
|
|
database.Insert(series);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Today();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Tomorrow_skip_ingored()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
|
|
|
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(1)).Single().Ignored = true;
|
|
|
|
|
|
|
|
database.InsertMany(episodes);
|
|
|
|
database.Insert(series);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().BeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Week_skip_ingored()
|
|
|
|
{
|
|
|
|
//Setup
|
|
|
|
var database = MockLib.GetEmptyDatabase();
|
|
|
|
var mocker = new AutoMoqer();
|
|
|
|
mocker.SetConstant(database);
|
|
|
|
|
|
|
|
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(2)).Single().Ignored = true;
|
|
|
|
|
|
|
|
database.InsertMany(episodes);
|
|
|
|
database.Insert(series);
|
|
|
|
|
|
|
|
//Act
|
|
|
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Week();
|
|
|
|
|
|
|
|
//Assert
|
|
|
|
result.Should().HaveCount(1);
|
|
|
|
result.First().Series.Should().NotBeNull();
|
|
|
|
result.First().Series.SeriesId.Should().NotBe(0);
|
|
|
|
}
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
}
|