mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 13:10:13 -07:00
Fixed: Various Unit Tests Issues/Additions (#28)
Fixed: Various Unit Tests Issues/Additions
This commit is contained in:
parent
f4006515a5
commit
572586063e
13 changed files with 276 additions and 332 deletions
|
@ -0,0 +1,128 @@
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
using NzbDrone.Core.Qualities;
|
||||||
|
using NzbDrone.Core.ArtistStats;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.ArtistStatsTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class ArtistStatisticsFixture : DbTest<ArtistStatisticsRepository, Artist>
|
||||||
|
{
|
||||||
|
private Artist _artist;
|
||||||
|
private Album _album;
|
||||||
|
private Track _track;
|
||||||
|
private TrackFile _trackFile;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_artist = Builder<Artist>.CreateNew()
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
_album = Builder<Album>.CreateNew()
|
||||||
|
.With(e => e.ReleaseDate = DateTime.Today.AddDays(5))
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
_artist.Id = Db.Insert(_artist).Id;
|
||||||
|
_artist.Id = Db.Insert(_album).Id;
|
||||||
|
|
||||||
|
_track = Builder<Track>.CreateNew()
|
||||||
|
.With(e => e.TrackFileId = 0)
|
||||||
|
.With(e => e.Monitored = false)
|
||||||
|
.With(e => e.ArtistId = _artist.Id)
|
||||||
|
.With(e => e.AlbumId = _album.Id)
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
_trackFile = Builder<TrackFile>.CreateNew()
|
||||||
|
.With(e => e.ArtistId = _artist.Id)
|
||||||
|
.With(e => e.AlbumId = _album.Id)
|
||||||
|
.With(e => e.Quality = new QualityModel(Quality.MP3_256))
|
||||||
|
.BuildNew();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenTrackWithFile()
|
||||||
|
{
|
||||||
|
_track.TrackFileId = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenMonitoredTrack()
|
||||||
|
{
|
||||||
|
_track.Monitored = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenTrack()
|
||||||
|
{
|
||||||
|
Db.Insert(_track);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenTrackFile()
|
||||||
|
{
|
||||||
|
Db.Insert(_trackFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_get_stats_for_artist()
|
||||||
|
{
|
||||||
|
GivenMonitoredTrack();
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
|
var stats = Subject.ArtistStatistics();
|
||||||
|
|
||||||
|
stats.Should().HaveCount(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_include_unmonitored_track_in_track_count()
|
||||||
|
{
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
|
var stats = Subject.ArtistStatistics();
|
||||||
|
|
||||||
|
stats.Should().HaveCount(1);
|
||||||
|
stats.First().TrackCount.Should().Be(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_include_unmonitored_track_with_file_in_track_count()
|
||||||
|
{
|
||||||
|
GivenTrackWithFile();
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
|
var stats = Subject.ArtistStatistics();
|
||||||
|
|
||||||
|
stats.Should().HaveCount(1);
|
||||||
|
stats.First().TrackCount.Should().Be(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_have_size_on_disk_of_zero_when_no_track_file()
|
||||||
|
{
|
||||||
|
GivenTrack();
|
||||||
|
|
||||||
|
var stats = Subject.ArtistStatistics();
|
||||||
|
|
||||||
|
stats.Should().HaveCount(1);
|
||||||
|
stats.First().SizeOnDisk.Should().Be(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_have_size_on_disk_when_track_file_exists()
|
||||||
|
{
|
||||||
|
GivenTrack();
|
||||||
|
GivenTrackFile();
|
||||||
|
|
||||||
|
var stats = Subject.ArtistStatistics();
|
||||||
|
|
||||||
|
stats.Should().HaveCount(1);
|
||||||
|
stats.First().SizeOnDisk.Should().Be(_trackFile.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
131
src/NzbDrone.Core.Test/MusicTests/AddArtistFixture.cs
Normal file
131
src/NzbDrone.Core.Test/MusicTests/AddArtistFixture.cs
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using FluentValidation;
|
||||||
|
using FluentValidation.Results;
|
||||||
|
using Moq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Exceptions;
|
||||||
|
using NzbDrone.Core.MetadataSource;
|
||||||
|
using NzbDrone.Core.Organizer;
|
||||||
|
using NzbDrone.Core.Music;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.MusicTests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class AddArtistFixture : CoreTest<AddArtistService>
|
||||||
|
{
|
||||||
|
private Artist _fakeArtist;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void Setup()
|
||||||
|
{
|
||||||
|
_fakeArtist = Builder<Artist>
|
||||||
|
.CreateNew()
|
||||||
|
.With(s => s.Path = null)
|
||||||
|
.Build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenValidArtist(string lidarrId)
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IProvideArtistInfo>()
|
||||||
|
.Setup(s => s.GetArtistInfo(lidarrId))
|
||||||
|
.Returns(new Tuple<Artist, List<Album>>(_fakeArtist, new List<Album>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void GivenValidPath()
|
||||||
|
{
|
||||||
|
Mocker.GetMock<IBuildFileNames>()
|
||||||
|
.Setup(s => s.GetArtistFolder(It.IsAny<Artist>(), null))
|
||||||
|
.Returns<Artist, NamingConfig>((c, n) => c.Name);
|
||||||
|
|
||||||
|
Mocker.GetMock<IAddArtistValidator>()
|
||||||
|
.Setup(s => s.Validate(It.IsAny<Artist>()))
|
||||||
|
.Returns(new ValidationResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_be_able_to_add_a_artist_without_passing_in_name()
|
||||||
|
{
|
||||||
|
var newArtist = new Artist
|
||||||
|
{
|
||||||
|
ForeignArtistId = "123456",
|
||||||
|
RootFolderPath = @"C:\Test\Music"
|
||||||
|
};
|
||||||
|
|
||||||
|
GivenValidArtist(newArtist.ForeignArtistId);
|
||||||
|
GivenValidPath();
|
||||||
|
|
||||||
|
var artist = Subject.AddArtist(newArtist);
|
||||||
|
|
||||||
|
artist.Name.Should().Be(_fakeArtist.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_have_proper_path()
|
||||||
|
{
|
||||||
|
var newArtist = new Artist
|
||||||
|
{
|
||||||
|
ForeignArtistId = "123456",
|
||||||
|
RootFolderPath = @"C:\Test\Music"
|
||||||
|
};
|
||||||
|
|
||||||
|
GivenValidArtist(newArtist.ForeignArtistId);
|
||||||
|
GivenValidPath();
|
||||||
|
|
||||||
|
var artist = Subject.AddArtist(newArtist);
|
||||||
|
|
||||||
|
artist.Path.Should().Be(Path.Combine(newArtist.RootFolderPath, _fakeArtist.Name));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_throw_if_artist_validation_fails()
|
||||||
|
{
|
||||||
|
var newArtist = new Artist
|
||||||
|
{
|
||||||
|
ForeignArtistId = "123456",
|
||||||
|
Path = @"C:\Test\Music\Name1"
|
||||||
|
};
|
||||||
|
|
||||||
|
GivenValidArtist(newArtist.ForeignArtistId);
|
||||||
|
|
||||||
|
Mocker.GetMock<IAddArtistValidator>()
|
||||||
|
.Setup(s => s.Validate(It.IsAny<Artist>()))
|
||||||
|
.Returns(new ValidationResult(new List<ValidationFailure>
|
||||||
|
{
|
||||||
|
new ValidationFailure("Path", "Test validation failure")
|
||||||
|
}));
|
||||||
|
|
||||||
|
Assert.Throws<ValidationException>(() => Subject.AddArtist(newArtist));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_throw_if_artist_cannot_be_found()
|
||||||
|
{
|
||||||
|
var newArtist = new Artist
|
||||||
|
{
|
||||||
|
ForeignArtistId = "123456",
|
||||||
|
Path = @"C:\Test\Music\Name1"
|
||||||
|
};
|
||||||
|
|
||||||
|
Mocker.GetMock<IProvideArtistInfo>()
|
||||||
|
.Setup(s => s.GetArtistInfo(newArtist.ForeignArtistId))
|
||||||
|
.Throws(new ArtistNotFoundException(newArtist.ForeignArtistId));
|
||||||
|
|
||||||
|
Mocker.GetMock<IAddArtistValidator>()
|
||||||
|
.Setup(s => s.Validate(It.IsAny<Artist>()))
|
||||||
|
.Returns(new ValidationResult(new List<ValidationFailure>
|
||||||
|
{
|
||||||
|
new ValidationFailure("Path", "Test validation failure")
|
||||||
|
}));
|
||||||
|
|
||||||
|
Assert.Throws<ValidationException>(() => Subject.AddArtist(newArtist));
|
||||||
|
|
||||||
|
ExceptionVerification.ExpectedErrors(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -112,6 +112,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="ArtistStatsTests\ArtistStatisticsFixture.cs" />
|
||||||
<Compile Include="Blacklisting\BlacklistRepositoryFixture.cs" />
|
<Compile Include="Blacklisting\BlacklistRepositoryFixture.cs" />
|
||||||
<Compile Include="Blacklisting\BlacklistServiceFixture.cs" />
|
<Compile Include="Blacklisting\BlacklistServiceFixture.cs" />
|
||||||
<Compile Include="Configuration\ConfigCachingFixture.cs" />
|
<Compile Include="Configuration\ConfigCachingFixture.cs" />
|
||||||
|
@ -296,6 +297,7 @@
|
||||||
<Compile Include="MetadataSource\SkyHook\SkyHookProxySearchFixture.cs" />
|
<Compile Include="MetadataSource\SkyHook\SkyHookProxySearchFixture.cs" />
|
||||||
<Compile Include="MetadataSource\SearchSeriesComparerFixture.cs" />
|
<Compile Include="MetadataSource\SearchSeriesComparerFixture.cs" />
|
||||||
<Compile Include="MetadataSource\SkyHook\SkyHookProxyFixture.cs" />
|
<Compile Include="MetadataSource\SkyHook\SkyHookProxyFixture.cs" />
|
||||||
|
<Compile Include="MusicTests\AddArtistFixture.cs" />
|
||||||
<Compile Include="NotificationTests\NotificationBaseFixture.cs" />
|
<Compile Include="NotificationTests\NotificationBaseFixture.cs" />
|
||||||
<Compile Include="NotificationTests\SynologyIndexerFixture.cs" />
|
<Compile Include="NotificationTests\SynologyIndexerFixture.cs" />
|
||||||
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />
|
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />
|
||||||
|
@ -366,7 +368,6 @@
|
||||||
<Compile Include="Qualities\QualityFixture.cs" />
|
<Compile Include="Qualities\QualityFixture.cs" />
|
||||||
<Compile Include="Qualities\QualityModelComparerFixture.cs" />
|
<Compile Include="Qualities\QualityModelComparerFixture.cs" />
|
||||||
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
|
<Compile Include="RootFolderTests\RootFolderServiceFixture.cs" />
|
||||||
<Compile Include="SeriesStatsTests\SeriesStatisticsFixture.cs" />
|
|
||||||
<Compile Include="ThingiProvider\ProviderBaseFixture.cs" />
|
<Compile Include="ThingiProvider\ProviderBaseFixture.cs" />
|
||||||
<Compile Include="ThingiProviderTests\NullConfigFixture.cs" />
|
<Compile Include="ThingiProviderTests\NullConfigFixture.cs" />
|
||||||
<Compile Include="TvTests\EpisodeServiceTests\FindEpisodeByTitleFixture.cs" />
|
<Compile Include="TvTests\EpisodeServiceTests\FindEpisodeByTitleFixture.cs" />
|
||||||
|
@ -383,7 +384,6 @@
|
||||||
<Compile Include="TvTests\RefreshSeriesServiceFixture.cs" />
|
<Compile Include="TvTests\RefreshSeriesServiceFixture.cs" />
|
||||||
<Compile Include="TvTests\EpisodeMonitoredServiceTests\SetEpisodeMontitoredFixture.cs" />
|
<Compile Include="TvTests\EpisodeMonitoredServiceTests\SetEpisodeMontitoredFixture.cs" />
|
||||||
<Compile Include="TvTests\SeriesRepositoryTests\SeriesRepositoryFixture.cs" />
|
<Compile Include="TvTests\SeriesRepositoryTests\SeriesRepositoryFixture.cs" />
|
||||||
<Compile Include="TvTests\AddSeriesFixture.cs" />
|
|
||||||
<Compile Include="TvTests\SeriesServiceTests\UpdateMultipleSeriesFixture.cs" />
|
<Compile Include="TvTests\SeriesServiceTests\UpdateMultipleSeriesFixture.cs" />
|
||||||
<Compile Include="TvTests\SeriesServiceTests\UpdateSeriesFixture.cs" />
|
<Compile Include="TvTests\SeriesServiceTests\UpdateSeriesFixture.cs" />
|
||||||
<Compile Include="TvTests\SeriesTitleNormalizerFixture.cs" />
|
<Compile Include="TvTests\SeriesTitleNormalizerFixture.cs" />
|
||||||
|
|
|
@ -1,182 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Linq;
|
|
||||||
using FizzWare.NBuilder;
|
|
||||||
using FluentAssertions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.MediaFiles;
|
|
||||||
using NzbDrone.Core.Qualities;
|
|
||||||
using NzbDrone.Core.SeriesStats;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
using NzbDrone.Core.Tv;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.SeriesStatsTests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class SeriesStatisticsFixture : DbTest<SeriesStatisticsRepository, Series>
|
|
||||||
{
|
|
||||||
private Series _series;
|
|
||||||
private Episode _episode;
|
|
||||||
private EpisodeFile _episodeFile;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
_series = Builder<Series>.CreateNew()
|
|
||||||
.With(s => s.Runtime = 30)
|
|
||||||
.BuildNew();
|
|
||||||
|
|
||||||
_series.Id = Db.Insert(_series).Id;
|
|
||||||
|
|
||||||
_episode = Builder<Episode>.CreateNew()
|
|
||||||
.With(e => e.EpisodeFileId = 0)
|
|
||||||
.With(e => e.Monitored = false)
|
|
||||||
.With(e => e.SeriesId = _series.Id)
|
|
||||||
.With(e => e.AirDateUtc = DateTime.Today.AddDays(5))
|
|
||||||
.BuildNew();
|
|
||||||
|
|
||||||
_episodeFile = Builder<EpisodeFile>.CreateNew()
|
|
||||||
.With(e => e.SeriesId = _series.Id)
|
|
||||||
.With(e => e.Quality = new QualityModel(Quality.MP3_256))
|
|
||||||
.BuildNew();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenEpisodeWithFile()
|
|
||||||
{
|
|
||||||
_episode.EpisodeFileId = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenOldEpisode()
|
|
||||||
{
|
|
||||||
_episode.AirDateUtc = DateTime.Now.AddSeconds(-10);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenMonitoredEpisode()
|
|
||||||
{
|
|
||||||
_episode.Monitored = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenEpisode()
|
|
||||||
{
|
|
||||||
Db.Insert(_episode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenEpisodeFile()
|
|
||||||
{
|
|
||||||
Db.Insert(_episodeFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_get_stats_for_series()
|
|
||||||
{
|
|
||||||
GivenMonitoredEpisode();
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().NextAiring.Should().Be(_episode.AirDateUtc);
|
|
||||||
stats.First().PreviousAiring.Should().NotHaveValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_have_next_airing_for_episode_with_file()
|
|
||||||
{
|
|
||||||
GivenEpisodeWithFile();
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().NextAiring.Should().NotHaveValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_have_previous_airing_for_old_episode_with_file()
|
|
||||||
{
|
|
||||||
GivenEpisodeWithFile();
|
|
||||||
GivenOldEpisode();
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().NextAiring.Should().NotHaveValue();
|
|
||||||
stats.First().PreviousAiring.Should().Be(_episode.AirDateUtc);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_have_previous_airing_for_old_episode_without_file_monitored()
|
|
||||||
{
|
|
||||||
GivenMonitoredEpisode();
|
|
||||||
GivenOldEpisode();
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().NextAiring.Should().NotHaveValue();
|
|
||||||
stats.First().PreviousAiring.Should().Be(_episode.AirDateUtc);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_have_previous_airing_for_old_episode_without_file_unmonitored()
|
|
||||||
{
|
|
||||||
GivenOldEpisode();
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().NextAiring.Should().NotHaveValue();
|
|
||||||
stats.First().PreviousAiring.Should().NotHaveValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_not_include_unmonitored_episode_in_episode_count()
|
|
||||||
{
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().EpisodeCount.Should().Be(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_include_unmonitored_episode_with_file_in_episode_count()
|
|
||||||
{
|
|
||||||
GivenEpisodeWithFile();
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().EpisodeCount.Should().Be(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_have_size_on_disk_of_zero_when_no_episode_file()
|
|
||||||
{
|
|
||||||
GivenEpisode();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().SizeOnDisk.Should().Be(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_have_size_on_disk_when_episode_file_exists()
|
|
||||||
{
|
|
||||||
GivenEpisode();
|
|
||||||
GivenEpisodeFile();
|
|
||||||
|
|
||||||
var stats = Subject.SeriesStatistics();
|
|
||||||
|
|
||||||
stats.Should().HaveCount(1);
|
|
||||||
stats.First().SizeOnDisk.Should().Be(_episodeFile.Size);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,132 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using FizzWare.NBuilder;
|
|
||||||
using FluentAssertions;
|
|
||||||
using FluentValidation;
|
|
||||||
using FluentValidation.Results;
|
|
||||||
using Moq;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using NzbDrone.Core.Exceptions;
|
|
||||||
using NzbDrone.Core.MetadataSource;
|
|
||||||
using NzbDrone.Core.Organizer;
|
|
||||||
using NzbDrone.Core.Tv;
|
|
||||||
using NzbDrone.Core.Test.Framework;
|
|
||||||
using NzbDrone.Core.Tv.Events;
|
|
||||||
using NzbDrone.Test.Common;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.TvTests
|
|
||||||
{
|
|
||||||
[TestFixture]
|
|
||||||
public class AddSeriesFixture : CoreTest<AddSeriesService>
|
|
||||||
{
|
|
||||||
private Series _fakeSeries;
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void Setup()
|
|
||||||
{
|
|
||||||
_fakeSeries = Builder<Series>
|
|
||||||
.CreateNew()
|
|
||||||
.With(s => s.Path = null)
|
|
||||||
.Build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenValidSeries(int tvdbId)
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IProvideSeriesInfo>()
|
|
||||||
.Setup(s => s.GetSeriesInfo(tvdbId))
|
|
||||||
.Returns(new Tuple<Series, List<Episode>>(_fakeSeries, new List<Episode>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void GivenValidPath()
|
|
||||||
{
|
|
||||||
Mocker.GetMock<IBuildFileNames>()
|
|
||||||
.Setup(s => s.GetSeriesFolder(It.IsAny<Series>(), null))
|
|
||||||
.Returns<Series, NamingConfig>((c, n) => c.Title);
|
|
||||||
|
|
||||||
Mocker.GetMock<IAddSeriesValidator>()
|
|
||||||
.Setup(s => s.Validate(It.IsAny<Series>()))
|
|
||||||
.Returns(new ValidationResult());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_be_able_to_add_a_series_without_passing_in_title()
|
|
||||||
{
|
|
||||||
var newSeries = new Series
|
|
||||||
{
|
|
||||||
TvdbId = 1,
|
|
||||||
RootFolderPath = @"C:\Test\TV"
|
|
||||||
};
|
|
||||||
|
|
||||||
GivenValidSeries(newSeries.TvdbId);
|
|
||||||
GivenValidPath();
|
|
||||||
|
|
||||||
var series = Subject.AddSeries(newSeries);
|
|
||||||
|
|
||||||
series.Title.Should().Be(_fakeSeries.Title);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_have_proper_path()
|
|
||||||
{
|
|
||||||
var newSeries = new Series
|
|
||||||
{
|
|
||||||
TvdbId = 1,
|
|
||||||
RootFolderPath = @"C:\Test\TV"
|
|
||||||
};
|
|
||||||
|
|
||||||
GivenValidSeries(newSeries.TvdbId);
|
|
||||||
GivenValidPath();
|
|
||||||
|
|
||||||
var series = Subject.AddSeries(newSeries);
|
|
||||||
|
|
||||||
series.Path.Should().Be(Path.Combine(newSeries.RootFolderPath, _fakeSeries.Title));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_throw_if_series_validation_fails()
|
|
||||||
{
|
|
||||||
var newSeries = new Series
|
|
||||||
{
|
|
||||||
TvdbId = 1,
|
|
||||||
Path = @"C:\Test\TV\Title1"
|
|
||||||
};
|
|
||||||
|
|
||||||
GivenValidSeries(newSeries.TvdbId);
|
|
||||||
|
|
||||||
Mocker.GetMock<IAddSeriesValidator>()
|
|
||||||
.Setup(s => s.Validate(It.IsAny<Series>()))
|
|
||||||
.Returns(new ValidationResult(new List<ValidationFailure>
|
|
||||||
{
|
|
||||||
new ValidationFailure("Path", "Test validation failure")
|
|
||||||
}));
|
|
||||||
|
|
||||||
Assert.Throws<ValidationException>(() => Subject.AddSeries(newSeries));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void should_throw_if_series_cannot_be_found()
|
|
||||||
{
|
|
||||||
var newSeries = new Series
|
|
||||||
{
|
|
||||||
TvdbId = 1,
|
|
||||||
Path = @"C:\Test\TV\Title1"
|
|
||||||
};
|
|
||||||
|
|
||||||
Mocker.GetMock<IProvideSeriesInfo>()
|
|
||||||
.Setup(s => s.GetSeriesInfo(newSeries.TvdbId))
|
|
||||||
.Throws(new SeriesNotFoundException(newSeries.TvdbId));
|
|
||||||
|
|
||||||
Mocker.GetMock<IAddSeriesValidator>()
|
|
||||||
.Setup(s => s.Validate(It.IsAny<Series>()))
|
|
||||||
.Returns(new ValidationResult(new List<ValidationFailure>
|
|
||||||
{
|
|
||||||
new ValidationFailure("Path", "Test validation failure")
|
|
||||||
}));
|
|
||||||
|
|
||||||
Assert.Throws<ValidationException>(() => Subject.AddSeries(newSeries));
|
|
||||||
|
|
||||||
ExceptionVerification.ExpectedErrors(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace NzbDrone.Core.MetadataSource.SkyHook
|
namespace NzbDrone.Core.MetadataSource
|
||||||
{
|
{
|
||||||
public interface IProvideArtistInfo
|
public interface IProvideArtistInfo
|
||||||
{
|
{
|
||||||
|
|
|
@ -206,7 +206,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook
|
||||||
var lowerTitle = title.ToLowerInvariant();
|
var lowerTitle = title.ToLowerInvariant();
|
||||||
Console.WriteLine("Searching for " + lowerTitle);
|
Console.WriteLine("Searching for " + lowerTitle);
|
||||||
|
|
||||||
if (lowerTitle.StartsWith("spotify:") || lowerTitle.StartsWith("spotifyid:"))
|
if (lowerTitle.StartsWith("lidarr:") || lowerTitle.StartsWith("lidarrid:"))
|
||||||
{
|
{
|
||||||
var slug = lowerTitle.Split(':')[1].Trim();
|
var slug = lowerTitle.Split(':')[1].Trim();
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace NzbDrone.Core.Music
|
||||||
Artist AddArtist(Artist newArtist);
|
Artist AddArtist(Artist newArtist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AddSeriesService : IAddArtistService
|
public class AddArtistService : IAddArtistService
|
||||||
{
|
{
|
||||||
private readonly IArtistService _artistService;
|
private readonly IArtistService _artistService;
|
||||||
private readonly IProvideArtistInfo _artistInfo;
|
private readonly IProvideArtistInfo _artistInfo;
|
||||||
|
@ -27,7 +27,7 @@ namespace NzbDrone.Core.Music
|
||||||
private readonly IAddArtistValidator _addArtistValidator;
|
private readonly IAddArtistValidator _addArtistValidator;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public AddSeriesService(IArtistService artistService,
|
public AddArtistService(IArtistService artistService,
|
||||||
IProvideArtistInfo artistInfo,
|
IProvideArtistInfo artistInfo,
|
||||||
IBuildFileNames fileNameBuilder,
|
IBuildFileNames fileNameBuilder,
|
||||||
IAddArtistValidator addArtistValidator,
|
IAddArtistValidator addArtistValidator,
|
||||||
|
|
|
@ -5,7 +5,7 @@ using NzbDrone.Core.Exceptions;
|
||||||
using NzbDrone.Core.MediaFiles;
|
using NzbDrone.Core.MediaFiles;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.MetadataSource.SkyHook;
|
using NzbDrone.Core.MetadataSource;
|
||||||
using NzbDrone.Core.Music.Commands;
|
using NzbDrone.Core.Music.Commands;
|
||||||
using NzbDrone.Core.Music.Events;
|
using NzbDrone.Core.Music.Events;
|
||||||
using System;
|
using System;
|
||||||
|
|
|
@ -12,10 +12,10 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||||
[Test, Order(0)]
|
[Test, Order(0)]
|
||||||
public void add_artist_with_tags_should_store_them()
|
public void add_artist_with_tags_should_store_them()
|
||||||
{
|
{
|
||||||
EnsureNoArtsit("266189", "Alien Ant Farm");
|
EnsureNoArtist("266189", "Alien Ant Farm");
|
||||||
var tag = EnsureTag("abc");
|
var tag = EnsureTag("abc");
|
||||||
|
|
||||||
var artist = Artist.Lookup("266189").Single();
|
var artist = Artist.Lookup("lidarr:266189").Single();
|
||||||
|
|
||||||
artist.ProfileId = 1;
|
artist.ProfileId = 1;
|
||||||
artist.Path = Path.Combine(ArtistRootFolder, artist.Name);
|
artist.Path = Path.Combine(ArtistRootFolder, artist.Name);
|
||||||
|
@ -31,9 +31,9 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||||
[Test, Order(0)]
|
[Test, Order(0)]
|
||||||
public void add_artist_without_profileid_should_return_badrequest()
|
public void add_artist_without_profileid_should_return_badrequest()
|
||||||
{
|
{
|
||||||
EnsureNoArtsit("266189", "Alien Ant Farm");
|
EnsureNoArtist("266189", "Alien Ant Farm");
|
||||||
|
|
||||||
var artist = Artist.Lookup("tvdb:266189").Single();
|
var artist = Artist.Lookup("lidarr:266189").Single();
|
||||||
|
|
||||||
artist.Path = Path.Combine(ArtistRootFolder, artist.Name);
|
artist.Path = Path.Combine(ArtistRootFolder, artist.Name);
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||||
[Test, Order(0)]
|
[Test, Order(0)]
|
||||||
public void add_artist_without_path_should_return_badrequest()
|
public void add_artist_without_path_should_return_badrequest()
|
||||||
{
|
{
|
||||||
EnsureNoArtsit("266189", "Alien Ant Farm");
|
EnsureNoArtist("266189", "Alien Ant Farm");
|
||||||
|
|
||||||
var artist = Artist.Lookup("lidarr:266189").Single();
|
var artist = Artist.Lookup("lidarr:266189").Single();
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||||
[Test, Order(1)]
|
[Test, Order(1)]
|
||||||
public void add_artist()
|
public void add_artist()
|
||||||
{
|
{
|
||||||
EnsureNoArtsit("266189", "Alien Ant Farm");
|
EnsureNoArtist("266189", "Alien Ant Farm");
|
||||||
|
|
||||||
var artist = Artist.Lookup("lidarr:266189").Single();
|
var artist = Artist.Lookup("lidarr:266189").Single();
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||||
[Test]
|
[Test]
|
||||||
public void lookup_new_series_by_tvdbid()
|
public void lookup_new_series_by_tvdbid()
|
||||||
{
|
{
|
||||||
var artist = Artist.Lookup("tvdb:266189");
|
var artist = Artist.Lookup("lidarr:266189");
|
||||||
|
|
||||||
artist.Should().NotBeEmpty();
|
artist.Should().NotBeEmpty();
|
||||||
artist.Should().Contain(c => c.Name == "The Blacklist");
|
artist.Should().Contain(c => c.Name == "The Blacklist");
|
||||||
|
|
|
@ -11,7 +11,7 @@ namespace NzbDrone.Integration.Test.ApiTests
|
||||||
[Test, Order(0)]
|
[Test, Order(0)]
|
||||||
public void missing_should_be_empty()
|
public void missing_should_be_empty()
|
||||||
{
|
{
|
||||||
EnsureNoArtsit("266189", "The Blacklist");
|
EnsureNoArtist("266189", "The Blacklist");
|
||||||
|
|
||||||
var result = WantedMissing.GetPaged(0, 15, "releaseDate", "desc");
|
var result = WantedMissing.GetPaged(0, 15, "releaseDate", "desc");
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ using NzbDrone.Api.Blacklist;
|
||||||
using NzbDrone.Api.Commands;
|
using NzbDrone.Api.Commands;
|
||||||
using NzbDrone.Api.Config;
|
using NzbDrone.Api.Config;
|
||||||
using NzbDrone.Api.DownloadClient;
|
using NzbDrone.Api.DownloadClient;
|
||||||
using NzbDrone.Api.EpisodeFiles;
|
|
||||||
using NzbDrone.Api.TrackFiles;
|
using NzbDrone.Api.TrackFiles;
|
||||||
using NzbDrone.Api.Episodes;
|
using NzbDrone.Api.Episodes;
|
||||||
using NzbDrone.Api.History;
|
using NzbDrone.Api.History;
|
||||||
|
@ -205,7 +204,7 @@ namespace NzbDrone.Integration.Test
|
||||||
Assert.Fail("Timed on wait");
|
Assert.Fail("Timed on wait");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArtistResource EnsureArtist(string lidarrId, string artsitName, bool? monitored = null)
|
public ArtistResource EnsureArtist(string lidarrId, string artistName, bool? monitored = null)
|
||||||
{
|
{
|
||||||
var result = Artist.All().FirstOrDefault(v => v.ForeignArtistId == lidarrId);
|
var result = Artist.All().FirstOrDefault(v => v.ForeignArtistId == lidarrId);
|
||||||
|
|
||||||
|
@ -252,7 +251,7 @@ namespace NzbDrone.Integration.Test
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void EnsureNoArtsit(string lidarrId, string artistTitle)
|
public void EnsureNoArtist(string lidarrId, string artistTitle)
|
||||||
{
|
{
|
||||||
var result = Artist.All().FirstOrDefault(v => v.ForeignArtistId == lidarrId);
|
var result = Artist.All().FirstOrDefault(v => v.ForeignArtistId == lidarrId);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue