1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 07:22:35 +01:00

Fix issue adding a series when TitleSlug for another series is null

Fixed: Adding a series when an existing series is has a null slug
Closes #1840
This commit is contained in:
Mark McDowall 2017-04-11 17:57:29 -07:00
parent b63bcd16a7
commit 41f769790d
7 changed files with 109 additions and 2 deletions

View File

@ -383,6 +383,7 @@
<Compile Include="TvTests\SeriesServiceTests\UpdateMultipleSeriesFixture.cs" />
<Compile Include="TvTests\SeriesServiceTests\UpdateSeriesFixture.cs" />
<Compile Include="TvTests\SeriesTitleNormalizerFixture.cs" />
<Compile Include="TvTests\SeriesTitleSlugValidatorFixture.cs" />
<Compile Include="TvTests\ShouldRefreshSeriesFixture.cs" />
<Compile Include="UpdateTests\UpdatePackageProviderFixture.cs" />
<Compile Include="UpdateTests\UpdateServiceFixture.cs" />

View File

@ -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.Tv;
using NzbDrone.Test.Common;
namespace NzbDrone.Core.Test.TvTests
{
[TestFixture]
public class SeriesTitleSlugValidatorFixture : CoreTest<SeriesTitleSlugValidator>
{
private List<Series> _series;
private TestValidator<Series> _validator;
[SetUp]
public void Setup()
{
_series = Builder<Series>.CreateListOfSize(1)
.Build()
.ToList();
_validator = new TestValidator<Series>
{
v => v.RuleFor(s => s.TitleSlug).SetValidator(Subject)
};
Mocker.GetMock<ISeriesService>()
.Setup(s => s.GetAllSeries())
.Returns(_series);
}
[Test]
public void should_not_be_valid_if_there_is_an_existing_series_with_the_same_title_slug()
{
var series = Builder<Series>.CreateNew()
.With(s => s.Id = 100)
.With(s => s.TitleSlug = _series.First().TitleSlug)
.Build();
_validator.Validate(series).IsValid.Should().BeFalse();
}
[Test]
public void should_be_valid_if_there_is_not_an_existing_series_with_the_same_title_slug()
{
var series = Builder<Series>.CreateNew()
.With(s => s.TitleSlug = "MyTitleSlug")
.Build();
_validator.Validate(series).IsValid.Should().BeTrue();
}
[Test]
public void should_be_valid_if_there_is_an_existing_series_with_a_null_title_slug()
{
_series.First().TitleSlug = null;
var series = Builder<Series>.CreateNew()
.With(s => s.TitleSlug = "MyTitleSlug")
.Build();
_validator.Validate(series).IsValid.Should().BeTrue();
}
[Test]
public void should_be_valid_when_updating_an_existing_series()
{
_validator.Validate(_series.First().JsonClone()).IsValid.Should().BeTrue();
}
}
}

View File

@ -1,4 +1,6 @@
using FluentValidation.Validators;
using System.Linq;
using FluentValidation.Validators;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Tv
{
@ -16,10 +18,13 @@ namespace NzbDrone.Core.Tv
{
if (context.PropertyValue == null) return true;
dynamic instance = context.ParentContext.InstanceToValidate;
var instanceId = (int)instance.Id;
return !_seriesService.GetAllSeries().Exists(s => s.TitleSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId);
return !_seriesService.GetAllSeries().Where(s => s.TitleSlug.IsNotNullOrWhiteSpace())
.ToList()
.Exists(s => s.TitleSlug.Equals(context.PropertyValue.ToString()) && s.Id != instanceId);
}
}
}

View File

@ -21,6 +21,10 @@
<assemblyIdentity name="Microsoft.Practices.Unity" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.1.505.0" newVersion="2.1.505.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Practices.ServiceLocation" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -43,6 +43,9 @@
<Reference Include="FluentAssertions.Core, Version=4.19.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.19.0\lib\net40\FluentAssertions.Core.dll</HintPath>
</Reference>
<Reference Include="FluentValidation, Version=6.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\FluentValidation.6.2.1.0\lib\portable-net40+sl50+wp80+win8+wpa81\FluentValidation.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
@ -94,6 +97,7 @@
<Compile Include="StringExtensions.cs" />
<Compile Include="TestBase.cs" />
<Compile Include="TestException.cs" />
<Compile Include="TestValidator.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="AutoMoq\License.txt" />

View File

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

View File

@ -2,6 +2,7 @@
<packages>
<package id="CommonServiceLocator" version="1.3" targetFramework="net40" />
<package id="FluentAssertions" version="4.19.0" targetFramework="net40" />
<package id="FluentValidation" version="6.2.1.0" targetFramework="net40" />
<package id="Moq" version="4.0.10827" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" />
<package id="NLog" version="4.4.3" targetFramework="net40" />