mirror of https://github.com/lidarr/Lidarr
Fix issue adding a artist when NameSlug for another artist null
Sonarr '413ce1d9a
This commit is contained in:
parent
5003cd8a14
commit
e8fb678fb8
|
@ -0,0 +1,76 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using FluentValidation.Validators;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
using NzbDrone.Core.Music;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.TvTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ArtistNameSlugValidatorFixture : CoreTest<ArtistSlugValidator>
|
||||
{
|
||||
private List<Artist> _artist;
|
||||
private TestValidator<Artist> _validator;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_artist = Builder<Artist>.CreateListOfSize(1)
|
||||
.Build()
|
||||
.ToList();
|
||||
|
||||
_validator = new TestValidator<Artist>
|
||||
{
|
||||
v => v.RuleFor(s => s.NameSlug).SetValidator(Subject)
|
||||
};
|
||||
|
||||
Mocker.GetMock<IArtistService>()
|
||||
.Setup(s => s.GetAllArtists())
|
||||
.Returns(_artist);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_be_valid_if_there_is_an_existing_artist_with_the_same_title_slug()
|
||||
{
|
||||
var series = Builder<Artist>.CreateNew()
|
||||
.With(s => s.Id = 100)
|
||||
.With(s => s.NameSlug = _artist.First().NameSlug)
|
||||
.Build();
|
||||
|
||||
_validator.Validate(series).IsValid.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_valid_if_there_is_not_an_existing_artist_with_the_same_title_slug()
|
||||
{
|
||||
var series = Builder<Artist>.CreateNew()
|
||||
.With(s => s.NameSlug = "MyNameSlug")
|
||||
.Build();
|
||||
|
||||
_validator.Validate(series).IsValid.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_valid_if_there_is_an_existing_artist_with_a_null_title_slug()
|
||||
{
|
||||
_artist.First().NameSlug = null;
|
||||
|
||||
var series = Builder<Artist>.CreateNew()
|
||||
.With(s => s.NameSlug = "MyNameSlug")
|
||||
.Build();
|
||||
|
||||
_validator.Validate(series).IsValid.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_valid_when_updating_an_existing_artist()
|
||||
{
|
||||
_validator.Validate(_artist.First().JsonClone()).IsValid.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -283,6 +283,7 @@
|
|||
<Compile Include="MetadataSource\SearchSeriesComparerFixture.cs" />
|
||||
<Compile Include="MetadataSource\SkyHook\SkyHookProxyFixture.cs" />
|
||||
<Compile Include="MusicTests\AddArtistFixture.cs" />
|
||||
<Compile Include="MusicTests\ArtistNameSlugValidatorFixture.cs" />
|
||||
<Compile Include="NotificationTests\NotificationBaseFixture.cs" />
|
||||
<Compile Include="NotificationTests\SynologyIndexerFixture.cs" />
|
||||
<Compile Include="OrganizerTests\FileNameBuilderTests\CleanTitleFixture.cs" />
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
using FluentValidation.Validators;
|
||||
using System.Linq;
|
||||
using FluentValidation.Validators;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace NzbDrone.Core.Music
|
||||
|
@ -23,7 +24,9 @@ namespace NzbDrone.Core.Music
|
|||
dynamic instance = context.ParentContext.InstanceToValidate;
|
||||
var instanceId = (int)instance.Id;
|
||||
|
||||
return !_artistService.GetAllArtists().Exists(s => s.NameSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId);
|
||||
return !_artistService.GetAllArtists().Where(s => s.NameSlug.IsNotNullOrWhiteSpace())
|
||||
.ToList()
|
||||
.Exists(s => s.NameSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@
|
|||
<Compile Include="StringExtensions.cs" />
|
||||
<Compile Include="TestBase.cs" />
|
||||
<Compile Include="TestException.cs" />
|
||||
<Compile Include="TestValidator.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="AutoMoq\License.txt" />
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
using System;
|
||||
using FluentValidation;
|
||||
|
||||
namespace NzbDrone.Test.Common
|
||||
{
|
||||
public class TestValidator<T> : InlineValidator<T>
|
||||
{
|
||||
public TestValidator(params Action<TestValidator<T>>[] actions)
|
||||
{
|
||||
foreach (var action in actions)
|
||||
{
|
||||
action(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue