using System.Collections.Generic; using System.IO; using System.Linq; using FizzWare.NBuilder; using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Core.Organizer; using NzbDrone.Core.RootFolders; using NzbDrone.Core.Tv; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests { [TestFixture] public class UpdateMultipleSeriesFixture : CoreTest { private List _series; [SetUp] public void Setup() { _series = Builder.CreateListOfSize(5) .All() .With(s => s.QualityProfileId = 1) .With(s => s.Monitored) .With(s => s.SeasonFolder) .With(s => s.Path = @"C:\Test\name".AsOsAgnostic()) .With(s => s.RootFolderPath = "") .Build().ToList(); } [Test] public void should_call_repo_updateMany() { Subject.UpdateSeries(_series, false); Mocker.GetMock().Verify(v => v.UpdateMany(_series), Times.Once()); } [Test] public void should_update_path_when_rootFolderPath_is_supplied() { var newRoot = @"C:\Test\TV2".AsOsAgnostic(); _series.ForEach(s => s.RootFolderPath = newRoot); Mocker.GetMock() .Setup(s => s.BuildPath(It.IsAny(), false)) .Returns((s, u) => Path.Combine(s.RootFolderPath, s.Title)); Subject.UpdateSeries(_series, false).ForEach(s => s.Path.Should().StartWith(newRoot)); } [Test] public void should_not_update_path_when_rootFolderPath_is_empty() { Subject.UpdateSeries(_series, false).ForEach(s => { var expectedPath = _series.Single(ser => ser.Id == s.Id).Path; s.Path.Should().Be(expectedPath); }); } [Test] public void should_be_able_to_update_many_series() { var series = Builder.CreateListOfSize(50) .All() .With(s => s.Path = (@"C:\Test\TV\" + s.Path).AsOsAgnostic()) .Build() .ToList(); var newRoot = @"C:\Test\TV2".AsOsAgnostic(); series.ForEach(s => s.RootFolderPath = newRoot); Mocker.GetMock() .Setup(s => s.GetSeriesFolder(It.IsAny(), (NamingConfig)null)) .Returns((s, n) => s.Title); Subject.UpdateSeries(series, false); } } }