parent
5b4ab75220
commit
61b6572f61
@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Test.MusicTests.ArtistRepositoryTests
|
||||
{
|
||||
[TestFixture]
|
||||
|
||||
public class ArtistMetadataRepositoryFixture : DbTest<ArtistMetadataRepository, ArtistMetadata>
|
||||
{
|
||||
private ArtistMetadataRepository _artistMetadataRepo;
|
||||
private List<ArtistMetadata> _metadataList;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_artistMetadataRepo = Mocker.Resolve<ArtistMetadataRepository>();
|
||||
_metadataList = Builder<ArtistMetadata>.CreateListOfSize(10).BuildList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void upsert_many_should_insert_list_of_new()
|
||||
{
|
||||
var updated = _artistMetadataRepo.UpsertMany(_metadataList);
|
||||
AllStoredModels.Should().HaveCount(_metadataList.Count);
|
||||
updated.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void upsert_many_should_upsert_existing_with_id_0()
|
||||
{
|
||||
var _clone = _metadataList.JsonClone();
|
||||
var updated = _artistMetadataRepo.UpsertMany(_clone);
|
||||
|
||||
updated.Should().BeTrue();
|
||||
AllStoredModels.Should().HaveCount(_metadataList.Count);
|
||||
|
||||
updated = _artistMetadataRepo.UpsertMany(_metadataList);
|
||||
updated.Should().BeFalse();
|
||||
AllStoredModels.Should().HaveCount(_metadataList.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void upsert_many_should_upsert_mixed_list_of_old_and_new()
|
||||
{
|
||||
var _clone = _metadataList.Take(5).ToList().JsonClone();
|
||||
var updated = _artistMetadataRepo.UpsertMany(_clone);
|
||||
|
||||
updated.Should().BeTrue();
|
||||
AllStoredModels.Should().HaveCount(_clone.Count);
|
||||
|
||||
updated = _artistMetadataRepo.UpsertMany(_metadataList);
|
||||
updated.Should().BeTrue();
|
||||
AllStoredModels.Should().HaveCount(_metadataList.Count);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using NLog;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
{
|
||||
public interface IArtistMetadataService
|
||||
{
|
||||
bool Upsert(ArtistMetadata artist);
|
||||
bool UpsertMany(List<ArtistMetadata> artists);
|
||||
}
|
||||
|
||||
public class ArtistMetadataService : IArtistMetadataService
|
||||
{
|
||||
private readonly IArtistMetadataRepository _artistMetadataRepository;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ArtistMetadataService(IArtistMetadataRepository artistMetadataRepository,
|
||||
Logger logger)
|
||||
{
|
||||
_artistMetadataRepository = artistMetadataRepository;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool Upsert(ArtistMetadata artist)
|
||||
{
|
||||
return _artistMetadataRepository.UpsertMany(new List<ArtistMetadata> { artist });
|
||||
}
|
||||
|
||||
public bool UpsertMany(List<ArtistMetadata> artists)
|
||||
{
|
||||
return _artistMetadataRepository.UpsertMany(artists);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue