From 08b95e905e27a3e5f829e9c8fa860626a2e1cd2b Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 16 Nov 2017 11:15:19 -0500 Subject: [PATCH] Add ArtistService Tests --- .../ArtistServiceTests/AddArtistFixture.cs | 40 +++++++++++ .../UpdateMultipleArtistFixture.cs | 72 +++++++++++++++++++ .../NzbDrone.Core.Test.csproj | 2 + 3 files changed, 114 insertions(+) create mode 100644 src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/AddArtistFixture.cs create mode 100644 src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/UpdateMultipleArtistFixture.cs diff --git a/src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/AddArtistFixture.cs b/src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/AddArtistFixture.cs new file mode 100644 index 000000000..57338ebce --- /dev/null +++ b/src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/AddArtistFixture.cs @@ -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 + { + private Artist _fakeArtist; + + [SetUp] + public void Setup() + { + _fakeArtist = Builder.CreateNew().Build(); + } + + [Test] + public void artist_added_event_should_have_proper_path() + { + _fakeArtist.Path = null; + _fakeArtist.RootFolderPath = @"C:\Test\Music"; + + Mocker.GetMock() + .Setup(s => s.GetArtistFolder(_fakeArtist, null)) + .Returns(_fakeArtist.Name); + + var artist = Subject.AddArtist(_fakeArtist); + + artist.Path.Should().NotBeNull(); + + VerifyEventPublished(); + } + + } +} diff --git a/src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/UpdateMultipleArtistFixture.cs b/src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/UpdateMultipleArtistFixture.cs new file mode 100644 index 000000000..fe4df3445 --- /dev/null +++ b/src/NzbDrone.Core.Test/MusicTests/ArtistServiceTests/UpdateMultipleArtistFixture.cs @@ -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 + { + private List _artists; + + [SetUp] + public void Setup() + { + _artists = Builder.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().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.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); + } + } +} diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index da4c8d376..770ab12aa 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -271,6 +271,8 @@ + +