Fix .gitattributes and normalize to LF in repository

Existing `*text eol=lf` is malformed (no space after *) so does
nothing.

CONTRIBUTING.md states 'We checkout Windows and commit *nix'.  The
correct way to achieve this is `* text=auto`. `* text eol=lf` would
force line endings to LF on checkout.

See:
https://git-scm.com/docs/gitattributes#Documentation/gitattributes.txt-Settostringvaluelf
pull/3357/head
ta264 5 years ago committed by Taloth
parent 8a2a41fab0
commit 7b68ce49d5

8
.gitattributes vendored

@ -1,5 +1,11 @@
# Auto detect text files and perform LF normalization # Auto detect text files and perform LF normalization
*text eol=lf * text=auto
# Explicitly set bash scripts to have unix endings
# when checked out on windows
*.sh text eol=lf
distribution/debian/* text eol=lf
macOS/Sonarr text eol=lf
# Custom for Visual Studio # Custom for Visual Studio
*.cs diff=csharp *.cs diff=csharp

@ -1,398 +1,398 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.MetadataSource.SkyHook; using NzbDrone.Core.MetadataSource.SkyHook;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.TvTests namespace NzbDrone.Core.Test.TvTests
{ {
[TestFixture] [TestFixture]
public class RefreshEpisodeServiceFixture : CoreTest<RefreshEpisodeService> public class RefreshEpisodeServiceFixture : CoreTest<RefreshEpisodeService>
{ {
private List<Episode> _insertedEpisodes; private List<Episode> _insertedEpisodes;
private List<Episode> _updatedEpisodes; private List<Episode> _updatedEpisodes;
private List<Episode> _deletedEpisodes; private List<Episode> _deletedEpisodes;
private Tuple<Series, List<Episode>> _gameOfThrones; private Tuple<Series, List<Episode>> _gameOfThrones;
[OneTimeSetUp] [OneTimeSetUp]
public void TestFixture() public void TestFixture()
{ {
UseRealHttp(); UseRealHttp();
_gameOfThrones = Mocker.Resolve<SkyHookProxy>().GetSeriesInfo(121361);//Game of thrones _gameOfThrones = Mocker.Resolve<SkyHookProxy>().GetSeriesInfo(121361);//Game of thrones
// Remove specials. // Remove specials.
_gameOfThrones.Item2.RemoveAll(v => v.SeasonNumber == 0); _gameOfThrones.Item2.RemoveAll(v => v.SeasonNumber == 0);
} }
private List<Episode> GetEpisodes() private List<Episode> GetEpisodes()
{ {
return _gameOfThrones.Item2.JsonClone(); return _gameOfThrones.Item2.JsonClone();
} }
private Series GetSeries() private Series GetSeries()
{ {
var series = _gameOfThrones.Item1.JsonClone(); var series = _gameOfThrones.Item1.JsonClone();
series.Seasons = new List<Season>(); series.Seasons = new List<Season>();
return series; return series;
} }
private Series GetAnimeSeries() private Series GetAnimeSeries()
{ {
var series = Builder<Series>.CreateNew().Build(); var series = Builder<Series>.CreateNew().Build();
series.SeriesType = SeriesTypes.Anime; series.SeriesType = SeriesTypes.Anime;
series.Seasons = new List<Season>(); series.Seasons = new List<Season>();
return series; return series;
} }
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_insertedEpisodes = new List<Episode>(); _insertedEpisodes = new List<Episode>();
_updatedEpisodes = new List<Episode>(); _updatedEpisodes = new List<Episode>();
_deletedEpisodes = new List<Episode>(); _deletedEpisodes = new List<Episode>();
Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>()))
.Callback<List<Episode>>(e => _insertedEpisodes = e); .Callback<List<Episode>>(e => _insertedEpisodes = e);
Mocker.GetMock<IEpisodeService>().Setup(c => c.UpdateMany(It.IsAny<List<Episode>>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.UpdateMany(It.IsAny<List<Episode>>()))
.Callback<List<Episode>>(e => _updatedEpisodes = e); .Callback<List<Episode>>(e => _updatedEpisodes = e);
Mocker.GetMock<IEpisodeService>().Setup(c => c.DeleteMany(It.IsAny<List<Episode>>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.DeleteMany(It.IsAny<List<Episode>>()))
.Callback<List<Episode>>(e => _deletedEpisodes = e); .Callback<List<Episode>>(e => _deletedEpisodes = e);
} }
[Test] [Test]
public void should_create_all_when_no_existing_episodes() public void should_create_all_when_no_existing_episodes()
{ {
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes()); Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
_insertedEpisodes.Should().HaveSameCount(GetEpisodes()); _insertedEpisodes.Should().HaveSameCount(GetEpisodes());
_updatedEpisodes.Should().BeEmpty(); _updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty(); _deletedEpisodes.Should().BeEmpty();
} }
[Test] [Test]
public void should_update_all_when_all_existing_episodes() public void should_update_all_when_all_existing_episodes()
{ {
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(GetEpisodes()); .Returns(GetEpisodes());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes()); Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
_insertedEpisodes.Should().BeEmpty(); _insertedEpisodes.Should().BeEmpty();
_updatedEpisodes.Should().HaveSameCount(GetEpisodes()); _updatedEpisodes.Should().HaveSameCount(GetEpisodes());
_deletedEpisodes.Should().BeEmpty(); _deletedEpisodes.Should().BeEmpty();
} }
[Test] [Test]
public void should_delete_all_when_all_existing_episodes_are_gone_from_datasource() public void should_delete_all_when_all_existing_episodes_are_gone_from_datasource()
{ {
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(GetEpisodes()); .Returns(GetEpisodes());
Subject.RefreshEpisodeInfo(GetSeries(), new List<Episode>()); Subject.RefreshEpisodeInfo(GetSeries(), new List<Episode>());
_insertedEpisodes.Should().BeEmpty(); _insertedEpisodes.Should().BeEmpty();
_updatedEpisodes.Should().BeEmpty(); _updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().HaveSameCount(GetEpisodes()); _deletedEpisodes.Should().HaveSameCount(GetEpisodes());
} }
[Test] [Test]
public void should_delete_duplicated_episodes_based_on_season_episode_number() public void should_delete_duplicated_episodes_based_on_season_episode_number()
{ {
var duplicateEpisodes = GetEpisodes().Skip(5).Take(2).ToList(); var duplicateEpisodes = GetEpisodes().Skip(5).Take(2).ToList();
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(GetEpisodes().Union(duplicateEpisodes).ToList()); .Returns(GetEpisodes().Union(duplicateEpisodes).ToList());
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes()); Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
_insertedEpisodes.Should().BeEmpty(); _insertedEpisodes.Should().BeEmpty();
_updatedEpisodes.Should().HaveSameCount(GetEpisodes()); _updatedEpisodes.Should().HaveSameCount(GetEpisodes());
_deletedEpisodes.Should().HaveSameCount(duplicateEpisodes); _deletedEpisodes.Should().HaveSameCount(duplicateEpisodes);
} }
[Test] [Test]
public void should_not_change_monitored_status_for_existing_episodes() public void should_not_change_monitored_status_for_existing_episodes()
{ {
var series = GetSeries(); var series = GetSeries();
series.Seasons = new List<Season>(); series.Seasons = new List<Season>();
series.Seasons.Add(new Season { SeasonNumber = 1, Monitored = false }); series.Seasons.Add(new Season { SeasonNumber = 1, Monitored = false });
var episodes = GetEpisodes(); var episodes = GetEpisodes();
episodes.ForEach(e => e.Monitored = true); episodes.ForEach(e => e.Monitored = true);
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(episodes); .Returns(episodes);
Subject.RefreshEpisodeInfo(series, GetEpisodes()); Subject.RefreshEpisodeInfo(series, GetEpisodes());
_updatedEpisodes.Should().HaveSameCount(GetEpisodes()); _updatedEpisodes.Should().HaveSameCount(GetEpisodes());
_updatedEpisodes.Should().OnlyContain(e => e.Monitored == true); _updatedEpisodes.Should().OnlyContain(e => e.Monitored == true);
} }
[Test] [Test]
public void should_remove_duplicate_remote_episodes_before_processing() public void should_remove_duplicate_remote_episodes_before_processing()
{ {
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
var episodes = Builder<Episode>.CreateListOfSize(5) var episodes = Builder<Episode>.CreateListOfSize(5)
.TheFirst(2) .TheFirst(2)
.With(e => e.SeasonNumber = 1) .With(e => e.SeasonNumber = 1)
.With(e => e.EpisodeNumber = 1) .With(e => e.EpisodeNumber = 1)
.Build() .Build()
.ToList(); .ToList();
Subject.RefreshEpisodeInfo(GetSeries(), episodes); Subject.RefreshEpisodeInfo(GetSeries(), episodes);
_insertedEpisodes.Should().HaveCount(episodes.Count - 1); _insertedEpisodes.Should().HaveCount(episodes.Count - 1);
_updatedEpisodes.Should().BeEmpty(); _updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty(); _deletedEpisodes.Should().BeEmpty();
} }
[Test] [Test]
public void should_set_absolute_episode_number_for_anime() public void should_set_absolute_episode_number_for_anime()
{ {
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList(); var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes); Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
_insertedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue(); _insertedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue();
_updatedEpisodes.Should().BeEmpty(); _updatedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty(); _deletedEpisodes.Should().BeEmpty();
} }
[Test] [Test]
public void should_set_absolute_episode_number_even_if_not_previously_set_for_anime() public void should_set_absolute_episode_number_even_if_not_previously_set_for_anime()
{ {
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList(); var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
var existingEpisodes = episodes.JsonClone(); var existingEpisodes = episodes.JsonClone();
existingEpisodes.ForEach(e => e.AbsoluteEpisodeNumber = null); existingEpisodes.ForEach(e => e.AbsoluteEpisodeNumber = null);
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(existingEpisodes); .Returns(existingEpisodes);
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes); Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
_insertedEpisodes.Should().BeEmpty(); _insertedEpisodes.Should().BeEmpty();
_updatedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue(); _updatedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue();
_deletedEpisodes.Should().BeEmpty(); _deletedEpisodes.Should().BeEmpty();
} }
[Test] [Test]
public void should_get_new_season_and_episode_numbers_when_absolute_episode_number_match_found() public void should_get_new_season_and_episode_numbers_when_absolute_episode_number_match_found()
{ {
const int expectedSeasonNumber = 10; const int expectedSeasonNumber = 10;
const int expectedEpisodeNumber = 5; const int expectedEpisodeNumber = 5;
const int expectedAbsoluteNumber = 3; const int expectedAbsoluteNumber = 3;
var episode = Builder<Episode>.CreateNew() var episode = Builder<Episode>.CreateNew()
.With(e => e.SeasonNumber = expectedSeasonNumber) .With(e => e.SeasonNumber = expectedSeasonNumber)
.With(e => e.EpisodeNumber = expectedEpisodeNumber) .With(e => e.EpisodeNumber = expectedEpisodeNumber)
.With(e => e.AbsoluteEpisodeNumber = expectedAbsoluteNumber) .With(e => e.AbsoluteEpisodeNumber = expectedAbsoluteNumber)
.Build(); .Build();
var existingEpisode = episode.JsonClone(); var existingEpisode = episode.JsonClone();
existingEpisode.SeasonNumber = 1; existingEpisode.SeasonNumber = 1;
existingEpisode.EpisodeNumber = 1; existingEpisode.EpisodeNumber = 1;
existingEpisode.AbsoluteEpisodeNumber = expectedAbsoluteNumber; existingEpisode.AbsoluteEpisodeNumber = expectedAbsoluteNumber;
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>{ existingEpisode }); .Returns(new List<Episode>{ existingEpisode });
Subject.RefreshEpisodeInfo(GetAnimeSeries(), new List<Episode> { episode }); Subject.RefreshEpisodeInfo(GetAnimeSeries(), new List<Episode> { episode });
_insertedEpisodes.Should().BeEmpty(); _insertedEpisodes.Should().BeEmpty();
_deletedEpisodes.Should().BeEmpty(); _deletedEpisodes.Should().BeEmpty();
_updatedEpisodes.First().SeasonNumber.Should().Be(expectedSeasonNumber); _updatedEpisodes.First().SeasonNumber.Should().Be(expectedSeasonNumber);
_updatedEpisodes.First().EpisodeNumber.Should().Be(expectedEpisodeNumber); _updatedEpisodes.First().EpisodeNumber.Should().Be(expectedEpisodeNumber);
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(expectedAbsoluteNumber); _updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(expectedAbsoluteNumber);
} }
[Test] [Test]
public void should_prefer_absolute_match_over_season_and_epsiode_match() public void should_prefer_absolute_match_over_season_and_epsiode_match()
{ {
var episodes = Builder<Episode>.CreateListOfSize(2) var episodes = Builder<Episode>.CreateListOfSize(2)
.Build() .Build()
.ToList(); .ToList();
episodes[0].AbsoluteEpisodeNumber = null; episodes[0].AbsoluteEpisodeNumber = null;
episodes[0].SeasonNumber.Should().NotBe(episodes[1].SeasonNumber); episodes[0].SeasonNumber.Should().NotBe(episodes[1].SeasonNumber);
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber); episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
var existingEpisode = new Episode var existingEpisode = new Episode
{ {
SeasonNumber = episodes[0].SeasonNumber, SeasonNumber = episodes[0].SeasonNumber,
EpisodeNumber = episodes[0].EpisodeNumber, EpisodeNumber = episodes[0].EpisodeNumber,
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
}; };
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode> { existingEpisode }); .Returns(new List<Episode> { existingEpisode });
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes); Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber); _updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber); _updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber); _updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
} }
[Test] [Test]
public void should_ignore_episodes_with_no_absolute_episode_in_distinct_by_absolute() public void should_ignore_episodes_with_no_absolute_episode_in_distinct_by_absolute()
{ {
var episodes = Builder<Episode>.CreateListOfSize(10) var episodes = Builder<Episode>.CreateListOfSize(10)
.Build() .Build()
.ToList(); .ToList();
episodes[0].AbsoluteEpisodeNumber = null; episodes[0].AbsoluteEpisodeNumber = null;
episodes[1].AbsoluteEpisodeNumber = null; episodes[1].AbsoluteEpisodeNumber = null;
episodes[2].AbsoluteEpisodeNumber = null; episodes[2].AbsoluteEpisodeNumber = null;
episodes[3].AbsoluteEpisodeNumber = null; episodes[3].AbsoluteEpisodeNumber = null;
episodes[4].AbsoluteEpisodeNumber = null; episodes[4].AbsoluteEpisodeNumber = null;
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes); Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
_insertedEpisodes.Should().HaveCount(episodes.Count); _insertedEpisodes.Should().HaveCount(episodes.Count);
} }
[Test] [Test]
public void should_override_empty_airdate_for_direct_to_dvd() public void should_override_empty_airdate_for_direct_to_dvd()
{ {
var series = GetSeries(); var series = GetSeries();
series.Status = SeriesStatusType.Ended; series.Status = SeriesStatusType.Ended;
var episodes = Builder<Episode>.CreateListOfSize(10) var episodes = Builder<Episode>.CreateListOfSize(10)
.All() .All()
.With(v => v.AirDateUtc = null) .With(v => v.AirDateUtc = null)
.BuildListOfNew(); .BuildListOfNew();
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
List<Episode> updateEpisodes = null; List<Episode> updateEpisodes = null;
Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>()))
.Callback<List<Episode>>(c => updateEpisodes = c); .Callback<List<Episode>>(c => updateEpisodes = c);
Subject.RefreshEpisodeInfo(series, episodes); Subject.RefreshEpisodeInfo(series, episodes);
updateEpisodes.Should().NotBeNull(); updateEpisodes.Should().NotBeNull();
updateEpisodes.Should().NotBeEmpty(); updateEpisodes.Should().NotBeEmpty();
updateEpisodes.All(v => v.AirDateUtc.HasValue).Should().BeTrue(); updateEpisodes.All(v => v.AirDateUtc.HasValue).Should().BeTrue();
} }
[Test] [Test]
public void should_use_tba_for_episode_title_when_null() public void should_use_tba_for_episode_title_when_null()
{ {
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
var episodes = Builder<Episode>.CreateListOfSize(1) var episodes = Builder<Episode>.CreateListOfSize(1)
.All() .All()
.With(e => e.Title = null) .With(e => e.Title = null)
.Build() .Build()
.ToList(); .ToList();
Subject.RefreshEpisodeInfo(GetSeries(), episodes); Subject.RefreshEpisodeInfo(GetSeries(), episodes);
_insertedEpisodes.First().Title.Should().Be("TBA"); _insertedEpisodes.First().Title.Should().Be("TBA");
} }
[Test] [Test]
public void should_update_air_date_when_multiple_episodes_air_on_the_same_day() public void should_update_air_date_when_multiple_episodes_air_on_the_same_day()
{ {
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
var series = GetSeries(); var series = GetSeries();
var episodes = Builder<Episode>.CreateListOfSize(2) var episodes = Builder<Episode>.CreateListOfSize(2)
.All() .All()
.With(e => e.SeasonNumber = 1) .With(e => e.SeasonNumber = 1)
.With(e => e.AirDate = now.ToShortDateString()) .With(e => e.AirDate = now.ToShortDateString())
.With(e => e.AirDateUtc = now) .With(e => e.AirDateUtc = now)
.Build() .Build()
.ToList(); .ToList();
Subject.RefreshEpisodeInfo(series, episodes); Subject.RefreshEpisodeInfo(series, episodes);
_insertedEpisodes.First().AirDateUtc.Value.ToString("s").Should().Be(episodes.First().AirDateUtc.Value.ToString("s")); _insertedEpisodes.First().AirDateUtc.Value.ToString("s").Should().Be(episodes.First().AirDateUtc.Value.ToString("s"));
_insertedEpisodes.Last().AirDateUtc.Value.ToString("s").Should().Be(episodes.First().AirDateUtc.Value.AddMinutes(series.Runtime).ToString("s")); _insertedEpisodes.Last().AirDateUtc.Value.ToString("s").Should().Be(episodes.First().AirDateUtc.Value.AddMinutes(series.Runtime).ToString("s"));
} }
[Test] [Test]
public void should_not_update_air_date_when_more_than_three_episodes_air_on_the_same_day() public void should_not_update_air_date_when_more_than_three_episodes_air_on_the_same_day()
{ {
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode>()); .Returns(new List<Episode>());
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
var series = GetSeries(); var series = GetSeries();
var episodes = Builder<Episode>.CreateListOfSize(4) var episodes = Builder<Episode>.CreateListOfSize(4)
.All() .All()
.With(e => e.SeasonNumber = 1) .With(e => e.SeasonNumber = 1)
.With(e => e.AirDate = now.ToShortDateString()) .With(e => e.AirDate = now.ToShortDateString())
.With(e => e.AirDateUtc = now) .With(e => e.AirDateUtc = now)
.Build() .Build()
.ToList(); .ToList();
Subject.RefreshEpisodeInfo(series, episodes); Subject.RefreshEpisodeInfo(series, episodes);
_insertedEpisodes.Should().OnlyContain(e => e.AirDateUtc.Value.ToString("s") == episodes.First().AirDateUtc.Value.ToString("s")); _insertedEpisodes.Should().OnlyContain(e => e.AirDateUtc.Value.ToString("s") == episodes.First().AirDateUtc.Value.ToString("s"));
} }
[Test] [Test]
public void should_prefer_regular_season_when_absolute_numbers_conflict() public void should_prefer_regular_season_when_absolute_numbers_conflict()
{ {
var episodes = Builder<Episode>.CreateListOfSize(2) var episodes = Builder<Episode>.CreateListOfSize(2)
.Build() .Build()
.ToList(); .ToList();
episodes[0].AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber; episodes[0].AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber;
episodes[0].SeasonNumber = 0; episodes[0].SeasonNumber = 0;
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber); episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
var existingEpisode = new Episode var existingEpisode = new Episode
{ {
SeasonNumber = episodes[0].SeasonNumber, SeasonNumber = episodes[0].SeasonNumber,
EpisodeNumber = episodes[0].EpisodeNumber, EpisodeNumber = episodes[0].EpisodeNumber,
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
}; };
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>())) Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
.Returns(new List<Episode> { existingEpisode }); .Returns(new List<Episode> { existingEpisode });
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes); Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber); _updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber); _updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber); _updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
} }
} }
} }

@ -1,84 +1,84 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions; using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Organizer; using NzbDrone.Core.Organizer;
using NzbDrone.Core.RootFolders; using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common; using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests
{ {
[TestFixture] [TestFixture]
public class UpdateMultipleSeriesFixture : CoreTest<SeriesService> public class UpdateMultipleSeriesFixture : CoreTest<SeriesService>
{ {
private List<Series> _series; private List<Series> _series;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_series = Builder<Series>.CreateListOfSize(5) _series = Builder<Series>.CreateListOfSize(5)
.All() .All()
.With(s => s.QualityProfileId = 1) .With(s => s.QualityProfileId = 1)
.With(s => s.Monitored) .With(s => s.Monitored)
.With(s => s.SeasonFolder) .With(s => s.SeasonFolder)
.With(s => s.Path = @"C:\Test\name".AsOsAgnostic()) .With(s => s.Path = @"C:\Test\name".AsOsAgnostic())
.With(s => s.RootFolderPath = "") .With(s => s.RootFolderPath = "")
.Build().ToList(); .Build().ToList();
} }
[Test] [Test]
public void should_call_repo_updateMany() public void should_call_repo_updateMany()
{ {
Subject.UpdateSeries(_series, false); Subject.UpdateSeries(_series, false);
Mocker.GetMock<ISeriesRepository>().Verify(v => v.UpdateMany(_series), Times.Once()); Mocker.GetMock<ISeriesRepository>().Verify(v => v.UpdateMany(_series), Times.Once());
} }
[Test] [Test]
public void should_update_path_when_rootFolderPath_is_supplied() public void should_update_path_when_rootFolderPath_is_supplied()
{ {
var newRoot = @"C:\Test\TV2".AsOsAgnostic(); var newRoot = @"C:\Test\TV2".AsOsAgnostic();
_series.ForEach(s => s.RootFolderPath = newRoot); _series.ForEach(s => s.RootFolderPath = newRoot);
Mocker.GetMock<IBuildSeriesPaths>() Mocker.GetMock<IBuildSeriesPaths>()
.Setup(s => s.BuildPath(It.IsAny<Series>(), false)) .Setup(s => s.BuildPath(It.IsAny<Series>(), false))
.Returns<Series, bool>((s, u) => Path.Combine(s.RootFolderPath, s.Title)); .Returns<Series, bool>((s, u) => Path.Combine(s.RootFolderPath, s.Title));
Subject.UpdateSeries(_series, false).ForEach(s => s.Path.Should().StartWith(newRoot)); Subject.UpdateSeries(_series, false).ForEach(s => s.Path.Should().StartWith(newRoot));
} }
[Test] [Test]
public void should_not_update_path_when_rootFolderPath_is_empty() public void should_not_update_path_when_rootFolderPath_is_empty()
{ {
Subject.UpdateSeries(_series, false).ForEach(s => Subject.UpdateSeries(_series, false).ForEach(s =>
{ {
var expectedPath = _series.Single(ser => ser.Id == s.Id).Path; var expectedPath = _series.Single(ser => ser.Id == s.Id).Path;
s.Path.Should().Be(expectedPath); s.Path.Should().Be(expectedPath);
}); });
} }
[Test] [Test]
public void should_be_able_to_update_many_series() public void should_be_able_to_update_many_series()
{ {
var series = Builder<Series>.CreateListOfSize(50) var series = Builder<Series>.CreateListOfSize(50)
.All() .All()
.With(s => s.Path = (@"C:\Test\TV\" + s.Path).AsOsAgnostic()) .With(s => s.Path = (@"C:\Test\TV\" + s.Path).AsOsAgnostic())
.Build() .Build()
.ToList(); .ToList();
var newRoot = @"C:\Test\TV2".AsOsAgnostic(); var newRoot = @"C:\Test\TV2".AsOsAgnostic();
series.ForEach(s => s.RootFolderPath = newRoot); series.ForEach(s => s.RootFolderPath = newRoot);
Mocker.GetMock<IBuildFileNames>() Mocker.GetMock<IBuildFileNames>()
.Setup(s => s.GetSeriesFolder(It.IsAny<Series>(), (NamingConfig)null)) .Setup(s => s.GetSeriesFolder(It.IsAny<Series>(), (NamingConfig)null))
.Returns<Series, NamingConfig>((s, n) => s.Title); .Returns<Series, NamingConfig>((s, n) => s.Title);
Subject.UpdateSeries(series, false); Subject.UpdateSeries(series, false);
} }
} }
} }

@ -1,72 +1,72 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests
{ {
[TestFixture] [TestFixture]
public class UpdateSeriesFixture : CoreTest<SeriesService> public class UpdateSeriesFixture : CoreTest<SeriesService>
{ {
private Series _fakeSeries; private Series _fakeSeries;
private Series _existingSeries; private Series _existingSeries;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
_fakeSeries = Builder<Series>.CreateNew().Build(); _fakeSeries = Builder<Series>.CreateNew().Build();
_existingSeries = Builder<Series>.CreateNew().Build(); _existingSeries = Builder<Series>.CreateNew().Build();
_fakeSeries.Seasons = new List<Season> _fakeSeries.Seasons = new List<Season>
{ {
new Season{ SeasonNumber = 1, Monitored = true }, new Season{ SeasonNumber = 1, Monitored = true },
new Season{ SeasonNumber = 2, Monitored = true } new Season{ SeasonNumber = 2, Monitored = true }
}; };
_existingSeries.Seasons = new List<Season> _existingSeries.Seasons = new List<Season>
{ {
new Season{ SeasonNumber = 1, Monitored = true }, new Season{ SeasonNumber = 1, Monitored = true },
new Season{ SeasonNumber = 2, Monitored = true } new Season{ SeasonNumber = 2, Monitored = true }
}; };
} }
private void GivenExistingSeries() private void GivenExistingSeries()
{ {
Mocker.GetMock<ISeriesRepository>() Mocker.GetMock<ISeriesRepository>()
.Setup(s => s.Get(It.IsAny<int>())) .Setup(s => s.Get(It.IsAny<int>()))
.Returns(_existingSeries); .Returns(_existingSeries);
} }
[Test] [Test]
public void should_not_update_episodes_if_season_hasnt_changed() public void should_not_update_episodes_if_season_hasnt_changed()
{ {
GivenExistingSeries(); GivenExistingSeries();
Subject.UpdateSeries(_fakeSeries); Subject.UpdateSeries(_fakeSeries);
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Never()); .Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Never());
} }
[Test] [Test]
public void should_update_series_when_it_changes() public void should_update_series_when_it_changes()
{ {
GivenExistingSeries(); GivenExistingSeries();
var seasonNumber = 1; var seasonNumber = 1;
var monitored = false; var monitored = false;
_fakeSeries.Seasons.Single(s => s.SeasonNumber == seasonNumber).Monitored = monitored; _fakeSeries.Seasons.Single(s => s.SeasonNumber == seasonNumber).Monitored = monitored;
Subject.UpdateSeries(_fakeSeries); Subject.UpdateSeries(_fakeSeries);
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, seasonNumber, monitored), Times.Once()); .Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, seasonNumber, monitored), Times.Once());
Mocker.GetMock<IEpisodeService>() Mocker.GetMock<IEpisodeService>()
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Once()); .Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Once());
} }
} }
} }

@ -1,7 +1,7 @@
namespace NzbDrone.Core.Download.Clients.Sabnzbd.Responses namespace NzbDrone.Core.Download.Clients.Sabnzbd.Responses
{ {
public class SabnzbdFullStatusResponse public class SabnzbdFullStatusResponse
{ {
public SabnzbdFullStatus Status { get; set; } public SabnzbdFullStatus Status { get; set; }
} }
} }

@ -1,93 +1,93 @@
using System; using System;
using System.Threading; using System.Threading;
using Nancy; using Nancy;
using Nancy.Bootstrapper; using Nancy.Bootstrapper;
using NLog; using NLog;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using Sonarr.Http.ErrorManagement; using Sonarr.Http.ErrorManagement;
using Sonarr.Http.Extensions; using Sonarr.Http.Extensions;
using Sonarr.Http.Extensions.Pipelines; using Sonarr.Http.Extensions.Pipelines;
namespace NzbDrone.Api.Extensions.Pipelines namespace NzbDrone.Api.Extensions.Pipelines
{ {
public class RequestLoggingPipeline : IRegisterNancyPipeline public class RequestLoggingPipeline : IRegisterNancyPipeline
{ {
private static readonly Logger _loggerHttp = LogManager.GetLogger("Http"); private static readonly Logger _loggerHttp = LogManager.GetLogger("Http");
private static readonly Logger _loggerApi = LogManager.GetLogger("Api"); private static readonly Logger _loggerApi = LogManager.GetLogger("Api");
private static int _requestSequenceID; private static int _requestSequenceID;
private readonly SonarrErrorPipeline _errorPipeline; private readonly SonarrErrorPipeline _errorPipeline;
public RequestLoggingPipeline(SonarrErrorPipeline errorPipeline) public RequestLoggingPipeline(SonarrErrorPipeline errorPipeline)
{ {
_errorPipeline = errorPipeline; _errorPipeline = errorPipeline;
} }
public int Order => 100; public int Order => 100;
public void Register(IPipelines pipelines) public void Register(IPipelines pipelines)
{ {
pipelines.BeforeRequest.AddItemToStartOfPipeline(LogStart); pipelines.BeforeRequest.AddItemToStartOfPipeline(LogStart);
pipelines.AfterRequest.AddItemToEndOfPipeline(LogEnd); pipelines.AfterRequest.AddItemToEndOfPipeline(LogEnd);
pipelines.OnError.AddItemToEndOfPipeline(LogError); pipelines.OnError.AddItemToEndOfPipeline(LogError);
} }
private Response LogStart(NancyContext context) private Response LogStart(NancyContext context)
{ {
var id = Interlocked.Increment(ref _requestSequenceID); var id = Interlocked.Increment(ref _requestSequenceID);
context.Items["ApiRequestSequenceID"] = id; context.Items["ApiRequestSequenceID"] = id;
context.Items["ApiRequestStartTime"] = DateTime.UtcNow; context.Items["ApiRequestStartTime"] = DateTime.UtcNow;
var reqPath = GetRequestPathAndQuery(context.Request); var reqPath = GetRequestPathAndQuery(context.Request);
_loggerHttp.Trace("Req: {0} [{1}] {2}", id, context.Request.Method, reqPath); _loggerHttp.Trace("Req: {0} [{1}] {2}", id, context.Request.Method, reqPath);
return null; return null;
} }
private void LogEnd(NancyContext context) private void LogEnd(NancyContext context)
{ {
var id = (int)context.Items["ApiRequestSequenceID"]; var id = (int)context.Items["ApiRequestSequenceID"];
var startTime = (DateTime)context.Items["ApiRequestStartTime"]; var startTime = (DateTime)context.Items["ApiRequestStartTime"];
var endTime = DateTime.UtcNow; var endTime = DateTime.UtcNow;
var duration = endTime - startTime; var duration = endTime - startTime;
var reqPath = GetRequestPathAndQuery(context.Request); var reqPath = GetRequestPathAndQuery(context.Request);
_loggerHttp.Trace("Res: {0} [{1}] {2}: {3}.{4} ({5} ms)", id, context.Request.Method, reqPath, (int)context.Response.StatusCode, context.Response.StatusCode, (int)duration.TotalMilliseconds); _loggerHttp.Trace("Res: {0} [{1}] {2}: {3}.{4} ({5} ms)", id, context.Request.Method, reqPath, (int)context.Response.StatusCode, context.Response.StatusCode, (int)duration.TotalMilliseconds);
if (context.Request.IsApiRequest()) if (context.Request.IsApiRequest())
{ {
_loggerApi.Debug("[{0}] {1}: {2}.{3} ({4} ms)", context.Request.Method, reqPath, (int)context.Response.StatusCode, context.Response.StatusCode, (int)duration.TotalMilliseconds); _loggerApi.Debug("[{0}] {1}: {2}.{3} ({4} ms)", context.Request.Method, reqPath, (int)context.Response.StatusCode, context.Response.StatusCode, (int)duration.TotalMilliseconds);
} }
} }
private Response LogError(NancyContext context, Exception exception) private Response LogError(NancyContext context, Exception exception)
{ {
var response = _errorPipeline.HandleException(context, exception); var response = _errorPipeline.HandleException(context, exception);
context.Response = response; context.Response = response;
LogEnd(context); LogEnd(context);
context.Response = null; context.Response = null;
return response; return response;
} }
private static string GetRequestPathAndQuery(Request request) private static string GetRequestPathAndQuery(Request request)
{ {
if (request.Url.Query.IsNotNullOrWhiteSpace()) if (request.Url.Query.IsNotNullOrWhiteSpace())
{ {
return string.Concat(request.Url.Path, request.Url.Query); return string.Concat(request.Url.Path, request.Url.Query);
} }
else else
{ {
return request.Url.Path; return request.Url.Path;
} }
} }
} }
} }

Loading…
Cancel
Save