Merge 10e27923c0
into a91a9f7fd9
commit
b27f931447
@ -0,0 +1,61 @@
|
||||
using FizzWare.NBuilder;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.CustomFormats
|
||||
{
|
||||
[TestFixture]
|
||||
public class IndexerSpecificationFixture : CoreTest<IndexerSpecification>
|
||||
{
|
||||
private CustomFormatInput _movieInput;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_movieInput = new CustomFormatInput
|
||||
{
|
||||
Movie = Builder<Movie>.CreateNew().Build()
|
||||
};
|
||||
}
|
||||
|
||||
private void GivenCustomFormatIndexer(int indexerId)
|
||||
{
|
||||
Subject.Value = indexerId;
|
||||
}
|
||||
|
||||
private void GivenMovieReleaseIndexer(int indexerId)
|
||||
{
|
||||
_movieInput.IndexerId = indexerId;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_indexer_id_not_captured()
|
||||
{
|
||||
GivenCustomFormatIndexer(4);
|
||||
GivenMovieReleaseIndexer(-1);
|
||||
|
||||
Subject.IsSatisfiedBy(_movieInput).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_indexer_id_does_not_match_custom_format()
|
||||
{
|
||||
GivenCustomFormatIndexer(4);
|
||||
GivenMovieReleaseIndexer(3);
|
||||
|
||||
Subject.IsSatisfiedBy(_movieInput).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_indexer_id_matches_custom_format()
|
||||
{
|
||||
GivenCustomFormatIndexer(4);
|
||||
GivenMovieReleaseIndexer(4);
|
||||
|
||||
Subject.IsSatisfiedBy(_movieInput).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using FluentValidation;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Validation;
|
||||
|
||||
namespace NzbDrone.Core.CustomFormats
|
||||
{
|
||||
public class IndexerSpecificationValidator : AbstractValidator<IndexerSpecification>
|
||||
{
|
||||
public IndexerSpecificationValidator()
|
||||
{
|
||||
RuleFor(c => c.Value).GreaterThan(0);
|
||||
}
|
||||
}
|
||||
|
||||
public class IndexerSpecification : CustomFormatSpecificationBase
|
||||
{
|
||||
private static readonly IndexerSpecificationValidator Validator = new IndexerSpecificationValidator();
|
||||
|
||||
public override int Order => 4;
|
||||
public override string ImplementationName => "Indexer";
|
||||
|
||||
[FieldDefinition(1, Label = "Indexer", Type = FieldType.Select, SelectOptionsProviderAction = "indexers")]
|
||||
public int Value { get; set; }
|
||||
|
||||
protected override bool IsSatisfiedByWithoutNegate(CustomFormatInput input)
|
||||
{
|
||||
return input.IndexerId == Value;
|
||||
}
|
||||
|
||||
public override NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using FluentMigrator;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(234)]
|
||||
public class add_indexer_id_columns : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Alter.Table("Blocklist").AddColumn("IndexerId").AsInt32().WithDefaultValue(-1);
|
||||
Alter.Table("MovieFiles").AddColumn("IndexerId").AsInt32().WithDefaultValue(-1);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using Radarr.Http;
|
||||
|
||||
namespace Radarr.Api.V3.Specifications
|
||||
{
|
||||
[V3ApiController]
|
||||
public class SpecificationsController : Controller
|
||||
{
|
||||
private readonly IIndexerFactory _indexerFactory;
|
||||
|
||||
public SpecificationsController(IIndexerFactory indexerFactory)
|
||||
{
|
||||
_indexerFactory = indexerFactory;
|
||||
}
|
||||
|
||||
[HttpPost("action/indexers")]
|
||||
public object GetIndexers()
|
||||
{
|
||||
return new
|
||||
{
|
||||
options = _indexerFactory.All().Select(o => new FieldSelectOption { Value = o.Id, Name = o.Name }).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue