using System; using System.Collections.Generic; using System.IO; using FizzWare.NBuilder; using FluentAssertions; using FluentValidation; using FluentValidation.Results; using Moq; using NUnit.Framework; using NzbDrone.Core.Exceptions; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Music; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.MusicTests { [TestFixture] public class AddAlbumFixture : CoreTest { private Album _fakeAlbum; private AlbumRelease _fakeRelease; private readonly string _fakeArtistForeignId = "xxx-xxx-xxx"; private readonly List _fakeArtists = new List { new ArtistMetadata() }; [SetUp] public void Setup() { _fakeAlbum = Builder .CreateNew() .Build(); _fakeRelease = Builder .CreateNew() .Build(); _fakeRelease.Tracks = new List(); _fakeAlbum.AlbumReleases = new List {_fakeRelease}; } private void GivenValidAlbum(string lidarrId) { Mocker.GetMock() .Setup(s => s.GetAlbumInfo(lidarrId)) .Returns(new Tuple>(_fakeArtistForeignId, _fakeAlbum, _fakeArtists)); } [Test] public void should_be_able_to_add_an_album_without_passing_in_title() { var newAlbum = new Album { ForeignAlbumId = "ce09ea31-3d4a-4487-a797-e315175457a0" }; GivenValidAlbum(newAlbum.ForeignAlbumId); var album = Subject.AddAlbum(newAlbum); album.Title.Should().Be(_fakeAlbum.Title); } [Test] public void should_throw_if_album_cannot_be_found() { var newAlbum = new Album { ForeignAlbumId = "ce09ea31-3d4a-4487-a797-e315175457a0" }; Mocker.GetMock() .Setup(s => s.GetAlbumInfo(newAlbum.ForeignAlbumId)) .Throws(new AlbumNotFoundException(newAlbum.ForeignAlbumId)); Assert.Throws(() => Subject.AddAlbum(newAlbum)); ExceptionVerification.ExpectedErrors(1); } } }