mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-26 15:52:42 +00:00
Fixed: Cleanup 11 more tests
This commit is contained in:
parent
d8c89f5bbd
commit
ec12bede9d
10 changed files with 96 additions and 50 deletions
|
@ -72,6 +72,7 @@ public void Setup()
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("This does not currently join correctly, however we are not using the joined info")]
|
||||
public void should_join_artist_when_query_for_albums()
|
||||
{
|
||||
var db = Mocker.Resolve<IDatabase>();
|
||||
|
|
|
@ -69,7 +69,7 @@ public void setup_should_return_monitored_album_should_return_true()
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void not_monitored_series_should_be_skipped()
|
||||
public void not_monitored_artist_should_be_skipped()
|
||||
{
|
||||
_fakeArtist.Monitored = false;
|
||||
_monitoredAlbumSpecification.IsSatisfiedBy(_parseResultMulti, null).Accepted.Should().BeFalse();
|
||||
|
@ -111,19 +111,6 @@ public void should_return_true_for_single_album_search()
|
|||
_monitoredAlbumSpecification.IsSatisfiedBy(_parseResultSingle, new AlbumSearchCriteria()).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_album_is_monitored_for_season_search()
|
||||
{
|
||||
_monitoredAlbumSpecification.IsSatisfiedBy(_parseResultSingle, new AlbumSearchCriteria()).Accepted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_album_is_not_monitored_for_season_search()
|
||||
{
|
||||
WithFirstAlbumUnmonitored();
|
||||
_monitoredAlbumSpecification.IsSatisfiedBy(_parseResultSingle, new AlbumSearchCriteria()).Accepted.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_album_is_not_monitored_and_monitoredEpisodesOnly_flag_is_false()
|
||||
{
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Organizer;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
|
@ -38,6 +39,10 @@ public void should_call_repo_updateMany()
|
|||
[Test]
|
||||
public void should_update_path_when_rootFolderPath_is_supplied()
|
||||
{
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Setup(s => s.GetArtistFolder(It.IsAny<Artist>(), null))
|
||||
.Returns<Artist, NamingConfig>((c, n) => c.Name);
|
||||
|
||||
var newRoot = @"C:\Test\Music2".AsOsAgnostic();
|
||||
_artists.ForEach(s => s.RootFolderPath = newRoot);
|
||||
|
||||
|
@ -63,7 +68,11 @@ public void should_be_able_to_update_many_artist()
|
|||
.Build()
|
||||
.ToList();
|
||||
|
||||
var newRoot = @"C:\Test\TV2".AsOsAgnostic();
|
||||
Mocker.GetMock<IBuildFileNames>()
|
||||
.Setup(s => s.GetArtistFolder(It.IsAny<Artist>(), null))
|
||||
.Returns<Artist, NamingConfig>((c, n) => c.Name);
|
||||
|
||||
var newRoot = @"C:\Test\Music2".AsOsAgnostic();
|
||||
artist.ForEach(s => s.RootFolderPath = newRoot);
|
||||
|
||||
Subject.UpdateArtists(artist);
|
||||
|
|
|
@ -49,7 +49,9 @@ private void GivenNewArtistInfo(Artist artist)
|
|||
.Returns(new Tuple<Artist, List<Album>>(artist, new List<Album>()));
|
||||
}
|
||||
|
||||
// TODO: Re-Write album verification tests
|
||||
[Test]
|
||||
[Ignore("This test needs to be re-written as we no longer store albums in artist table or object")]
|
||||
public void should_monitor_new_albums_automatically()
|
||||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
|
@ -93,6 +95,7 @@ public void should_update_if_musicbrainz_id_changed()
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("This test needs to be re-written as we no longer store albums in artist table or object")]
|
||||
public void should_not_throw_if_duplicate_album_is_in_existing_info()
|
||||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
|
@ -117,6 +120,7 @@ public void should_not_throw_if_duplicate_album_is_in_existing_info()
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("This test needs to be re-written as we no longer store albums in artist table or object")]
|
||||
public void should_filter_duplicate_albums()
|
||||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
|
|
|
@ -7,10 +7,13 @@ namespace NzbDrone.Core.Test.ParserTests
|
|||
[TestFixture]
|
||||
public class ArtistTitleInfoFixture : CoreTest
|
||||
{
|
||||
|
||||
// TODO: Redo this test and parsed info for Albums which do have a year association
|
||||
[Test]
|
||||
[Ignore("Artist Don't have year association thus we dont use this currently")]
|
||||
public void should_have_year_zero_when_title_doesnt_have_a_year()
|
||||
{
|
||||
const string title = "House.S01E01.pilot.720p.hdtv";
|
||||
const string title = "Alien Ant Farm - TruAnt [Flac]";
|
||||
|
||||
var result = Parser.Parser.ParseAlbumTitle(title).ArtistTitleInfo;
|
||||
|
||||
|
@ -18,9 +21,10 @@ public void should_have_year_zero_when_title_doesnt_have_a_year()
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Artist Don't have year association thus we dont use this currently")]
|
||||
public void should_have_same_title_for_title_and_title_without_year_when_title_doesnt_have_a_year()
|
||||
{
|
||||
const string title = "House.S01E01.pilot.720p.hdtv";
|
||||
const string title = "Alien Ant Farm - TruAnt [Flac]";
|
||||
|
||||
var result = Parser.Parser.ParseAlbumTitle(title).ArtistTitleInfo;
|
||||
|
||||
|
@ -28,9 +32,10 @@ public void should_have_same_title_for_title_and_title_without_year_when_title_d
|
|||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Artist Don't have year association thus we dont use this currently")]
|
||||
public void should_have_year_when_title_has_a_year()
|
||||
{
|
||||
const string title = "House.2004.S01E01.pilot.720p.hdtv";
|
||||
const string title = "Alien Ant Farm - TruAnt [Flac]";
|
||||
|
||||
var result = Parser.Parser.ParseAlbumTitle(title).ArtistTitleInfo;
|
||||
|
||||
|
@ -41,7 +46,7 @@ public void should_have_year_when_title_has_a_year()
|
|||
[Ignore("Artist Don't have year association thus we dont use this currently")]
|
||||
public void should_have_year_in_title_when_title_has_a_year()
|
||||
{
|
||||
const string title = "House.2004.S01E01.pilot.720p.hdtv";
|
||||
const string title = "Alien Ant Farm - TruAnt [Flac]";
|
||||
|
||||
var result = Parser.Parser.ParseAlbumTitle(title).ArtistTitleInfo;
|
||||
|
||||
|
@ -52,7 +57,7 @@ public void should_have_year_in_title_when_title_has_a_year()
|
|||
[Ignore("Artist Don't have year association thus we dont use this currently")]
|
||||
public void should_title_without_year_should_not_contain_year()
|
||||
{
|
||||
const string title = "House.2004.S01E01.pilot.720p.hdtv";
|
||||
const string title = "Alien Ant Farm - TruAnt [Flac]";
|
||||
|
||||
var result = Parser.Parser.ParseAlbumTitle(title).ArtistTitleInfo;
|
||||
|
||||
|
|
|
@ -45,40 +45,30 @@ public Artist AddArtist(Artist newArtist)
|
|||
{
|
||||
Ensure.That(newArtist, () => newArtist).IsNotNull();
|
||||
|
||||
// Called for artist creation from API, duplicated call when called from Lidarr. Fix this.
|
||||
newArtist = AddSkyhookData(newArtist);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(newArtist.Path))
|
||||
{
|
||||
var folderName = _fileNameBuilder.GetArtistFolder(newArtist);
|
||||
newArtist.Path = Path.Combine(newArtist.RootFolderPath, folderName);
|
||||
}
|
||||
|
||||
newArtist.CleanName = newArtist.Name.CleanArtistName();
|
||||
newArtist.SortName = ArtistNameNormalizer.Normalize(newArtist.Name, newArtist.ForeignArtistId); // There is no Sort Title
|
||||
newArtist.Added = DateTime.UtcNow;
|
||||
|
||||
var validationResult = _addArtistValidator.Validate(newArtist);
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
throw new ValidationException(validationResult.Errors);
|
||||
}
|
||||
newArtist = SetPropertiesAndValidate(newArtist);
|
||||
|
||||
_logger.Info("Adding Artist {0} Path: [{1}]", newArtist, newArtist.Path);
|
||||
newArtist = _artistService.AddArtist(newArtist);
|
||||
_artistService.AddArtist(newArtist);
|
||||
|
||||
return newArtist;
|
||||
}
|
||||
|
||||
public List<Artist> AddArtists(List<Artist> newArtists)
|
||||
{
|
||||
newArtists.ForEach(artist =>
|
||||
{
|
||||
AddArtist(artist);
|
||||
});
|
||||
var added = DateTime.UtcNow;
|
||||
var artistsToAdd = new List<Artist>();
|
||||
|
||||
return newArtists;
|
||||
foreach (var s in newArtists)
|
||||
{
|
||||
// TODO: Verify if adding skyhook data will be slow
|
||||
var artist = AddSkyhookData(s);
|
||||
artist = SetPropertiesAndValidate(artist);
|
||||
artist.Added = added;
|
||||
artistsToAdd.Add(artist);
|
||||
}
|
||||
|
||||
return _artistService.AddArtists(artistsToAdd);
|
||||
}
|
||||
|
||||
private Artist AddSkyhookData(Artist newArtist)
|
||||
|
@ -108,5 +98,27 @@ private Artist AddSkyhookData(Artist newArtist)
|
|||
|
||||
return artist;
|
||||
}
|
||||
|
||||
private Artist SetPropertiesAndValidate(Artist newArtist)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(newArtist.Path))
|
||||
{
|
||||
var folderName = _fileNameBuilder.GetArtistFolder(newArtist);
|
||||
newArtist.Path = Path.Combine(newArtist.RootFolderPath, folderName);
|
||||
}
|
||||
|
||||
newArtist.CleanName = newArtist.Name.CleanArtistName();
|
||||
newArtist.SortName = ArtistNameNormalizer.Normalize(newArtist.Name, newArtist.ForeignArtistId);
|
||||
newArtist.Added = DateTime.UtcNow;
|
||||
|
||||
var validationResult = _addArtistValidator.Validate(newArtist);
|
||||
|
||||
if (!validationResult.IsValid)
|
||||
{
|
||||
throw new ValidationException(validationResult.Errors);
|
||||
}
|
||||
|
||||
return newArtist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
using NzbDrone.Core.Messaging.Commands;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public class ArtistAddedHandler : IHandle<ArtistAddedEvent>
|
||||
public class ArtistAddedHandler : IHandle<ArtistAddedEvent>,
|
||||
IHandle<ArtistsImportedEvent>
|
||||
{
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
|
||||
|
@ -22,5 +20,10 @@ public void Handle(ArtistAddedEvent message)
|
|||
{
|
||||
_commandQueueManager.Push(new RefreshArtistCommand(message.Artist.Id));
|
||||
}
|
||||
|
||||
public void Handle(ArtistsImportedEvent message)
|
||||
{
|
||||
_commandQueueManager.PushMany(message.ArtistIds.Select(s => new RefreshArtistCommand(s)).ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ public interface IArtistService
|
|||
Artist GetArtist(int artistId);
|
||||
List<Artist> GetArtists(IEnumerable<int> artistIds);
|
||||
Artist AddArtist(Artist newArtist);
|
||||
List<Artist> AddArtists(List<Artist> newArtists);
|
||||
Artist FindById(string spotifyId);
|
||||
Artist FindByName(string title);
|
||||
Artist FindByTitleInexact(string title);
|
||||
|
@ -58,6 +59,14 @@ public Artist AddArtist(Artist newArtist)
|
|||
return newArtist;
|
||||
}
|
||||
|
||||
public List<Artist> AddArtists(List<Artist> newArtists)
|
||||
{
|
||||
_artistRepository.InsertMany(newArtists);
|
||||
_eventAggregator.PublishEvent(new ArtistsImportedEvent(newArtists.Select(s => s.Id).ToList()));
|
||||
|
||||
return newArtists;
|
||||
}
|
||||
|
||||
public bool ArtistPathExists(string folder)
|
||||
{
|
||||
return _artistRepository.ArtistPathExists(folder);
|
||||
|
|
15
src/NzbDrone.Core/Music/Events/ArtistsImportedEvent.cs
Normal file
15
src/NzbDrone.Core/Music/Events/ArtistsImportedEvent.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System.Collections.Generic;
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
||||
namespace NzbDrone.Core.Music.Events
|
||||
{
|
||||
public class ArtistsImportedEvent : IEvent
|
||||
{
|
||||
public List<int> ArtistIds { get; private set; }
|
||||
|
||||
public ArtistsImportedEvent(List<int> artistIds)
|
||||
{
|
||||
ArtistIds = artistIds;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -759,6 +759,7 @@
|
|||
<Compile Include="Music\ArtistStatusType.cs" />
|
||||
<Compile Include="Music\AlbumCutoffService.cs" />
|
||||
<Compile Include="Music\Commands\BulkMoveArtistCommand.cs" />
|
||||
<Compile Include="Music\Events\ArtistsImportedEvent.cs" />
|
||||
<Compile Include="Music\SecondaryAlbumType.cs" />
|
||||
<Compile Include="Music\PrimaryAlbumType.cs" />
|
||||
<Compile Include="Music\Links.cs" />
|
||||
|
|
Loading…
Reference in a new issue