Fixed: Cleanup 11 more tests

This commit is contained in:
Qstick 2017-12-30 01:09:10 -05:00
parent d8c89f5bbd
commit ec12bede9d
10 changed files with 96 additions and 50 deletions

View File

@ -72,6 +72,7 @@ namespace NzbDrone.Core.Test.Datastore
}
[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>();

View File

@ -69,7 +69,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
}
[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 @@ namespace NzbDrone.Core.Test.DecisionEngineTests
_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()
{

View File

@ -5,6 +5,7 @@ using FluentAssertions;
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 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistServiceTests
[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 @@ namespace NzbDrone.Core.Test.MusicTests.ArtistServiceTests
.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);

View File

@ -49,7 +49,9 @@ namespace NzbDrone.Core.Test.MusicTests
.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 @@ namespace NzbDrone.Core.Test.MusicTests
}
[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 @@ namespace NzbDrone.Core.Test.MusicTests
}
[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();

View File

@ -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 @@ namespace NzbDrone.Core.Test.ParserTests
}
[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 @@ namespace NzbDrone.Core.Test.ParserTests
}
[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 @@ namespace NzbDrone.Core.Test.ParserTests
[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 @@ namespace NzbDrone.Core.Test.ParserTests
[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;

View File

@ -45,40 +45,30 @@ namespace NzbDrone.Core.Music
{
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 @@ namespace NzbDrone.Core.Music
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;
}
}
}

View File

@ -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 @@ namespace NzbDrone.Core.Music
{
_commandQueueManager.Push(new RefreshArtistCommand(message.Artist.Id));
}
public void Handle(ArtistsImportedEvent message)
{
_commandQueueManager.PushMany(message.ArtistIds.Select(s => new RefreshArtistCommand(s)).ToList());
}
}
}

View File

@ -17,6 +17,7 @@ namespace NzbDrone.Core.Music
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 @@ namespace NzbDrone.Core.Music
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);

View 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;
}
}
}

View File

@ -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" />