parent
d10fb92a09
commit
6e4638f7b1
@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.MetadataSource;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Core.Music.Commands;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MusicTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RefreshArtistServiceFixture : CoreTest<RefreshArtistService>
|
||||
{
|
||||
private Artist _artist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
var season1 = Builder<Album>.CreateNew()
|
||||
.With(s => s.ForeignAlbumId = "1")
|
||||
.Build();
|
||||
|
||||
_artist = Builder<Artist>.CreateNew()
|
||||
.With(s => s.Albums = new List<Album>
|
||||
{
|
||||
season1
|
||||
})
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Setup(s => s.GetArtist(_artist.Id))
|
||||
.Returns(_artist);
|
||||
|
||||
Mocker.GetMock<IProvideArtistInfo>()
|
||||
.Setup(s => s.GetArtistInfo(It.IsAny<string>()))
|
||||
.Callback<string>(p => { throw new ArtistNotFoundException(p); });
|
||||
}
|
||||
|
||||
private void GivenNewArtistInfo(Artist artist)
|
||||
{
|
||||
Mocker.GetMock<IProvideArtistInfo>()
|
||||
.Setup(s => s.GetArtistInfo(_artist.ForeignArtistId))
|
||||
.Returns(new Tuple<Artist, List<Album>>(artist, new List<Album>()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_monitor_new_albums_automatically()
|
||||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
newArtistInfo.Albums.Add(Builder<Album>.CreateNew()
|
||||
.With(s => s.ForeignAlbumId = "2")
|
||||
.Build());
|
||||
|
||||
GivenNewArtistInfo(newArtistInfo);
|
||||
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Verify(v => v.UpdateArtist(It.Is<Artist>(s => s.Albums.Count == 2 && s.Albums.Single(season => season.ForeignAlbumId == "2").Monitored == true)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_log_error_if_musicbrainz_id_not_found()
|
||||
{
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Verify(v => v.UpdateArtist(It.IsAny<Artist>()), Times.Never());
|
||||
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_update_if_musicbrainz_id_changed()
|
||||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
newArtistInfo.ForeignArtistId = _artist.ForeignArtistId + 1;
|
||||
|
||||
GivenNewArtistInfo(newArtistInfo);
|
||||
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Verify(v => v.UpdateArtist(It.Is<Artist>(s => s.ForeignArtistId == newArtistInfo.ForeignArtistId)));
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_throw_if_duplicate_album_is_in_existing_info()
|
||||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
newArtistInfo.Albums.Add(Builder<Album>.CreateNew()
|
||||
.With(s => s.ForeignAlbumId = "2")
|
||||
.Build());
|
||||
|
||||
_artist.Albums.Add(Builder<Album>.CreateNew()
|
||||
.With(s => s.ForeignAlbumId = "2")
|
||||
.Build());
|
||||
|
||||
_artist.Albums.Add(Builder<Album>.CreateNew()
|
||||
.With(s => s.ForeignAlbumId = "2")
|
||||
.Build());
|
||||
|
||||
GivenNewArtistInfo(newArtistInfo);
|
||||
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Verify(v => v.UpdateArtist(It.Is<Artist>(s => s.Albums.Count == 2)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_filter_duplicate_albums()
|
||||
{
|
||||
var newArtistInfo = _artist.JsonClone();
|
||||
newArtistInfo.Albums.Add(Builder<Album>.CreateNew()
|
||||
.With(s => s.ForeignAlbumId = "2")
|
||||
.Build());
|
||||
|
||||
newArtistInfo.Albums.Add(Builder<Album>.CreateNew()
|
||||
.With(s => s.ForeignAlbumId = "2")
|
||||
.Build());
|
||||
|
||||
GivenNewArtistInfo(newArtistInfo);
|
||||
|
||||
Subject.Execute(new RefreshArtistCommand(_artist.Id));
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Verify(v => v.UpdateArtist(It.Is<Artist>(s => s.Albums.Count == 2)));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.MusicTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ShouldRefreshArtistFixture : TestBase<ShouldRefreshArtist>
|
||||
{
|
||||
private Artist _artist;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_artist = Builder<Artist>.CreateNew()
|
||||
.With(v => v.Status == ArtistStatusType.Continuing)
|
||||
.Build();
|
||||
|
||||
Mocker.GetMock<IAlbumService>()
|
||||
.Setup(s => s.GetAlbumsByArtist(_artist.Id))
|
||||
.Returns(Builder<Album>.CreateListOfSize(2)
|
||||
.All()
|
||||
.With(e => e.ReleaseDate = DateTime.Today.AddDays(-100))
|
||||
.Build()
|
||||
.ToList());
|
||||
}
|
||||
|
||||
private void GivenArtistIsEnded()
|
||||
{
|
||||
_artist.Status = ArtistStatusType.Ended;
|
||||
}
|
||||
|
||||
private void GivenArtistLastRefreshedMonthsAgo()
|
||||
{
|
||||
_artist.LastInfoSync = DateTime.UtcNow.AddDays(-90);
|
||||
}
|
||||
|
||||
private void GivenArtistLastRefreshedYesterday()
|
||||
{
|
||||
_artist.LastInfoSync = DateTime.UtcNow.AddDays(-1);
|
||||
}
|
||||
|
||||
private void GivenArtistLastRefreshedHalfADayAgo()
|
||||
{
|
||||
_artist.LastInfoSync = DateTime.UtcNow.AddHours(-12);
|
||||
}
|
||||
|
||||
private void GivenArtistLastRefreshedRecently()
|
||||
{
|
||||
_artist.LastInfoSync = DateTime.UtcNow.AddHours(-1);
|
||||
}
|
||||
|
||||
private void GivenRecentlyAired()
|
||||
{
|
||||
Mocker.GetMock<IAlbumService>()
|
||||
.Setup(s => s.GetAlbumsByArtist(_artist.Id))
|
||||
.Returns(Builder<Album>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(e => e.ReleaseDate = DateTime.Today.AddDays(-7))
|
||||
.TheLast(1)
|
||||
.With(e => e.ReleaseDate = DateTime.Today.AddDays(-100))
|
||||
.Build()
|
||||
.ToList());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_running_artist_last_refreshed_more_than_6_hours_ago()
|
||||
{
|
||||
GivenArtistLastRefreshedHalfADayAgo();
|
||||
|
||||
Subject.ShouldRefresh(_artist).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_running_artist_last_refreshed_less_than_6_hours_ago()
|
||||
{
|
||||
GivenArtistLastRefreshedRecently();
|
||||
|
||||
Subject.ShouldRefresh(_artist).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_ended_artist_last_refreshed_yesterday()
|
||||
{
|
||||
GivenArtistIsEnded();
|
||||
GivenArtistLastRefreshedYesterday();
|
||||
|
||||
Subject.ShouldRefresh(_artist).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_artist_last_refreshed_more_than_30_days_ago()
|
||||
{
|
||||
GivenArtistIsEnded();
|
||||
GivenArtistLastRefreshedMonthsAgo();
|
||||
|
||||
Subject.ShouldRefresh(_artist).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_album_released_in_last_30_days()
|
||||
{
|
||||
GivenArtistIsEnded();
|
||||
GivenArtistLastRefreshedYesterday();
|
||||
|
||||
GivenRecentlyAired();
|
||||
|
||||
Subject.ShouldRefresh(_artist).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_recently_refreshed_ended_show_has_not_aired_for_30_days()
|
||||
{
|
||||
GivenArtistIsEnded();
|
||||
GivenArtistLastRefreshedYesterday();
|
||||
|
||||
Subject.ShouldRefresh(_artist).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_recently_refreshed_ended_show_aired_in_last_30_days()
|
||||
{
|
||||
GivenArtistIsEnded();
|
||||
GivenArtistLastRefreshedRecently();
|
||||
|
||||
GivenRecentlyAired();
|
||||
|
||||
Subject.ShouldRefresh(_artist).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class ActorResource
|
||||
public class MemberResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Character { get; set; }
|
||||
public string Instrument { get; set; }
|
||||
public string Image { get; set; }
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.MetadataSource.SkyHook.Resource
|
||||
{
|
||||
public class SeasonResource
|
||||
{
|
||||
public SeasonResource()
|
||||
{
|
||||
Images = new List<ImageResource>();
|
||||
}
|
||||
|
||||
public int SeasonNumber { get; set; }
|
||||
public List<ImageResource> Images { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in new issue