diff --git a/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs b/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs index 8d085646b..30a6e58c4 100644 --- a/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs +++ b/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs @@ -57,8 +57,6 @@ namespace NzbDrone.Api.Movie //Todo error handling } - //var existingMovieTmdbIds = _movieService.GetAllMovies().Select(m => m.TmdbId); - RootFolder rootFolder = _rootFolderService.Get(Request.Query.Id); int page = Request.Query.page; @@ -135,10 +133,8 @@ namespace NzbDrone.Api.Movie mappedMovie = _searchProxy.MapMovieToTmdbMovie(m); - if (mappedMovie != null /*&& !existingMovieTmdbIds.Contains(mappedMovie.TmdbId)*/) + if (mappedMovie != null) { - //Could split these checks to flag movie as possible duplicate - mappedMovie.Monitored = true; _mappedMovies.Set(f.Name, mappedMovie, TimeSpan.FromDays(2)); diff --git a/src/NzbDrone.Core.Test/BulkImport/AddMultiMoviesFixture.cs b/src/NzbDrone.Core.Test/BulkImport/AddMultiMoviesFixture.cs new file mode 100644 index 000000000..c0910ec50 --- /dev/null +++ b/src/NzbDrone.Core.Test/BulkImport/AddMultiMoviesFixture.cs @@ -0,0 +1,75 @@ +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using Moq; +using NzbDrone.Core.Organizer; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv.Events; +using System.Collections.Generic; + +namespace NzbDrone.Core.Test.BulkImport +{ + [TestFixture] + public class AddMultiMoviesFixture : CoreTest + { + private List fakeMovies; + + [SetUp] + public void Setup() + { + fakeMovies = Builder.CreateListOfSize(3).BuildList(); + fakeMovies.ForEach(m => + { + m.Path = null; + m.RootFolderPath = @"C:\Test\TV"; + }); + } + + [Test] + public void movies_added_event_should_have_proper_path() + { + Mocker.GetMock() + .Setup(s => s.GetMovieFolder(It.IsAny(), null)) + .Returns((Movie m, NamingConfig n) => m.Title); + + var movies = Subject.AddMovies(fakeMovies); + + foreach (Movie movie in movies) + { + movie.Path.Should().NotBeNullOrEmpty(); + } + + //Subject.GetAllMovies().Should().HaveCount(3); + } + + [Test] + public void movies_added_should_ignore_already_added() + { + Mocker.GetMock() + .Setup(s => s.GetMovieFolder(It.IsAny(), null)) + .Returns((Movie m, NamingConfig n) => m.Title); + + Mocker.GetMock().Setup(s => s.All()).Returns(new List { fakeMovies[0] }); + + var movies = Subject.AddMovies(fakeMovies); + + Mocker.GetMock().Verify(v => v.InsertMany(It.Is>(l => l.Count == 2))); + } + + [Test] + public void movies_added_should_ignore_duplicates() + { + Mocker.GetMock() + .Setup(s => s.GetMovieFolder(It.IsAny(), null)) + .Returns((Movie m, NamingConfig n) => m.Title); + + fakeMovies[2].TmdbId = fakeMovies[0].TmdbId; + + var movies = Subject.AddMovies(fakeMovies); + + Mocker.GetMock().Verify(v => v.InsertMany(It.Is>(l => l.Count == 2))); + } + + } +} \ No newline at end of file diff --git a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index cef8c2283..10b01b539 100644 --- a/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/src/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -384,6 +384,7 @@ + @@ -575,6 +576,7 @@ + diff --git a/src/NzbDrone.Core.Test/TvTests/SeriesServiceTests/AddSeriesFixture.cs b/src/NzbDrone.Core.Test/TvTests/SeriesServiceTests/AddSeriesFixture.cs index cdc1041e7..c1b542d2f 100644 --- a/src/NzbDrone.Core.Test/TvTests/SeriesServiceTests/AddSeriesFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/SeriesServiceTests/AddSeriesFixture.cs @@ -1,40 +1,39 @@ -using FizzWare.NBuilder; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Core.Organizer; -using NzbDrone.Core.Tv; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Core.Tv.Events; - -namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests -{ - [TestFixture] - public class AddSeriesFixture : CoreTest - { - private Series fakeSeries; - - [SetUp] - public void Setup() - { - fakeSeries = Builder.CreateNew().Build(); - } - - [Test] - public void series_added_event_should_have_proper_path() - { - fakeSeries.Path = null; - fakeSeries.RootFolderPath = @"C:\Test\TV"; - - Mocker.GetMock() - .Setup(s => s.GetSeriesFolder(fakeSeries, null)) - .Returns(fakeSeries.Title); - - var series = Subject.AddSeries(fakeSeries); - - series.Path.Should().NotBeNull(); - - VerifyEventPublished(); - } - - } +using FizzWare.NBuilder; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.Organizer; +using NzbDrone.Core.Tv; +using NzbDrone.Core.Test.Framework; +using NzbDrone.Core.Tv.Events; + +namespace NzbDrone.Core.Test.TvTests.SeriesServiceTests +{ + [TestFixture] + public class AddSeriesFixture : CoreTest + { + private Series fakeSeries; + + [SetUp] + public void Setup() + { + fakeSeries = Builder.CreateNew().Build(); + } + + [Test] + public void series_added_event_should_have_proper_path() + { + fakeSeries.Path = null; + fakeSeries.RootFolderPath = @"C:\Test\TV"; + + Mocker.GetMock() + .Setup(s => s.GetSeriesFolder(fakeSeries, null)) + .Returns(fakeSeries.Title); + + var series = Subject.AddSeries(fakeSeries); + + series.Path.Should().NotBeNull(); + + } + + } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Tv/MovieService.cs b/src/NzbDrone.Core/Tv/MovieService.cs index e6b1a0842..6d359d7a3 100644 --- a/src/NzbDrone.Core/Tv/MovieService.cs +++ b/src/NzbDrone.Core/Tv/MovieService.cs @@ -110,15 +110,16 @@ namespace NzbDrone.Core.Tv m.Added = DateTime.UtcNow; }); - //var existingMovies = GetAllMovies(); - //var potentialMovieCount = newMovies.Count; + var existingMovies = GetAllMovies(); + var potentialMovieCount = newMovies.Count; - //newMovies = newMovies.ExceptBy(n => n.TitleSlug, existingMovies, e => e.TitleSlug, StringComparer.InvariantCultureIgnoreCase).ToList(); + newMovies = newMovies.DistinctBy(movie => movie.TmdbId).ToList(); // Ensure we don't add the same movie twice + + newMovies = newMovies.ExceptBy(n => n.TmdbId, existingMovies, e => e.TmdbId, EqualityComparer.Default).ToList(); // Ensure we don't add a movie that already exists _movieRepository.InsertMany(newMovies); - //_logger.Debug("Adding {0} movies, {1} duplicates detected", newMovies.Count, potentialMovieCount - newMovies.Count); - _logger.Debug("Adding {0} movies", newMovies.Count); + _logger.Debug("Adding {0} movies, {1} duplicates detected and skipped", newMovies.Count, potentialMovieCount - newMovies.Count); newMovies.ForEach(m => {