|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FizzWare.NBuilder;
|
|
|
|
|
using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Core.ImportLists;
|
|
|
|
|
using NzbDrone.Core.ImportLists.Exclusions;
|
|
|
|
|
using NzbDrone.Core.IndexerSearch;
|
|
|
|
|
using NzbDrone.Core.Messaging.Commands;
|
|
|
|
|
using NzbDrone.Core.MetadataSource;
|
|
|
|
|
using NzbDrone.Core.Music;
|
|
|
|
|
using NzbDrone.Core.Parser.Model;
|
|
|
|
@ -85,18 +88,32 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
_importListReports.Add(importListItem2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithExistingArtist()
|
|
|
|
|
private void WithExistingArtist(bool monitored)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IArtistService>()
|
|
|
|
|
.Setup(v => v.FindById(_importListReports.First().ArtistMusicBrainzId))
|
|
|
|
|
.Returns(new Artist { Id = 1, ForeignArtistId = _importListReports.First().ArtistMusicBrainzId });
|
|
|
|
|
.Returns(new Artist { Id = 1, ForeignArtistId = _importListReports.First().ArtistMusicBrainzId, Monitored = monitored });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithExistingAlbum()
|
|
|
|
|
private void WithExistingAlbum(bool monitored)
|
|
|
|
|
{
|
|
|
|
|
var album = Builder<Album>.CreateNew()
|
|
|
|
|
.With(x => x.Id = 1)
|
|
|
|
|
.With(x => x.ForeignAlbumId = _importListReports.First().AlbumMusicBrainzId)
|
|
|
|
|
.With(x => x.Monitored = monitored)
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
var artist = Builder<Artist>.CreateNew()
|
|
|
|
|
.With(x => x.Monitored = monitored)
|
|
|
|
|
.With(x => x.ForeignArtistId = _importListReports.First().ArtistMusicBrainzId)
|
|
|
|
|
.With(x => x.Albums = new List<Album> { album })
|
|
|
|
|
.Build();
|
|
|
|
|
|
|
|
|
|
album.Artist = artist;
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IAlbumService>()
|
|
|
|
|
.Setup(v => v.FindById(_importListReports.First().AlbumMusicBrainzId))
|
|
|
|
|
.Returns(new Album { Id = 1, ForeignAlbumId = _importListReports.First().AlbumMusicBrainzId });
|
|
|
|
|
.Returns(album);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithExcludedArtist()
|
|
|
|
@ -125,11 +142,11 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WithMonitorType(ImportListMonitorType monitor)
|
|
|
|
|
private void WithListSettings(ImportListMonitorType monitor = ImportListMonitorType.EntireArtist, bool shouldMonitorExisting = false, bool shouldSearch = true)
|
|
|
|
|
{
|
|
|
|
|
Mocker.GetMock<IImportListFactory>()
|
|
|
|
|
.Setup(v => v.Get(It.IsAny<int>()))
|
|
|
|
|
.Returns(new ImportListDefinition { ShouldMonitor = monitor });
|
|
|
|
|
.Returns(new ImportListDefinition { ShouldMonitor = monitor, ShouldMonitorExisting = shouldMonitorExisting, ShouldSearch = shouldSearch });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
@ -191,7 +208,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
public void should_not_add_if_existing_artist()
|
|
|
|
|
{
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingArtist();
|
|
|
|
|
WithExistingArtist(false);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
@ -203,7 +220,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
public void should_not_add_if_existing_album()
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithExistingAlbum();
|
|
|
|
|
WithExistingAlbum(false);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
@ -216,7 +233,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingArtist();
|
|
|
|
|
WithExistingArtist(false);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
@ -230,7 +247,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
public void should_add_if_not_existing_artist(ImportListMonitorType monitor, bool expectedArtistMonitored)
|
|
|
|
|
{
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithMonitorType(monitor);
|
|
|
|
|
WithListSettings(monitor);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
@ -244,7 +261,8 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
public void should_add_if_not_existing_album(ImportListMonitorType monitor, bool expectedAlbumMonitored)
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithMonitorType(monitor);
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithListSettings(monitor);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
@ -268,6 +286,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
public void should_not_add_album_if_excluded_album()
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExcludedAlbum();
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
@ -298,7 +317,7 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithSecondBook();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithMonitorType(monitor);
|
|
|
|
|
WithListSettings(monitor);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
@ -311,5 +330,195 @@ namespace NzbDrone.Core.Test.ImportListTests
|
|
|
|
|
false,
|
|
|
|
|
true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(ImportListMonitorType.SpecificAlbum)]
|
|
|
|
|
[TestCase(ImportListMonitorType.EntireArtist)]
|
|
|
|
|
public void should_monitor_existing_unmonitored_album(ImportListMonitorType monitorType)
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingAlbum(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(monitorType, true);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IAlbumService>()
|
|
|
|
|
.Verify(v => v.SetAlbumMonitored(1, true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(ImportListMonitorType.SpecificAlbum)]
|
|
|
|
|
[TestCase(ImportListMonitorType.EntireArtist)]
|
|
|
|
|
public void should_not_monitor_existing_monitored_album(ImportListMonitorType monitorType)
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingAlbum(true);
|
|
|
|
|
|
|
|
|
|
WithListSettings(monitorType, true);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IAlbumService>()
|
|
|
|
|
.Verify(v => v.SetAlbumMonitored(1, true), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(ImportListMonitorType.SpecificAlbum, false)]
|
|
|
|
|
[TestCase(ImportListMonitorType.EntireArtist, false)]
|
|
|
|
|
[TestCase(ImportListMonitorType.None, false)]
|
|
|
|
|
[TestCase(ImportListMonitorType.None, true)]
|
|
|
|
|
|
|
|
|
|
public void should_not_monitor_existing_unmonitored_album(ImportListMonitorType monitorType, bool shouldMonitorExisting)
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingAlbum(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(monitorType, shouldMonitorExisting);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IAlbumService>()
|
|
|
|
|
.Verify(v => v.SetAlbumMonitored(1, true), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_search_specific_existing_unmonitored_album()
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingAlbum(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(ImportListMonitorType.SpecificAlbum, true, true);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IManageCommandQueue>()
|
|
|
|
|
.Verify(v => v.Push<Command>(It.Is<AlbumSearchCommand>(x => x.AlbumIds.Count == 1 && x.AlbumIds.Contains(1)), CommandPriority.Normal, CommandTrigger.Unspecified));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_search_specific_existing_unmonitored_album()
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingAlbum(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(ImportListMonitorType.SpecificAlbum, true, false);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IManageCommandQueue>()
|
|
|
|
|
.Verify(v => v.Push<Command>(It.Is<AlbumSearchCommand>(x => x.AlbumIds.Count == 1 && x.AlbumIds.Contains(1)), CommandPriority.Normal, CommandTrigger.Unspecified), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_search_all_artist_albums()
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingAlbum(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(ImportListMonitorType.EntireArtist, true, true);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IManageCommandQueue>()
|
|
|
|
|
.Verify(v => v.Push<Command>(It.Is<MissingAlbumSearchCommand>(x => x.ArtistId == 1), CommandPriority.Normal, CommandTrigger.Unspecified));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_search_all_artist_albums()
|
|
|
|
|
{
|
|
|
|
|
WithAlbumId();
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingAlbum(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(ImportListMonitorType.EntireArtist, true, false);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IManageCommandQueue>()
|
|
|
|
|
.Verify(v => v.Push<Command>(It.Is<MissingAlbumSearchCommand>(x => x.ArtistId == 1), CommandPriority.Normal, CommandTrigger.Unspecified), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(ImportListMonitorType.SpecificAlbum)]
|
|
|
|
|
[TestCase(ImportListMonitorType.EntireArtist)]
|
|
|
|
|
[TestCase(ImportListMonitorType.None)]
|
|
|
|
|
|
|
|
|
|
public void should_monitor_existing_unmonitored_artist(ImportListMonitorType monitorType)
|
|
|
|
|
{
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingArtist(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(monitorType, true);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IArtistService>()
|
|
|
|
|
.Verify(v => v.UpdateArtist(It.Is<Artist>(a => a.Monitored), true));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(ImportListMonitorType.SpecificAlbum)]
|
|
|
|
|
[TestCase(ImportListMonitorType.EntireArtist)]
|
|
|
|
|
[TestCase(ImportListMonitorType.None)]
|
|
|
|
|
|
|
|
|
|
public void should_not_monitor_existing_monitored_artist(ImportListMonitorType monitorType)
|
|
|
|
|
{
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingArtist(true);
|
|
|
|
|
|
|
|
|
|
WithListSettings(monitorType, true);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IArtistService>()
|
|
|
|
|
.Verify(v => v.UpdateArtist(It.IsAny<Artist>(), It.IsAny<bool>()), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase(ImportListMonitorType.SpecificAlbum)]
|
|
|
|
|
[TestCase(ImportListMonitorType.EntireArtist)]
|
|
|
|
|
[TestCase(ImportListMonitorType.None)]
|
|
|
|
|
|
|
|
|
|
public void should_not_monitor_existing_unmonitored_artist(ImportListMonitorType monitorType)
|
|
|
|
|
{
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingArtist(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(monitorType, false);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IArtistService>()
|
|
|
|
|
.Verify(v => v.UpdateArtist(It.IsAny<Artist>(), It.IsAny<bool>()), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_search_unmonitored_artist()
|
|
|
|
|
{
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingArtist(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(ImportListMonitorType.EntireArtist, true, true);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IManageCommandQueue>()
|
|
|
|
|
.Verify(v => v.Push<Command>(It.Is<MissingAlbumSearchCommand>(x => x.ArtistId == 1), CommandPriority.Normal, CommandTrigger.Unspecified));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_search_unmonitored_artist()
|
|
|
|
|
{
|
|
|
|
|
WithArtistId();
|
|
|
|
|
WithExistingArtist(false);
|
|
|
|
|
|
|
|
|
|
WithListSettings(ImportListMonitorType.EntireArtist, true, false);
|
|
|
|
|
|
|
|
|
|
Subject.Execute(new ImportListSyncCommand());
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IManageCommandQueue>()
|
|
|
|
|
.Verify(v => v.Push<Command>(It.IsAny<MissingAlbumSearchCommand>(), CommandPriority.Normal, CommandTrigger.Unspecified), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|