Patch/bulk import tests (#833)

* Ensure duplicates are not imported

* Clean up some unnecessary code

* Added some fancy tests for bulk import.
v0.2.0.375
Tim Turner 8 years ago committed by Leonardo Galli
parent 056fb154a8
commit 89e5001bad

@ -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));

@ -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<MovieService>
{
private List<Movie> fakeMovies;
[SetUp]
public void Setup()
{
fakeMovies = Builder<Movie>.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<IBuildFileNames>()
.Setup(s => s.GetMovieFolder(It.IsAny<Movie>(), 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<IBuildFileNames>()
.Setup(s => s.GetMovieFolder(It.IsAny<Movie>(), null))
.Returns((Movie m, NamingConfig n) => m.Title);
Mocker.GetMock<IMovieRepository>().Setup(s => s.All()).Returns(new List<Movie> { fakeMovies[0] });
var movies = Subject.AddMovies(fakeMovies);
Mocker.GetMock<IMovieRepository>().Verify(v => v.InsertMany(It.Is<List<Movie>>(l => l.Count == 2)));
}
[Test]
public void movies_added_should_ignore_duplicates()
{
Mocker.GetMock<IBuildFileNames>()
.Setup(s => s.GetMovieFolder(It.IsAny<Movie>(), null))
.Returns((Movie m, NamingConfig n) => m.Title);
fakeMovies[2].TmdbId = fakeMovies[0].TmdbId;
var movies = Subject.AddMovies(fakeMovies);
Mocker.GetMock<IMovieRepository>().Verify(v => v.InsertMany(It.Is<List<Movie>>(l => l.Count == 2)));
}
}
}

@ -384,6 +384,7 @@
<Compile Include="UpdateTests\UpdatePackageProviderFixture.cs" />
<Compile Include="UpdateTests\UpdateServiceFixture.cs" />
<Compile Include="XbmcVersionTests.cs" />
<Compile Include="BulkImport\AddMultiMoviesFixture.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Marr.Data\Marr.Data.csproj">
@ -575,6 +576,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="ProviderTests\UpdateProviderTests\" />
<Folder Include="BulkImport\" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />

@ -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<SeriesService>
{
private Series fakeSeries;
[SetUp]
public void Setup()
{
fakeSeries = Builder<Series>.CreateNew().Build();
}
[Test]
public void series_added_event_should_have_proper_path()
{
fakeSeries.Path = null;
fakeSeries.RootFolderPath = @"C:\Test\TV";
Mocker.GetMock<IBuildFileNames>()
.Setup(s => s.GetSeriesFolder(fakeSeries, null))
.Returns(fakeSeries.Title);
var series = Subject.AddSeries(fakeSeries);
series.Path.Should().NotBeNull();
VerifyEventPublished<SeriesAddedEvent>();
}
}
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<SeriesService>
{
private Series fakeSeries;
[SetUp]
public void Setup()
{
fakeSeries = Builder<Series>.CreateNew().Build();
}
[Test]
public void series_added_event_should_have_proper_path()
{
fakeSeries.Path = null;
fakeSeries.RootFolderPath = @"C:\Test\TV";
Mocker.GetMock<IBuildFileNames>()
.Setup(s => s.GetSeriesFolder(fakeSeries, null))
.Returns(fakeSeries.Title);
var series = Subject.AddSeries(fakeSeries);
series.Path.Should().NotBeNull();
}
}
}

@ -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<int>.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 =>
{

Loading…
Cancel
Save