2012-02-12 00:02:36 +00:00
|
|
|
// ReSharper disable InconsistentNaming
|
2011-06-17 23:01:09 +00:00
|
|
|
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 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;
|
|
|
|
|
2011-10-20 23:42:17 +00:00
|
|
|
namespace NzbDrone.Core.Test.ProviderTests
|
2011-06-17 23:01:09 +00:00
|
|
|
{
|
|
|
|
[TestFixture]
|
2012-02-12 00:02:36 +00:00
|
|
|
|
2011-11-13 07:27:16 +00:00
|
|
|
public class UpcomingEpisodesProviderTest : CoreTest
|
2011-06-17 23:01:09 +00:00
|
|
|
{
|
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]
|
2011-10-24 05:54:09 +00:00
|
|
|
public void Setup()
|
2011-06-17 23:01:09 +00:00
|
|
|
{
|
2012-02-12 00:02:36 +00:00
|
|
|
WithRealDb();
|
|
|
|
|
2011-09-29 00:20:29 +00:00
|
|
|
episodes = Builder<Episode>.CreateListOfSize(6)
|
2011-10-18 21:46:06 +00:00
|
|
|
.All()
|
|
|
|
.With(e => e.SeriesId = 1)
|
|
|
|
.With(e => e.Ignored = false)
|
|
|
|
.TheFirst(1)
|
2011-10-23 05:39:14 +00: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))
|
2011-06-17 23:01:09 +00:00
|
|
|
.Build();
|
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
series = Builder<Series>.CreateNew()
|
|
|
|
.With(s => s.SeriesId = 1)
|
|
|
|
.And(c => c.Monitored = true)
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
|
|
Db.InsertMany(episodes);
|
|
|
|
Db.Insert(series);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
private void WithIgnoredEpisodes()
|
2011-06-17 23:01:09 +00:00
|
|
|
{
|
2012-02-12 00:02:36 +00:00
|
|
|
episodes.ToList().ForEach(c => c.Ignored = true);
|
|
|
|
Db.UpdateMany(episodes);
|
|
|
|
}
|
2011-06-17 23:01:09 +00:00
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
private void WithIgnoredSeries()
|
|
|
|
{
|
|
|
|
series.Monitored = false;
|
|
|
|
Db.Update(series);
|
|
|
|
}
|
2011-06-17 23:01:09 +00:00
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
[Test]
|
|
|
|
public void Get_Yesterday()
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
|
2011-06-17 23:01:09 +00:00
|
|
|
|
|
|
|
//Assert
|
2012-02-12 00:02:36 +00:00
|
|
|
result.Should().NotBeEmpty();
|
|
|
|
result.Should().OnlyContain(c => c.AirDate.Value.Date == DateTime.Today.AddDays(-1).Date);
|
2011-09-29 00:20:29 +00:00
|
|
|
result.First().Series.Should().NotBeNull();
|
2012-02-12 00:02:36 +00:00
|
|
|
result.First().Series.SeriesId.Should().Be(series.SeriesId);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Today()
|
|
|
|
{
|
|
|
|
//Act
|
2011-12-15 04:15:53 +00:00
|
|
|
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Today();
|
2011-06-17 23:01:09 +00:00
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
result.Should().NotBeEmpty();
|
|
|
|
result.Should().OnlyContain(c => c.AirDate.Value.Date == DateTime.Today.Date);
|
2011-09-29 00:20:29 +00:00
|
|
|
result.First().Series.Should().NotBeNull();
|
2012-02-12 00:02:36 +00:00
|
|
|
result.First().Series.SeriesId.Should().Be(series.SeriesId);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Tomorrow()
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
|
2011-06-17 23:01:09 +00:00
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
result.Should().NotBeEmpty();
|
|
|
|
result.Should().OnlyContain(c => c.AirDate.Value.Date == DateTime.Today.AddDays(1).Date);
|
2011-09-29 00:20:29 +00:00
|
|
|
result.First().Series.Should().NotBeNull();
|
2012-02-12 00:02:36 +00:00
|
|
|
result.First().Series.SeriesId.Should().Be(series.SeriesId);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Get_Week()
|
|
|
|
{
|
2011-12-15 04:15:53 +00:00
|
|
|
var result = Mocker.Resolve<UpcomingEpisodesProvider>().Week();
|
2011-06-17 23:01:09 +00:00
|
|
|
|
|
|
|
//Assert
|
2011-09-29 00:20:29 +00:00
|
|
|
result.Should().HaveCount(2);
|
2012-02-12 00:02:36 +00:00
|
|
|
result.Should().OnlyContain(c => c.Series != null && c.SeriesId == series.SeriesId);
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
2011-10-03 23:53:21 +00:00
|
|
|
|
|
|
|
[Test]
|
2012-02-12 00:02:36 +00:00
|
|
|
public void Get_Yesterday_should_skip_ingored()
|
2011-10-03 23:53:21 +00:00
|
|
|
{
|
2012-02-12 00:02:36 +00:00
|
|
|
WithIgnoredEpisodes();
|
|
|
|
Mocker.Resolve<UpcomingEpisodesProvider>().Yesterday().Should().BeEmpty();
|
2011-10-03 23:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-02-12 00:02:36 +00:00
|
|
|
public void Get_Today_should_skip_ingored()
|
2011-10-03 23:53:21 +00:00
|
|
|
{
|
2012-02-12 00:02:36 +00:00
|
|
|
WithIgnoredEpisodes();
|
|
|
|
Mocker.Resolve<UpcomingEpisodesProvider>().Today().Should().BeEmpty();
|
2011-10-03 23:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-02-12 00:02:36 +00:00
|
|
|
public void Get_Tomorrow_should_skip_ingored()
|
2011-10-03 23:53:21 +00:00
|
|
|
{
|
2012-02-12 00:02:36 +00:00
|
|
|
WithIgnoredEpisodes();
|
|
|
|
Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow().Should().BeEmpty();
|
2011-10-03 23:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2012-02-12 00:02:36 +00:00
|
|
|
public void Get_Week_should_skip_ingored()
|
2011-10-03 23:53:21 +00:00
|
|
|
{
|
2012-02-12 00:02:36 +00:00
|
|
|
WithIgnoredEpisodes();
|
|
|
|
Mocker.Resolve<UpcomingEpisodesProvider>().Week().Should().BeEmpty();
|
|
|
|
}
|
2011-10-03 23:53:21 +00:00
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
[Test]
|
|
|
|
public void Get_Today_should_skip_unmonitored_series()
|
|
|
|
{
|
|
|
|
WithIgnoredSeries();
|
|
|
|
Mocker.Resolve<UpcomingEpisodesProvider>().Today().Should().BeEmpty();
|
|
|
|
}
|
2011-10-03 23:53:21 +00:00
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
[Test]
|
|
|
|
public void Get_Tomoroww_should_skip_unmonitored_series()
|
|
|
|
{
|
|
|
|
WithIgnoredSeries();
|
|
|
|
Mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow().Should().BeEmpty();
|
|
|
|
}
|
2011-10-03 23:53:21 +00:00
|
|
|
|
2012-02-12 00:02:36 +00:00
|
|
|
[Test]
|
|
|
|
public void Get_Week_should_skip_unmonitored_series()
|
|
|
|
{
|
|
|
|
WithIgnoredSeries();
|
|
|
|
Mocker.Resolve<UpcomingEpisodesProvider>().Week().Should().BeEmpty();
|
2011-10-03 23:53:21 +00:00
|
|
|
}
|
2011-06-17 23:01:09 +00:00
|
|
|
}
|
|
|
|
}
|