Improve use of All() for Path related queries

Signed-off-by: Robin Dadswell <robin@dadswell.email>
test-rebase
Qstick 4 years ago committed by nitsua
parent ac4a82abf4
commit 15e0b8dd4d

@ -33,9 +33,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
_metadata = Builder<MetadataFile>.CreateListOfSize(1)
.Build().ToList();
Mocker.GetMock<IAuthorService>()
.Setup(c => c.GetAllAuthors())
.Returns(_artist);
Mocker.GetMock<IArtistService>()
.Setup(c => c.AllArtistPaths())
.Returns(_artist.ToDictionary(x => x.Id, x => x.Path));
Mocker.GetMock<IMetadataFileService>()
.Setup(c => c.GetFilesByAuthor(_artist.First().Id))
@ -73,7 +73,7 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
Subject.Clean();
Mocker.GetMock<IConfigService>().VerifySet(c => c.CleanupMetadataImages = true, Times.Never());
Mocker.GetMock<IAuthorService>().Verify(c => c.GetAllAuthors(), Times.Never());
Mocker.GetMock<IArtistService>().Verify(c => c.GetAllAuthors(), Times.Never());
AssertImageWasNotRemoved();
}

@ -24,9 +24,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
.Build()
.ToList();
Mocker.GetMock<IAuthorService>()
.Setup(s => s.GetAllAuthors())
.Returns(artist);
Mocker.GetMock<IArtistService>()
.Setup(s => s.AllArtistPaths())
.Returns(artist.ToDictionary(x => x.Id, x => x.Path));
Mocker.GetMock<IImportListFactory>()
.Setup(s => s.All())
@ -44,9 +44,9 @@ namespace NzbDrone.Core.Test.HealthCheck.Checks
[Test]
public void should_not_return_error_when_no_artist()
{
Mocker.GetMock<IAuthorService>()
.Setup(s => s.GetAllAuthors())
.Returns(new List<Author>());
Mocker.GetMock<IArtistService>()
.Setup(s => s.AllArtistPaths())
.Returns(new Dictionary<int, string>());
Mocker.GetMock<IImportListFactory>()
.Setup(s => s.All())

@ -43,14 +43,14 @@ namespace NzbDrone.Core.Housekeeping.Housekeepers
foreach (var author in artists)
{
var images = _metaFileService.GetFilesByAuthor(author.Id)
var images = _metaFileService.GetFilesByAuthor(author.Key)
.Where(c => c.LastUpdated > new DateTime(2014, 12, 27) && imageExtensions.Any(x => c.RelativePath.EndsWith(x, StringComparison.InvariantCultureIgnoreCase)));
foreach (var image in images)
{
try
{
var path = Path.Combine(author.Path, image.RelativePath);
var path = Path.Combine(author.Value, image.RelativePath);
if (!IsValid(path))
{
_logger.Debug("Deleting invalid image file " + path);

@ -104,22 +104,22 @@ namespace NzbDrone.Core.MediaFiles
if (message.DeleteFiles)
{
var author = message.Author;
var allArtists = _authorService.GetAllAuthors();
var allArtists = _artistService.GetAllAuthors();
foreach (var s in allArtists)
{
if (s.Id == author.Id)
if (s.Key == artist.Id)
{
continue;
}
if (author.Path.IsParentPath(s.Path))
if (author.Path.IsParentPath(s.Value))
{
_logger.Error("Author path: '{0}' is a parent of another author, not deleting files.", author.Path);
return;
}
if (author.Path.PathEquals(s.Path))
if (author.Path.PathEquals(s.Value))
{
_logger.Error("Author path: '{0}' is the same as another author, not deleting files.", author.Path);
return;

@ -22,7 +22,7 @@ namespace NzbDrone.Core.Validation.Paths
return true;
}
return !_authorService.GetAllAuthors().Any(s => context.PropertyValue.ToString().IsParentPath(s.Path));
return !_artistService.GetAllAuthors().Any(s => context.PropertyValue.ToString().IsParentPath(s.Value));
}
}
}

@ -1,4 +1,5 @@
using FluentValidation.Validators;
using System.Linq;
using FluentValidation.Validators;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Books;
@ -24,7 +25,7 @@ namespace NzbDrone.Core.Validation.Paths
dynamic instance = context.ParentContext.InstanceToValidate;
var instanceId = (int)instance.Id;
return !_authorService.GetAllAuthors().Exists(s => s.Path.PathEquals(context.PropertyValue.ToString()) && s.Id != instanceId);
return !_authorService.GetAllAuthors().Any(s => s.Value.PathEquals(context.PropertyValue.ToString()) && s.Key != instanceId);
}
}
}

Loading…
Cancel
Save