1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-29 02:55:38 +00:00
Lidarr/NzbDrone.Core.Test/ProviderTests/EpisodeProviderTest_GetEpisodesByParseResult.cs

389 lines
14 KiB
C#
Raw Normal View History

2011-06-22 01:12:20 +00:00
// ReSharper disable RedundantUsingDirective
using System;
2011-06-22 01:12:20 +00:00
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
2011-06-22 01:12:20 +00:00
using NUnit.Framework;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common.AutoMoq;
using PetaPoco;
2011-06-22 01:12:20 +00:00
namespace NzbDrone.Core.Test.ProviderTests
2011-06-22 01:12:20 +00:00
{
[TestFixture]
// ReSharper disable InconsistentNaming
2011-11-13 07:27:16 +00:00
public class EpisodeProviderTest_GetEpisodesByParseResult : CoreTest
2011-06-22 01:12:20 +00:00
{
[Test]
public void Single_GetSeason_Episode_Exists()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
2011-06-22 01:12:20 +00:00
var fakeEpisode = Builder<Episode>.CreateNew()
2011-12-01 19:05:17 +00:00
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 10)
.Build();
2011-06-22 01:12:20 +00:00
var fakeSeries = Builder<Series>.CreateNew().Build();
2011-12-01 19:05:17 +00:00
Db.Insert(fakeEpisode);
Db.Insert(fakeSeries);
2011-06-22 01:12:20 +00:00
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 10 }
};
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
ep.Should().HaveCount(1);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
2011-06-22 01:12:20 +00:00
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
}
[Test]
public void Single_GetSeason_Episode_Doesnt_exists_should_not_add()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
2011-06-22 01:12:20 +00:00
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 10 }
};
2011-06-22 01:12:20 +00:00
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
ep.Should().BeEmpty();
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(0);
2011-06-22 01:12:20 +00:00
}
[Test]
public void Single_GetSeason_Episode_Doesnt_exists_should_add()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
2011-06-22 01:12:20 +00:00
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 10 }
};
2011-06-22 01:12:20 +00:00
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult, true);
2011-06-22 01:12:20 +00:00
ep.Should().HaveCount(1);
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(1);
2011-06-22 01:12:20 +00:00
}
[Test]
public void Multi_GetSeason_Episode_Exists()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
2011-06-22 01:12:20 +00:00
var fakeEpisode = Builder<Episode>.CreateNew()
2011-12-01 19:05:17 +00:00
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 10)
.Build();
2011-06-22 01:12:20 +00:00
var fakeEpisode2 = Builder<Episode>.CreateNew()
2011-12-01 19:05:17 +00:00
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 11)
.Build();
2011-06-22 01:12:20 +00:00
var fakeSeries = Builder<Series>.CreateNew().Build();
2011-12-01 19:05:17 +00:00
Db.Insert(fakeEpisode);
Db.Insert(fakeEpisode2);
Db.Insert(fakeSeries);
2011-06-22 01:12:20 +00:00
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 10, 11 }
};
2011-06-22 01:12:20 +00:00
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
ep.Should().HaveCount(2);
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(2);
2011-06-22 01:12:20 +00:00
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
}
[Test]
public void Multi_GetSeason_Episode_Doesnt_exists_should_not_add()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
2011-06-22 01:12:20 +00:00
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 10, 11 }
};
2011-06-22 01:12:20 +00:00
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
2011-06-22 01:12:20 +00:00
ep.Should().BeEmpty();
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(0);
2011-06-22 01:12:20 +00:00
}
[Test]
public void Multi_GetSeason_Episode_Doesnt_exists_should_add()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
2011-06-22 01:12:20 +00:00
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 10, 11 }
};
2011-06-22 01:12:20 +00:00
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult, true);
2011-06-22 01:12:20 +00:00
ep.Should().HaveCount(2);
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(2);
2011-06-22 01:12:20 +00:00
}
[Test]
public void Get_Episode_Zero_Doesnt_Exist_Should_add_ignored()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 0 }
};
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult, true);
ep.Should().HaveCount(1);
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(1);
ep.First().Ignored.Should().BeTrue();
}
[Test]
public void Get_Multi_Episode_Zero_Doesnt_Exist_Should_not_add_ignored()
{
2011-12-01 19:05:17 +00:00
WithRealDb();
var fakeSeries = Builder<Series>.CreateNew().Build();
var parseResult = new EpisodeParseResult
2011-12-01 19:05:17 +00:00
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { 0, 1 }
};
2011-12-01 19:05:17 +00:00
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult, true);
ep.Should().HaveCount(2);
2011-12-01 19:05:17 +00:00
Db.Fetch<Episode>().Should().HaveCount(2);
ep.First().Ignored.Should().BeFalse();
}
[Test]
[Description("GetEpisodeParseResult should return empty list if episode list is null")]
public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_null()
{
//Act
2011-12-01 19:05:17 +00:00
var episodes = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(new EpisodeParseResult());
//Assert
episodes.Should().NotBeNull();
episodes.Should().BeEmpty();
}
[Test]
[Description("GetEpisodeParseResult should return empty list if episode list is empty")]
public void GetEpisodeParseResult_should_return_empty_list_if_episode_list_is_empty()
{
//Act
2011-12-01 19:05:17 +00:00
var episodes =
Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(new EpisodeParseResult { EpisodeNumbers = new List<int>() });
//Assert
episodes.Should().NotBeNull();
episodes.Should().BeEmpty();
}
[Test]
public void GetEpisodeParseResult_should_return_single_episode_when_air_date_is_provided()
{
//Setup
var fakeEpisode = Builder<Episode>.CreateListOfSize(1)
.All()
.With(e => e.AirDate = DateTime.Today)
.Build()
.ToList();
var fakeSeries = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.Build();
2011-12-01 19:05:17 +00:00
Mocker.GetMock<IDatabase>().Setup(
s =>
s.Fetch<Episode, Series, EpisodeFile>(It.IsAny<String>(),
It.IsAny<Object[]>()))
.Returns(fakeEpisode);
//Act
var episodes = Mocker.Resolve<EpisodeProvider>()
2011-12-01 19:05:17 +00:00
.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries },
true);
//Assert
episodes.Should().HaveCount(1);
episodes.First().AirDate.Should().Be(DateTime.Today);
2011-12-01 19:05:17 +00:00
Mocker.GetMock<IDatabase>().Verify(v => v.Insert(It.IsAny<Episode>()), Times.Never());
}
[Test]
public void GetEpisodeParseResult_get_daily_should_add_new_episode()
{
//Setup
2011-12-01 01:10:36 +00:00
WithRealDb();
var fakeSeries = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.Build();
//Act
var episodes = Mocker.Resolve<EpisodeProvider>()
2011-12-01 19:05:17 +00:00
.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries },
true);
//Assert
episodes.Should().HaveCount(1);
episodes.First().AirDate.Should().Be(DateTime.Today);
2011-12-01 01:10:36 +00:00
var episodesInDb = Db.Fetch<Episode>();
episodesInDb.Should().HaveCount(1);
}
2011-12-01 19:05:17 +00:00
[Test]
public void GetEpisodeParseResult_get_daily_should_not_add_new_episode_when_auto_add_is_false()
{
//Setup
WithRealDb();
var fakeSeries = Builder<Series>.CreateNew()
.With(s => s.SeriesId = 1)
.Build();
//Act
var episodes = Mocker.Resolve<EpisodeProvider>()
.GetEpisodesByParseResult(new EpisodeParseResult { AirDate = DateTime.Today, Series = fakeSeries }, false);
//Assert
episodes.Should().BeEmpty();
Db.Fetch<Episode>().Should().BeEmpty();
}
[Test]
public void GetEpisodeParseResult_should_return_multiple_titles_for_multiple_episodes()
{
WithRealDb();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 10)
.With(e => e.Title = "Title1")
.Build();
var fakeEpisode2 = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 11)
.With(e => e.Title = "Title2")
.Build();
var fakeSeries = Builder<Series>.CreateNew().Build();
Db.Insert(fakeEpisode);
Db.Insert(fakeEpisode2);
Db.Insert(fakeSeries);
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber, fakeEpisode2.EpisodeNumber }
};
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
ep.Should().HaveCount(2);
Db.Fetch<Episode>().Should().HaveCount(2);
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title + " + " + fakeEpisode2.Title);
}
[Test]
public void GetEpisodeParseResult_should_return_single_title_for_single_episode()
{
WithRealDb();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(e => e.SeriesId = 1)
.With(e => e.SeasonNumber = 2)
.With(e => e.EpisodeNumber = 10)
.With(e => e.Title = "Title1")
.Build();
var fakeSeries = Builder<Series>.CreateNew().Build();
Db.Insert(fakeEpisode);
Db.Insert(fakeSeries);
var parseResult = new EpisodeParseResult
{
Series = fakeSeries,
SeasonNumber = 2,
EpisodeNumbers = new List<int> { fakeEpisode.EpisodeNumber }
};
var ep = Mocker.Resolve<EpisodeProvider>().GetEpisodesByParseResult(parseResult);
ep.Should().HaveCount(1);
Db.Fetch<Episode>().Should().HaveCount(1);
ep.First().ShouldHave().AllPropertiesBut(e => e.Series);
parseResult.EpisodeTitle.Should().Be(fakeEpisode.Title);
}
2011-06-22 01:12:20 +00:00
}
2011-12-01 19:05:17 +00:00
}