using System; using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Core.MediaCover; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; using NzbDrone.Core.Tv.Events; namespace NzbDrone.Core.Test.MediaCoverTests { [TestFixture] public class MediaCoverServiceFixture : CoreTest { Series _series; [SetUp] public void Setup() { Mocker.SetConstant(new AppFolderInfo(Mocker.Resolve())); _series = Builder.CreateNew() .With(v => v.Id = 2) .With(v => v.Images = new List { new MediaCover.MediaCover(MediaCoverTypes.Poster, "") }) .Build(); } [Test] public void should_convert_cover_urls_to_local() { var covers = new List { new MediaCover.MediaCover {CoverType = MediaCoverTypes.Banner} }; Mocker.GetMock().Setup(c => c.FileGetLastWrite(It.IsAny())) .Returns(new DateTime(1234)); Mocker.GetMock().Setup(c => c.FileExists(It.IsAny())) .Returns(true); Subject.ConvertToLocalUrls(12, covers); covers.Single().Url.Should().Be("/MediaCover/12/banner.jpg?lastWrite=1234"); } [Test] public void should_convert_media_urls_to_local_without_time_if_file_doesnt_exist() { var covers = new List { new MediaCover.MediaCover {CoverType = MediaCoverTypes.Banner} }; Subject.ConvertToLocalUrls(12, covers); covers.Single().Url.Should().Be("/MediaCover/12/banner.jpg"); } [Test] public void should_resize_covers_if_main_downloaded() { Mocker.GetMock() .Setup(v => v.AlreadyExists(It.IsAny(), It.IsAny())) .Returns(false); Mocker.GetMock() .Setup(v => v.FileExists(It.IsAny())) .Returns(true); Subject.HandleAsync(new SeriesUpdatedEvent(_series)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); } [Test] public void should_resize_covers_if_missing() { Mocker.GetMock() .Setup(v => v.AlreadyExists(It.IsAny(), It.IsAny())) .Returns(true); Mocker.GetMock() .Setup(v => v.FileExists(It.IsAny())) .Returns(false); Subject.HandleAsync(new SeriesUpdatedEvent(_series)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Exactly(2)); } [Test] public void should_not_resize_covers_if_exists() { Mocker.GetMock() .Setup(v => v.AlreadyExists(It.IsAny(), It.IsAny())) .Returns(true); Mocker.GetMock() .Setup(v => v.FileExists(It.IsAny())) .Returns(true); Subject.HandleAsync(new SeriesUpdatedEvent(_series)); Mocker.GetMock() .Verify(v => v.Resize(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never()); } } }