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
This commit is contained in:
parent
8a2a41fab0
commit
7b68ce49d5
|
@ -1,5 +1,11 @@
|
|||
# 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
|
||||
*.cs diff=csharp
|
||||
|
|
|
@ -1,398 +1,398 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RefreshEpisodeServiceFixture : CoreTest<RefreshEpisodeService>
|
||||
{
|
||||
private List<Episode> _insertedEpisodes;
|
||||
private List<Episode> _updatedEpisodes;
|
||||
private List<Episode> _deletedEpisodes;
|
||||
private Tuple<Series, List<Episode>> _gameOfThrones;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void TestFixture()
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
_gameOfThrones = Mocker.Resolve<SkyHookProxy>().GetSeriesInfo(121361);//Game of thrones
|
||||
|
||||
// Remove specials.
|
||||
_gameOfThrones.Item2.RemoveAll(v => v.SeasonNumber == 0);
|
||||
}
|
||||
|
||||
private List<Episode> GetEpisodes()
|
||||
{
|
||||
return _gameOfThrones.Item2.JsonClone();
|
||||
}
|
||||
|
||||
private Series GetSeries()
|
||||
{
|
||||
var series = _gameOfThrones.Item1.JsonClone();
|
||||
series.Seasons = new List<Season>();
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
private Series GetAnimeSeries()
|
||||
{
|
||||
var series = Builder<Series>.CreateNew().Build();
|
||||
series.SeriesType = SeriesTypes.Anime;
|
||||
series.Seasons = new List<Season>();
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_insertedEpisodes = new List<Episode>();
|
||||
_updatedEpisodes = new List<Episode>();
|
||||
_deletedEpisodes = new List<Episode>();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(e => _insertedEpisodes = e);
|
||||
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.UpdateMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(e => _updatedEpisodes = e);
|
||||
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.DeleteMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(e => _deletedEpisodes = e);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_create_all_when_no_existing_episodes()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
|
||||
|
||||
_insertedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_all_when_all_existing_episodes()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(GetEpisodes());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_all_when_all_existing_episodes_are_gone_from_datasource()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(GetEpisodes());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), new List<Episode>());
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_duplicated_episodes_based_on_season_episode_number()
|
||||
{
|
||||
var duplicateEpisodes = GetEpisodes().Skip(5).Take(2).ToList();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(GetEpisodes().Union(duplicateEpisodes).ToList());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_deletedEpisodes.Should().HaveSameCount(duplicateEpisodes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_change_monitored_status_for_existing_episodes()
|
||||
{
|
||||
var series = GetSeries();
|
||||
series.Seasons = new List<Season>();
|
||||
series.Seasons.Add(new Season { SeasonNumber = 1, Monitored = false });
|
||||
|
||||
var episodes = GetEpisodes();
|
||||
|
||||
episodes.ForEach(e => e.Monitored = true);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(episodes);
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, GetEpisodes());
|
||||
|
||||
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_updatedEpisodes.Should().OnlyContain(e => e.Monitored == true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_remove_duplicate_remote_episodes_before_processing()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(5)
|
||||
.TheFirst(2)
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.With(e => e.EpisodeNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.Should().HaveCount(episodes.Count - 1);
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_absolute_episode_number_for_anime()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue();
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_absolute_episode_number_even_if_not_previously_set_for_anime()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
|
||||
|
||||
var existingEpisodes = episodes.JsonClone();
|
||||
existingEpisodes.ForEach(e => e.AbsoluteEpisodeNumber = null);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(existingEpisodes);
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_new_season_and_episode_numbers_when_absolute_episode_number_match_found()
|
||||
{
|
||||
const int expectedSeasonNumber = 10;
|
||||
const int expectedEpisodeNumber = 5;
|
||||
const int expectedAbsoluteNumber = 3;
|
||||
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.SeasonNumber = expectedSeasonNumber)
|
||||
.With(e => e.EpisodeNumber = expectedEpisodeNumber)
|
||||
.With(e => e.AbsoluteEpisodeNumber = expectedAbsoluteNumber)
|
||||
.Build();
|
||||
|
||||
var existingEpisode = episode.JsonClone();
|
||||
existingEpisode.SeasonNumber = 1;
|
||||
existingEpisode.EpisodeNumber = 1;
|
||||
existingEpisode.AbsoluteEpisodeNumber = expectedAbsoluteNumber;
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>{ existingEpisode });
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), new List<Episode> { episode });
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
|
||||
_updatedEpisodes.First().SeasonNumber.Should().Be(expectedSeasonNumber);
|
||||
_updatedEpisodes.First().EpisodeNumber.Should().Be(expectedEpisodeNumber);
|
||||
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(expectedAbsoluteNumber);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_absolute_match_over_season_and_epsiode_match()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
episodes[0].AbsoluteEpisodeNumber = null;
|
||||
episodes[0].SeasonNumber.Should().NotBe(episodes[1].SeasonNumber);
|
||||
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
|
||||
|
||||
var existingEpisode = new Episode
|
||||
{
|
||||
SeasonNumber = episodes[0].SeasonNumber,
|
||||
EpisodeNumber = episodes[0].EpisodeNumber,
|
||||
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
|
||||
};
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode> { existingEpisode });
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
|
||||
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
|
||||
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_ignore_episodes_with_no_absolute_episode_in_distinct_by_absolute()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
episodes[0].AbsoluteEpisodeNumber = null;
|
||||
episodes[1].AbsoluteEpisodeNumber = null;
|
||||
episodes[2].AbsoluteEpisodeNumber = null;
|
||||
episodes[3].AbsoluteEpisodeNumber = null;
|
||||
episodes[4].AbsoluteEpisodeNumber = null;
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.Should().HaveCount(episodes.Count);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_override_empty_airdate_for_direct_to_dvd()
|
||||
{
|
||||
var series = GetSeries();
|
||||
series.Status = SeriesStatusType.Ended;
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(v => v.AirDateUtc = null)
|
||||
.BuildListOfNew();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
List<Episode> updateEpisodes = null;
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(c => updateEpisodes = c);
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, episodes);
|
||||
|
||||
updateEpisodes.Should().NotBeNull();
|
||||
updateEpisodes.Should().NotBeEmpty();
|
||||
updateEpisodes.All(v => v.AirDateUtc.HasValue).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_tba_for_episode_title_when_null()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.Title = null)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.First().Title.Should().Be("TBA");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_air_date_when_multiple_episodes_air_on_the_same_day()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var series = GetSeries();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.With(e => e.AirDate = now.ToShortDateString())
|
||||
.With(e => e.AirDateUtc = now)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, episodes);
|
||||
|
||||
_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"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
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>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var series = GetSeries();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.All()
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.With(e => e.AirDate = now.ToShortDateString())
|
||||
.With(e => e.AirDateUtc = now)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, episodes);
|
||||
|
||||
_insertedEpisodes.Should().OnlyContain(e => e.AirDateUtc.Value.ToString("s") == episodes.First().AirDateUtc.Value.ToString("s"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_regular_season_when_absolute_numbers_conflict()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
episodes[0].AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber;
|
||||
episodes[0].SeasonNumber = 0;
|
||||
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
|
||||
|
||||
var existingEpisode = new Episode
|
||||
{
|
||||
SeasonNumber = episodes[0].SeasonNumber,
|
||||
EpisodeNumber = episodes[0].EpisodeNumber,
|
||||
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
|
||||
};
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode> { existingEpisode });
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
|
||||
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
|
||||
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.MetadataSource.SkyHook;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RefreshEpisodeServiceFixture : CoreTest<RefreshEpisodeService>
|
||||
{
|
||||
private List<Episode> _insertedEpisodes;
|
||||
private List<Episode> _updatedEpisodes;
|
||||
private List<Episode> _deletedEpisodes;
|
||||
private Tuple<Series, List<Episode>> _gameOfThrones;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void TestFixture()
|
||||
{
|
||||
UseRealHttp();
|
||||
|
||||
_gameOfThrones = Mocker.Resolve<SkyHookProxy>().GetSeriesInfo(121361);//Game of thrones
|
||||
|
||||
// Remove specials.
|
||||
_gameOfThrones.Item2.RemoveAll(v => v.SeasonNumber == 0);
|
||||
}
|
||||
|
||||
private List<Episode> GetEpisodes()
|
||||
{
|
||||
return _gameOfThrones.Item2.JsonClone();
|
||||
}
|
||||
|
||||
private Series GetSeries()
|
||||
{
|
||||
var series = _gameOfThrones.Item1.JsonClone();
|
||||
series.Seasons = new List<Season>();
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
private Series GetAnimeSeries()
|
||||
{
|
||||
var series = Builder<Series>.CreateNew().Build();
|
||||
series.SeriesType = SeriesTypes.Anime;
|
||||
series.Seasons = new List<Season>();
|
||||
|
||||
return series;
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_insertedEpisodes = new List<Episode>();
|
||||
_updatedEpisodes = new List<Episode>();
|
||||
_deletedEpisodes = new List<Episode>();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(e => _insertedEpisodes = e);
|
||||
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.UpdateMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(e => _updatedEpisodes = e);
|
||||
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.DeleteMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(e => _deletedEpisodes = e);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_create_all_when_no_existing_episodes()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
|
||||
|
||||
_insertedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_all_when_all_existing_episodes()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(GetEpisodes());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_all_when_all_existing_episodes_are_gone_from_datasource()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(GetEpisodes());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), new List<Episode>());
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_duplicated_episodes_based_on_season_episode_number()
|
||||
{
|
||||
var duplicateEpisodes = GetEpisodes().Skip(5).Take(2).ToList();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(GetEpisodes().Union(duplicateEpisodes).ToList());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), GetEpisodes());
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_deletedEpisodes.Should().HaveSameCount(duplicateEpisodes);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_change_monitored_status_for_existing_episodes()
|
||||
{
|
||||
var series = GetSeries();
|
||||
series.Seasons = new List<Season>();
|
||||
series.Seasons.Add(new Season { SeasonNumber = 1, Monitored = false });
|
||||
|
||||
var episodes = GetEpisodes();
|
||||
|
||||
episodes.ForEach(e => e.Monitored = true);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(episodes);
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, GetEpisodes());
|
||||
|
||||
_updatedEpisodes.Should().HaveSameCount(GetEpisodes());
|
||||
_updatedEpisodes.Should().OnlyContain(e => e.Monitored == true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_remove_duplicate_remote_episodes_before_processing()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(5)
|
||||
.TheFirst(2)
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.With(e => e.EpisodeNumber = 1)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.Should().HaveCount(episodes.Count - 1);
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_absolute_episode_number_for_anime()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue();
|
||||
_updatedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_set_absolute_episode_number_even_if_not_previously_set_for_anime()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(3).Build().ToList();
|
||||
|
||||
var existingEpisodes = episodes.JsonClone();
|
||||
existingEpisodes.ForEach(e => e.AbsoluteEpisodeNumber = null);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(existingEpisodes);
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_updatedEpisodes.All(e => e.AbsoluteEpisodeNumber.HasValue).Should().BeTrue();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_get_new_season_and_episode_numbers_when_absolute_episode_number_match_found()
|
||||
{
|
||||
const int expectedSeasonNumber = 10;
|
||||
const int expectedEpisodeNumber = 5;
|
||||
const int expectedAbsoluteNumber = 3;
|
||||
|
||||
var episode = Builder<Episode>.CreateNew()
|
||||
.With(e => e.SeasonNumber = expectedSeasonNumber)
|
||||
.With(e => e.EpisodeNumber = expectedEpisodeNumber)
|
||||
.With(e => e.AbsoluteEpisodeNumber = expectedAbsoluteNumber)
|
||||
.Build();
|
||||
|
||||
var existingEpisode = episode.JsonClone();
|
||||
existingEpisode.SeasonNumber = 1;
|
||||
existingEpisode.EpisodeNumber = 1;
|
||||
existingEpisode.AbsoluteEpisodeNumber = expectedAbsoluteNumber;
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>{ existingEpisode });
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), new List<Episode> { episode });
|
||||
|
||||
_insertedEpisodes.Should().BeEmpty();
|
||||
_deletedEpisodes.Should().BeEmpty();
|
||||
|
||||
_updatedEpisodes.First().SeasonNumber.Should().Be(expectedSeasonNumber);
|
||||
_updatedEpisodes.First().EpisodeNumber.Should().Be(expectedEpisodeNumber);
|
||||
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(expectedAbsoluteNumber);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_absolute_match_over_season_and_epsiode_match()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
episodes[0].AbsoluteEpisodeNumber = null;
|
||||
episodes[0].SeasonNumber.Should().NotBe(episodes[1].SeasonNumber);
|
||||
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
|
||||
|
||||
var existingEpisode = new Episode
|
||||
{
|
||||
SeasonNumber = episodes[0].SeasonNumber,
|
||||
EpisodeNumber = episodes[0].EpisodeNumber,
|
||||
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
|
||||
};
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode> { existingEpisode });
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
|
||||
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
|
||||
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_ignore_episodes_with_no_absolute_episode_in_distinct_by_absolute()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
episodes[0].AbsoluteEpisodeNumber = null;
|
||||
episodes[1].AbsoluteEpisodeNumber = null;
|
||||
episodes[2].AbsoluteEpisodeNumber = null;
|
||||
episodes[3].AbsoluteEpisodeNumber = null;
|
||||
episodes[4].AbsoluteEpisodeNumber = null;
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.Should().HaveCount(episodes.Count);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_override_empty_airdate_for_direct_to_dvd()
|
||||
{
|
||||
var series = GetSeries();
|
||||
series.Status = SeriesStatusType.Ended;
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(10)
|
||||
.All()
|
||||
.With(v => v.AirDateUtc = null)
|
||||
.BuildListOfNew();
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
List<Episode> updateEpisodes = null;
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.InsertMany(It.IsAny<List<Episode>>()))
|
||||
.Callback<List<Episode>>(c => updateEpisodes = c);
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, episodes);
|
||||
|
||||
updateEpisodes.Should().NotBeNull();
|
||||
updateEpisodes.Should().NotBeEmpty();
|
||||
updateEpisodes.All(v => v.AirDateUtc.HasValue).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_use_tba_for_episode_title_when_null()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(1)
|
||||
.All()
|
||||
.With(e => e.Title = null)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetSeries(), episodes);
|
||||
|
||||
_insertedEpisodes.First().Title.Should().Be("TBA");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_air_date_when_multiple_episodes_air_on_the_same_day()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var series = GetSeries();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.With(e => e.AirDate = now.ToShortDateString())
|
||||
.With(e => e.AirDateUtc = now)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, episodes);
|
||||
|
||||
_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"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
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>()))
|
||||
.Returns(new List<Episode>());
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
var series = GetSeries();
|
||||
|
||||
var episodes = Builder<Episode>.CreateListOfSize(4)
|
||||
.All()
|
||||
.With(e => e.SeasonNumber = 1)
|
||||
.With(e => e.AirDate = now.ToShortDateString())
|
||||
.With(e => e.AirDateUtc = now)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
Subject.RefreshEpisodeInfo(series, episodes);
|
||||
|
||||
_insertedEpisodes.Should().OnlyContain(e => e.AirDateUtc.Value.ToString("s") == episodes.First().AirDateUtc.Value.ToString("s"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_prefer_regular_season_when_absolute_numbers_conflict()
|
||||
{
|
||||
var episodes = Builder<Episode>.CreateListOfSize(2)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
episodes[0].AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber;
|
||||
episodes[0].SeasonNumber = 0;
|
||||
episodes[0].EpisodeNumber.Should().NotBe(episodes[1].EpisodeNumber);
|
||||
|
||||
var existingEpisode = new Episode
|
||||
{
|
||||
SeasonNumber = episodes[0].SeasonNumber,
|
||||
EpisodeNumber = episodes[0].EpisodeNumber,
|
||||
AbsoluteEpisodeNumber = episodes[1].AbsoluteEpisodeNumber
|
||||
};
|
||||
|
||||
Mocker.GetMock<IEpisodeService>().Setup(c => c.GetEpisodeBySeries(It.IsAny<int>()))
|
||||
.Returns(new List<Episode> { existingEpisode });
|
||||
|
||||
Subject.RefreshEpisodeInfo(GetAnimeSeries(), episodes);
|
||||
|
||||
_updatedEpisodes.First().SeasonNumber.Should().Be(episodes[1].SeasonNumber);
|
||||
_updatedEpisodes.First().EpisodeNumber.Should().Be(episodes[1].EpisodeNumber);
|
||||
_updatedEpisodes.First().AbsoluteEpisodeNumber.Should().Be(episodes[1].AbsoluteEpisodeNumber);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,84 +1,84 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateMultipleSeriesFixture : CoreTest<SeriesService>
|
||||
{
|
||||
private List<Series> _series;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateListOfSize(5)
|
||||
.All()
|
||||
.With(s => s.QualityProfileId = 1)
|
||||
.With(s => s.Monitored)
|
||||
.With(s => s.SeasonFolder)
|
||||
.With(s => s.Path = @"C:\Test\name".AsOsAgnostic())
|
||||
.With(s => s.RootFolderPath = "")
|
||||
.Build().ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_repo_updateMany()
|
||||
{
|
||||
Subject.UpdateSeries(_series, false);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Verify(v => v.UpdateMany(_series), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_path_when_rootFolderPath_is_supplied()
|
||||
{
|
||||
var newRoot = @"C:\Test\TV2".AsOsAgnostic();
|
||||
_series.ForEach(s => s.RootFolderPath = newRoot);
|
||||
|
||||
Mocker.GetMock<IBuildSeriesPaths>()
|
||||
.Setup(s => s.BuildPath(It.IsAny<Series>(), false))
|
||||
.Returns<Series, bool>((s, u) => Path.Combine(s.RootFolderPath, s.Title));
|
||||
|
||||
Subject.UpdateSeries(_series, false).ForEach(s => s.Path.Should().StartWith(newRoot));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_path_when_rootFolderPath_is_empty()
|
||||
{
|
||||
Subject.UpdateSeries(_series, false).ForEach(s =>
|
||||
{
|
||||
var expectedPath = _series.Single(ser => ser.Id == s.Id).Path;
|
||||
s.Path.Should().Be(expectedPath);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_update_many_series()
|
||||
{
|
||||
var series = Builder<Series>.CreateListOfSize(50)
|
||||
.All()
|
||||
.With(s => s.Path = (@"C:\Test\TV\" + s.Path).AsOsAgnostic())
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
var newRoot = @"C:\Test\TV2".AsOsAgnostic();
|
||||
series.ForEach(s => s.RootFolderPath = newRoot);
|
||||
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Setup(s => s.GetSeriesFolder(It.IsAny<Series>(), (NamingConfig)null))
|
||||
.Returns<Series, NamingConfig>((s, n) => s.Title);
|
||||
|
||||
Subject.UpdateSeries(series, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateMultipleSeriesFixture : CoreTest<SeriesService>
|
||||
{
|
||||
private List<Series> _series;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateListOfSize(5)
|
||||
.All()
|
||||
.With(s => s.QualityProfileId = 1)
|
||||
.With(s => s.Monitored)
|
||||
.With(s => s.SeasonFolder)
|
||||
.With(s => s.Path = @"C:\Test\name".AsOsAgnostic())
|
||||
.With(s => s.RootFolderPath = "")
|
||||
.Build().ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_call_repo_updateMany()
|
||||
{
|
||||
Subject.UpdateSeries(_series, false);
|
||||
|
||||
Mocker.GetMock<ISeriesRepository>().Verify(v => v.UpdateMany(_series), Times.Once());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_path_when_rootFolderPath_is_supplied()
|
||||
{
|
||||
var newRoot = @"C:\Test\TV2".AsOsAgnostic();
|
||||
_series.ForEach(s => s.RootFolderPath = newRoot);
|
||||
|
||||
Mocker.GetMock<IBuildSeriesPaths>()
|
||||
.Setup(s => s.BuildPath(It.IsAny<Series>(), false))
|
||||
.Returns<Series, bool>((s, u) => Path.Combine(s.RootFolderPath, s.Title));
|
||||
|
||||
Subject.UpdateSeries(_series, false).ForEach(s => s.Path.Should().StartWith(newRoot));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_path_when_rootFolderPath_is_empty()
|
||||
{
|
||||
Subject.UpdateSeries(_series, false).ForEach(s =>
|
||||
{
|
||||
var expectedPath = _series.Single(ser => ser.Id == s.Id).Path;
|
||||
s.Path.Should().Be(expectedPath);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_update_many_series()
|
||||
{
|
||||
var series = Builder<Series>.CreateListOfSize(50)
|
||||
.All()
|
||||
.With(s => s.Path = (@"C:\Test\TV\" + s.Path).AsOsAgnostic())
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
var newRoot = @"C:\Test\TV2".AsOsAgnostic();
|
||||
series.ForEach(s => s.RootFolderPath = newRoot);
|
||||
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Setup(s => s.GetSeriesFolder(It.IsAny<Series>(), (NamingConfig)null))
|
||||
.Returns<Series, NamingConfig>((s, n) => s.Title);
|
||||
|
||||
Subject.UpdateSeries(series, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,72 +1,72 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateSeriesFixture : CoreTest<SeriesService>
|
||||
{
|
||||
private Series _fakeSeries;
|
||||
private Series _existingSeries;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
_existingSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
_fakeSeries.Seasons = new List<Season>
|
||||
{
|
||||
new Season{ SeasonNumber = 1, Monitored = true },
|
||||
new Season{ SeasonNumber = 2, Monitored = true }
|
||||
};
|
||||
|
||||
_existingSeries.Seasons = new List<Season>
|
||||
{
|
||||
new Season{ SeasonNumber = 1, Monitored = true },
|
||||
new Season{ SeasonNumber = 2, Monitored = true }
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenExistingSeries()
|
||||
{
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(s => s.Get(It.IsAny<int>()))
|
||||
.Returns(_existingSeries);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_episodes_if_season_hasnt_changed()
|
||||
{
|
||||
GivenExistingSeries();
|
||||
|
||||
Subject.UpdateSeries(_fakeSeries);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_series_when_it_changes()
|
||||
{
|
||||
GivenExistingSeries();
|
||||
var seasonNumber = 1;
|
||||
var monitored = false;
|
||||
|
||||
_fakeSeries.Seasons.Single(s => s.SeasonNumber == seasonNumber).Monitored = monitored;
|
||||
|
||||
Subject.UpdateSeries(_fakeSeries);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, seasonNumber, monitored), Times.Once());
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Once());
|
||||
}
|
||||
}
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class UpdateSeriesFixture : CoreTest<SeriesService>
|
||||
{
|
||||
private Series _fakeSeries;
|
||||
private Series _existingSeries;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_fakeSeries = Builder<Series>.CreateNew().Build();
|
||||
_existingSeries = Builder<Series>.CreateNew().Build();
|
||||
|
||||
_fakeSeries.Seasons = new List<Season>
|
||||
{
|
||||
new Season{ SeasonNumber = 1, Monitored = true },
|
||||
new Season{ SeasonNumber = 2, Monitored = true }
|
||||
};
|
||||
|
||||
_existingSeries.Seasons = new List<Season>
|
||||
{
|
||||
new Season{ SeasonNumber = 1, Monitored = true },
|
||||
new Season{ SeasonNumber = 2, Monitored = true }
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenExistingSeries()
|
||||
{
|
||||
Mocker.GetMock<ISeriesRepository>()
|
||||
.Setup(s => s.Get(It.IsAny<int>()))
|
||||
.Returns(_existingSeries);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_update_episodes_if_season_hasnt_changed()
|
||||
{
|
||||
GivenExistingSeries();
|
||||
|
||||
Subject.UpdateSeries(_fakeSeries);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, It.IsAny<int>(), It.IsAny<bool>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_series_when_it_changes()
|
||||
{
|
||||
GivenExistingSeries();
|
||||
var seasonNumber = 1;
|
||||
var monitored = false;
|
||||
|
||||
_fakeSeries.Seasons.Single(s => s.SeasonNumber == seasonNumber).Monitored = monitored;
|
||||
|
||||
Subject.UpdateSeries(_fakeSeries);
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Verify(v => v.SetEpisodeMonitoredBySeason(_fakeSeries.Id, seasonNumber, monitored), Times.Once());
|
||||
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.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
|
||||
{
|
||||
public class SabnzbdFullStatusResponse
|
||||
{
|
||||
public SabnzbdFullStatus Status { get; set; }
|
||||
}
|
||||
}
|
||||
namespace NzbDrone.Core.Download.Clients.Sabnzbd.Responses
|
||||
{
|
||||
public class SabnzbdFullStatusResponse
|
||||
{
|
||||
public SabnzbdFullStatus Status { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,93 +1,93 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using Nancy;
|
||||
using Nancy.Bootstrapper;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using Sonarr.Http.ErrorManagement;
|
||||
using Sonarr.Http.Extensions;
|
||||
using Sonarr.Http.Extensions.Pipelines;
|
||||
|
||||
namespace NzbDrone.Api.Extensions.Pipelines
|
||||
{
|
||||
public class RequestLoggingPipeline : IRegisterNancyPipeline
|
||||
{
|
||||
private static readonly Logger _loggerHttp = LogManager.GetLogger("Http");
|
||||
private static readonly Logger _loggerApi = LogManager.GetLogger("Api");
|
||||
|
||||
private static int _requestSequenceID;
|
||||
|
||||
private readonly SonarrErrorPipeline _errorPipeline;
|
||||
|
||||
public RequestLoggingPipeline(SonarrErrorPipeline errorPipeline)
|
||||
{
|
||||
_errorPipeline = errorPipeline;
|
||||
}
|
||||
|
||||
public int Order => 100;
|
||||
|
||||
public void Register(IPipelines pipelines)
|
||||
{
|
||||
pipelines.BeforeRequest.AddItemToStartOfPipeline(LogStart);
|
||||
pipelines.AfterRequest.AddItemToEndOfPipeline(LogEnd);
|
||||
pipelines.OnError.AddItemToEndOfPipeline(LogError);
|
||||
}
|
||||
|
||||
private Response LogStart(NancyContext context)
|
||||
{
|
||||
var id = Interlocked.Increment(ref _requestSequenceID);
|
||||
|
||||
context.Items["ApiRequestSequenceID"] = id;
|
||||
context.Items["ApiRequestStartTime"] = DateTime.UtcNow;
|
||||
|
||||
var reqPath = GetRequestPathAndQuery(context.Request);
|
||||
|
||||
_loggerHttp.Trace("Req: {0} [{1}] {2}", id, context.Request.Method, reqPath);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void LogEnd(NancyContext context)
|
||||
{
|
||||
var id = (int)context.Items["ApiRequestSequenceID"];
|
||||
var startTime = (DateTime)context.Items["ApiRequestStartTime"];
|
||||
|
||||
var endTime = DateTime.UtcNow;
|
||||
var duration = endTime - startTime;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private Response LogError(NancyContext context, Exception exception)
|
||||
{
|
||||
var response = _errorPipeline.HandleException(context, exception);
|
||||
|
||||
context.Response = response;
|
||||
|
||||
LogEnd(context);
|
||||
|
||||
context.Response = null;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private static string GetRequestPathAndQuery(Request request)
|
||||
{
|
||||
if (request.Url.Query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return string.Concat(request.Url.Path, request.Url.Query);
|
||||
}
|
||||
else
|
||||
{
|
||||
return request.Url.Path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Nancy;
|
||||
using Nancy.Bootstrapper;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using Sonarr.Http.ErrorManagement;
|
||||
using Sonarr.Http.Extensions;
|
||||
using Sonarr.Http.Extensions.Pipelines;
|
||||
|
||||
namespace NzbDrone.Api.Extensions.Pipelines
|
||||
{
|
||||
public class RequestLoggingPipeline : IRegisterNancyPipeline
|
||||
{
|
||||
private static readonly Logger _loggerHttp = LogManager.GetLogger("Http");
|
||||
private static readonly Logger _loggerApi = LogManager.GetLogger("Api");
|
||||
|
||||
private static int _requestSequenceID;
|
||||
|
||||
private readonly SonarrErrorPipeline _errorPipeline;
|
||||
|
||||
public RequestLoggingPipeline(SonarrErrorPipeline errorPipeline)
|
||||
{
|
||||
_errorPipeline = errorPipeline;
|
||||
}
|
||||
|
||||
public int Order => 100;
|
||||
|
||||
public void Register(IPipelines pipelines)
|
||||
{
|
||||
pipelines.BeforeRequest.AddItemToStartOfPipeline(LogStart);
|
||||
pipelines.AfterRequest.AddItemToEndOfPipeline(LogEnd);
|
||||
pipelines.OnError.AddItemToEndOfPipeline(LogError);
|
||||
}
|
||||
|
||||
private Response LogStart(NancyContext context)
|
||||
{
|
||||
var id = Interlocked.Increment(ref _requestSequenceID);
|
||||
|
||||
context.Items["ApiRequestSequenceID"] = id;
|
||||
context.Items["ApiRequestStartTime"] = DateTime.UtcNow;
|
||||
|
||||
var reqPath = GetRequestPathAndQuery(context.Request);
|
||||
|
||||
_loggerHttp.Trace("Req: {0} [{1}] {2}", id, context.Request.Method, reqPath);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void LogEnd(NancyContext context)
|
||||
{
|
||||
var id = (int)context.Items["ApiRequestSequenceID"];
|
||||
var startTime = (DateTime)context.Items["ApiRequestStartTime"];
|
||||
|
||||
var endTime = DateTime.UtcNow;
|
||||
var duration = endTime - startTime;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private Response LogError(NancyContext context, Exception exception)
|
||||
{
|
||||
var response = _errorPipeline.HandleException(context, exception);
|
||||
|
||||
context.Response = response;
|
||||
|
||||
LogEnd(context);
|
||||
|
||||
context.Response = null;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private static string GetRequestPathAndQuery(Request request)
|
||||
{
|
||||
if (request.Url.Query.IsNotNullOrWhiteSpace())
|
||||
{
|
||||
return string.Concat(request.Url.Path, request.Url.Query);
|
||||
}
|
||||
else
|
||||
{
|
||||
return request.Url.Path;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue