using System.Collections.Generic; using System.Linq; using FizzWare.NBuilder; using Moq; using NUnit.Framework; using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Notifications; using NzbDrone.Core.Notifications.Xbmc; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Movies; namespace NzbDrone.Core.Test.NotificationTests.Xbmc { [TestFixture] public class OnDownloadFixture : CoreTest { private DownloadMessage _downloadMessage; [SetUp] public void Setup() { var movie = Builder.CreateNew() .Build(); var movieFile = Builder.CreateNew() .Build(); _downloadMessage = Builder.CreateNew() .With(d => d.Movie = movie) .With(d => d.MovieFile = movieFile) .With(d => d.OldMovieFiles = new List()) .Build(); Subject.Definition = new NotificationDefinition(); Subject.Definition.Settings = new XbmcSettings { UpdateLibrary = true }; } private void GivenOldFiles() { _downloadMessage.OldMovieFiles = Builder.CreateListOfSize(1) .Build() .ToList(); Subject.Definition.Settings = new XbmcSettings { UpdateLibrary = true, CleanLibrary = true }; } [Test] public void should_not_clean_if_no_movie_was_replaced() { Subject.OnDownload(_downloadMessage); Mocker.GetMock().Verify(v => v.Clean(It.IsAny()), Times.Never()); } [Test] public void should_clean_if_movie_was_replaced() { GivenOldFiles(); Subject.OnDownload(_downloadMessage); Mocker.GetMock().Verify(v => v.Clean(It.IsAny()), Times.Once()); } } }