|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Moq;
|
|
|
|
@ -136,5 +136,164 @@ namespace NzbDrone.Core.Test.Download.TrackedDownloads
|
|
|
|
|
trackedDownloads.Should().HaveCount(1);
|
|
|
|
|
trackedDownloads.First().RemoteAlbum.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_unmap_tracked_download_if_album_removed()
|
|
|
|
|
{
|
|
|
|
|
GivenDownloadHistory();
|
|
|
|
|
|
|
|
|
|
var remoteAlbum = new RemoteAlbum
|
|
|
|
|
{
|
|
|
|
|
Artist = new Artist() { Id = 5 },
|
|
|
|
|
Albums = new List<Album> { new Album { Id = 4 } },
|
|
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo()
|
|
|
|
|
{
|
|
|
|
|
AlbumTitle = "Audio Album",
|
|
|
|
|
ArtistName = "Audio Artist"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
|
|
|
|
.Returns(remoteAlbum);
|
|
|
|
|
|
|
|
|
|
var client = new DownloadClientDefinition()
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Protocol = DownloadProtocol.Torrent
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var item = new DownloadClientItem()
|
|
|
|
|
{
|
|
|
|
|
Title = "Audio Artist - Audio Album [2018 - FLAC]",
|
|
|
|
|
DownloadId = "35238",
|
|
|
|
|
DownloadClientInfo = new DownloadClientItemClientInfo
|
|
|
|
|
{
|
|
|
|
|
Protocol = client.Protocol,
|
|
|
|
|
Id = client.Id,
|
|
|
|
|
Name = client.Name
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Subject.TrackDownload(client, item);
|
|
|
|
|
Subject.GetTrackedDownloads().Should().HaveCount(1);
|
|
|
|
|
|
|
|
|
|
// simulate deletion - album no longer maps
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
|
|
|
|
.Returns(default(RemoteAlbum));
|
|
|
|
|
|
|
|
|
|
Subject.Handle(new AlbumInfoRefreshedEvent(remoteAlbum.Artist, new List<Album>(), new List<Album>(), remoteAlbum.Albums));
|
|
|
|
|
|
|
|
|
|
var trackedDownloads = Subject.GetTrackedDownloads();
|
|
|
|
|
trackedDownloads.Should().HaveCount(1);
|
|
|
|
|
trackedDownloads.First().RemoteAlbum.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_throw_when_processing_deleted_albums()
|
|
|
|
|
{
|
|
|
|
|
GivenDownloadHistory();
|
|
|
|
|
|
|
|
|
|
var remoteAlbum = new RemoteAlbum
|
|
|
|
|
{
|
|
|
|
|
Artist = new Artist() { Id = 5 },
|
|
|
|
|
Albums = new List<Album> { new Album { Id = 4 } },
|
|
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo()
|
|
|
|
|
{
|
|
|
|
|
AlbumTitle = "Audio Album",
|
|
|
|
|
ArtistName = "Audio Artist"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
|
|
|
|
.Returns(remoteAlbum);
|
|
|
|
|
|
|
|
|
|
var client = new DownloadClientDefinition()
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Protocol = DownloadProtocol.Torrent
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var item = new DownloadClientItem()
|
|
|
|
|
{
|
|
|
|
|
Title = "Audio Artist - Audio Album [2018 - FLAC]",
|
|
|
|
|
DownloadId = "35238",
|
|
|
|
|
DownloadClientInfo = new DownloadClientItemClientInfo
|
|
|
|
|
{
|
|
|
|
|
Protocol = client.Protocol,
|
|
|
|
|
Id = client.Id,
|
|
|
|
|
Name = client.Name
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Subject.TrackDownload(client, item);
|
|
|
|
|
Subject.GetTrackedDownloads().Should().HaveCount(1);
|
|
|
|
|
|
|
|
|
|
// simulate deletion - album no longer maps
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
|
|
|
|
.Returns(default(RemoteAlbum));
|
|
|
|
|
|
|
|
|
|
Subject.Handle(new AlbumInfoRefreshedEvent(remoteAlbum.Artist, new List<Album>(), new List<Album>(), remoteAlbum.Albums));
|
|
|
|
|
|
|
|
|
|
var trackedDownloads = Subject.GetTrackedDownloads();
|
|
|
|
|
trackedDownloads.Should().HaveCount(1);
|
|
|
|
|
trackedDownloads.First().RemoteAlbum.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void should_not_throw_when_processing_deleted_artist()
|
|
|
|
|
{
|
|
|
|
|
GivenDownloadHistory();
|
|
|
|
|
|
|
|
|
|
var remoteAlbum = new RemoteAlbum
|
|
|
|
|
{
|
|
|
|
|
Artist = new Artist() { Id = 5 },
|
|
|
|
|
Albums = new List<Album> { new Album { Id = 4 } },
|
|
|
|
|
ParsedAlbumInfo = new ParsedAlbumInfo()
|
|
|
|
|
{
|
|
|
|
|
AlbumTitle = "Audio Album",
|
|
|
|
|
ArtistName = "Audio Artist"
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
|
|
|
|
.Returns(remoteAlbum);
|
|
|
|
|
|
|
|
|
|
var client = new DownloadClientDefinition()
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Protocol = DownloadProtocol.Torrent
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var item = new DownloadClientItem()
|
|
|
|
|
{
|
|
|
|
|
Title = "Audio Artist - Audio Album [2018 - FLAC]",
|
|
|
|
|
DownloadId = "35238",
|
|
|
|
|
DownloadClientInfo = new DownloadClientItemClientInfo
|
|
|
|
|
{
|
|
|
|
|
Protocol = client.Protocol,
|
|
|
|
|
Id = client.Id,
|
|
|
|
|
Name = client.Name
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Subject.TrackDownload(client, item);
|
|
|
|
|
Subject.GetTrackedDownloads().Should().HaveCount(1);
|
|
|
|
|
|
|
|
|
|
// simulate deletion - album no longer maps
|
|
|
|
|
Mocker.GetMock<IParsingService>()
|
|
|
|
|
.Setup(s => s.Map(It.Is<ParsedAlbumInfo>(i => i.AlbumTitle == "Audio Album" && i.ArtistName == "Audio Artist"), It.IsAny<int>(), It.IsAny<IEnumerable<int>>()))
|
|
|
|
|
.Returns(default(RemoteAlbum));
|
|
|
|
|
|
|
|
|
|
Subject.Handle(new ArtistsDeletedEvent(new List<Artist> { remoteAlbum.Artist }, true, true));
|
|
|
|
|
|
|
|
|
|
var trackedDownloads = Subject.GetTrackedDownloads();
|
|
|
|
|
trackedDownloads.Should().HaveCount(1);
|
|
|
|
|
trackedDownloads.First().RemoteAlbum.Should().BeNull();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|