Add ArtistService Tests

pull/131/head
Qstick 7 years ago
parent e8d44d1cc2
commit 08b95e905e

@ -0,0 +1,40 @@
using FizzWare.NBuilder;
using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Organizer;
using NzbDrone.Core.Music;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Music.Events;
namespace NzbDrone.Core.Test.MusicTests.ArtistServiceTests
{
[TestFixture]
public class AddArtistFixture : CoreTest<ArtistService>
{
private Artist _fakeArtist;
[SetUp]
public void Setup()
{
_fakeArtist = Builder<Artist>.CreateNew().Build();
}
[Test]
public void artist_added_event_should_have_proper_path()
{
_fakeArtist.Path = null;
_fakeArtist.RootFolderPath = @"C:\Test\Music";
Mocker.GetMock<IBuildFileNames>()
.Setup(s => s.GetArtistFolder(_fakeArtist, null))
.Returns(_fakeArtist.Name);
var artist = Subject.AddArtist(_fakeArtist);
artist.Path.Should().NotBeNull();
VerifyEventPublished<ArtistAddedEvent>();
}
}
}

@ -0,0 +1,72 @@
using System.Collections.Generic;
using System.Linq;
using FizzWare.NBuilder;
using FluentAssertions;
using Moq;
using NUnit.Framework;
using NzbDrone.Core.Music;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.MusicTests.ArtistServiceTests
{
[TestFixture]
public class UpdateMultipleArtistFixture : CoreTest<ArtistService>
{
private List<Artist> _artists;
[SetUp]
public void Setup()
{
_artists = Builder<Artist>.CreateListOfSize(5)
.All()
.With(s => s.ProfileId = 1)
.With(s => s.Monitored)
.With(s => s.Path = @"C:\Test\name".AsOsAgnostic())
.With(s => s.RootFolderPath = "")
.Build().ToList();
}
[Test]
public void should_call_repo_updateMany()
{
Subject.UpdateArtists(_artists);
Mocker.GetMock<IArtistRepository>().Verify(v => v.UpdateMany(_artists), Times.Once());
}
[Test]
public void should_update_path_when_rootFolderPath_is_supplied()
{
var newRoot = @"C:\Test\Music2".AsOsAgnostic();
_artists.ForEach(s => s.RootFolderPath = newRoot);
Subject.UpdateArtists(_artists).ForEach(s => s.Path.Should().StartWith(newRoot));
}
[Test]
public void should_not_update_path_when_rootFolderPath_is_empty()
{
Subject.UpdateArtists(_artists).ForEach(s =>
{
var expectedPath = _artists.Single(ser => ser.Id == s.Id).Path;
s.Path.Should().Be(expectedPath);
});
}
[Test]
public void should_be_able_to_update_many_artist()
{
var artist = Builder<Artist>.CreateListOfSize(50)
.All()
.With(s => s.Path = (@"C:\Test\Music\" + s.Path).AsOsAgnostic())
.Build()
.ToList();
var newRoot = @"C:\Test\TV2".AsOsAgnostic();
artist.ForEach(s => s.RootFolderPath = newRoot);
Subject.UpdateArtists(artist);
}
}
}

@ -271,6 +271,8 @@
<Compile Include="MusicTests\AddArtistFixture.cs" />
<Compile Include="MusicTests\ArtistNameSlugValidatorFixture.cs" />
<Compile Include="MusicTests\ArtistRepositoryTests\ArtistRepositoryFixture.cs" />
<Compile Include="MusicTests\ArtistServiceTests\AddArtistFixture.cs" />
<Compile Include="MusicTests\ArtistServiceTests\UpdateMultipleArtistFixture.cs" />
<Compile Include="NotificationTests\NotificationBaseFixture.cs" />
<Compile Include="NotificationTests\SynologyIndexerFixture.cs" />
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />

Loading…
Cancel
Save