1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 23:42:33 +01:00
Sonarr/NzbDrone.Core.Test/ProviderTests/UpcomingEpisodesProviderTest.cs

216 lines
6.4 KiB
C#
Raw Normal View History

// ReSharper disable RedundantUsingDirective
using System;
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
{
[TestFixture]
// ReSharper disable InconsistentNaming
2011-11-13 08:27:16 +01:00
public class UpcomingEpisodesProviderTest : CoreTest
{
private IList<Episode> episodes;
private Series series;
[SetUp]
2011-10-24 07:54:09 +02:00
public void Setup()
{
episodes = Builder<Episode>.CreateListOfSize(6)
2011-10-18 23:46:06 +02:00
.All()
.With(e => e.SeriesId = 1)
.With(e => e.Ignored = false)
.TheFirst(1)
2011-10-23 07:39:14 +02:00
.With(e => e.AirDate = DateTime.Today.AddDays(-1))
.TheNext(1)
.With(e => e.AirDate = DateTime.Today)
.TheNext(1)
.With(e => e.AirDate = DateTime.Today.AddDays(1))
.TheNext(1)
.With(e => e.AirDate = DateTime.Today.AddDays(2))
.TheNext(1)
.With(e => e.AirDate = DateTime.Today.AddDays(7))
.TheNext(1)
.With(e => e.AirDate = DateTime.Today.AddDays(9))
.Build();
series = Builder<Series>.CreateNew().With(s => s.SeriesId = 1).Build();
}
[Test]
public void Get_Yesterday()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert
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);
}
[Test]
public void Get_Today()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert
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);
}
[Test]
public void Get_Tomorrow()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert
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);
}
[Test]
public void Get_Week()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//Assert
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);
}
[Test]
public void Get_Yesterday_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).Single().Ignored = true;
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
//Assert
result.Should().BeEmpty();
}
[Test]
public void Get_Today_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today).Single().Ignored = true;
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
//Assert
result.Should().BeEmpty();
}
[Test]
public void Get_Tomorrow_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(1)).Single().Ignored = true;
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
//Assert
result.Should().BeEmpty();
}
[Test]
public void Get_Week_skip_ingored()
{
//Setup
var database = TestDbHelper.GetEmptyDatabase();
2011-12-15 05:15:53 +01:00
Mocker.SetConstant(database);
episodes.Where(e => e.AirDate == DateTime.Today.AddDays(2)).Single().Ignored = true;
database.InsertMany(episodes);
database.Insert(series);
//Act
2011-12-15 05:15:53 +01:00
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
//Assert
result.Should().HaveCount(1);
result.First().Series.Should().NotBeNull();
result.First().Series.SeriesId.Should().NotBe(0);
}
}
}