From 1877f70403860e8a45ba60571a7d2c997fdee4c4 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 2 May 2013 22:24:52 -0700 Subject: [PATCH] fixed server side indexer issue --- .../ClientSchemaTests/SchemaBuilderFixture.cs | 3 ++ .../ClientSchema/FieldDefinitionAttribute.cs | 12 ------- NzbDrone.Api/ClientSchema/SchemaBuilder.cs | 35 +++++++++++-------- NzbDrone.Api/Frontend/StaticResourceMapper.cs | 2 +- NzbDrone.Api/Indexers/IndexerModule.cs | 10 +++--- .../NzbDrone.Common.Test.ncrunchproject | 30 ---------------- .../Annotations/FieldDefinitionAttribute.cs | 17 +++++++++ .../Indexers/Newznab/NewznabSettings.cs | 4 +++ .../Indexers/NzbsRUs/NzbsrusSettings.cs | 6 +++- .../Indexers/Omgwtfnzbs/OmgwtfnzbsSettings.cs | 4 +++ NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Client/IndexerClient.cs | 16 +++++++++ .../IndexerIntegrationFixture.cs | 22 ++++++++++++ NzbDrone.Integration.Test/IntegrationTest.cs | 3 ++ .../NzbDrone.Integration.Test.csproj | 2 ++ 15 files changed, 104 insertions(+), 63 deletions(-) create mode 100644 NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs create mode 100644 NzbDrone.Integration.Test/Client/IndexerClient.cs create mode 100644 NzbDrone.Integration.Test/IndexerIntegrationFixture.cs diff --git a/NzbDrone.Api.Test/ClientSchemaTests/SchemaBuilderFixture.cs b/NzbDrone.Api.Test/ClientSchemaTests/SchemaBuilderFixture.cs index d80aed440..f68bcb2ef 100644 --- a/NzbDrone.Api.Test/ClientSchemaTests/SchemaBuilderFixture.cs +++ b/NzbDrone.Api.Test/ClientSchemaTests/SchemaBuilderFixture.cs @@ -1,6 +1,7 @@ using FluentAssertions; using NUnit.Framework; using NzbDrone.Api.ClientSchema; +using NzbDrone.Core.Annotations; using NzbDrone.Test.Common; namespace NzbDrone.Api.Test.ClientSchemaTests @@ -41,5 +42,7 @@ public class TestModel [FieldDefinition(1, Label = "Last Name", HelpText = "Your Last Name")] public string LastName { get; set; } + + public string Other { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Api/ClientSchema/FieldDefinitionAttribute.cs b/NzbDrone.Api/ClientSchema/FieldDefinitionAttribute.cs index 1c1c06699..72fdeb408 100644 --- a/NzbDrone.Api/ClientSchema/FieldDefinitionAttribute.cs +++ b/NzbDrone.Api/ClientSchema/FieldDefinitionAttribute.cs @@ -2,17 +2,5 @@ namespace NzbDrone.Api.ClientSchema { - [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] - public class FieldDefinitionAttribute : Attribute - { - public FieldDefinitionAttribute(int order) - { - Order = order; - } - - public int Order { get; private set; } - public string Label { get; set; } - public string HelpText { get; set; } - } } \ No newline at end of file diff --git a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs index 8be6507b6..c91b5502b 100644 --- a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs +++ b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using NzbDrone.Common.Reflection; +using NzbDrone.Core.Annotations; namespace NzbDrone.Api.ClientSchema { @@ -13,24 +14,28 @@ public static List GenerateSchema(object model) foreach (var propertyInfo in properties) { - var fieldAttribute = propertyInfo.GetAttribute(); + var fieldAttribute = propertyInfo.GetAttribute(false); - var field = new Field() - { - Name = propertyInfo.Name, - Label = fieldAttribute.Label, - HelpText = fieldAttribute.HelpText, - Order = fieldAttribute.Order, - - }; - - var value = propertyInfo.GetValue(model, null); - if (value != null) + if (fieldAttribute != null) { - field.Value = value.ToString(); - } - result.Add(field); + var field = new Field() + { + Name = propertyInfo.Name, + Label = fieldAttribute.Label, + HelpText = fieldAttribute.HelpText, + Order = fieldAttribute.Order, + + }; + + var value = propertyInfo.GetValue(model, null); + if (value != null) + { + field.Value = value.ToString(); + } + + result.Add(field); + } } return result; diff --git a/NzbDrone.Api/Frontend/StaticResourceMapper.cs b/NzbDrone.Api/Frontend/StaticResourceMapper.cs index 9ef688ee0..f8b4fa738 100644 --- a/NzbDrone.Api/Frontend/StaticResourceMapper.cs +++ b/NzbDrone.Api/Frontend/StaticResourceMapper.cs @@ -15,7 +15,7 @@ public string Map(string resourceUrl) path = path.Trim(Path.DirectorySeparatorChar).ToLower(); - return Path.Combine("ui", path); + return Path.Combine(Directory.GetCurrentDirectory(), "ui", path); } } } \ No newline at end of file diff --git a/NzbDrone.Api/Indexers/IndexerModule.cs b/NzbDrone.Api/Indexers/IndexerModule.cs index 5931efbab..829dd1572 100644 --- a/NzbDrone.Api/Indexers/IndexerModule.cs +++ b/NzbDrone.Api/Indexers/IndexerModule.cs @@ -21,11 +21,13 @@ private List GetAll() var result = new List(indexers.Count); - foreach (var indexerDefinition in indexers) + foreach (var indexer in indexers) { - var resource = new IndexerResource(); - resource.InjectFrom(indexerDefinition); - resource.Fields = SchemaBuilder.GenerateSchema(indexerDefinition.Settings); + var indexerResource = new IndexerResource(); + indexerResource.InjectFrom(indexer); + indexerResource.Fields = SchemaBuilder.GenerateSchema(indexer.Settings); + + result.Add(indexerResource); } return result; diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject b/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject index f5ddf272f..033287d89 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.ncrunchproject @@ -23,38 +23,8 @@ NzbDrone.Common.Test.EnviromentProviderTest.ApplicationPath_should_find_root_in_current_folder - - NzbDrone.Common.Test.ProcessProviderTests.Should_be_able_to_kill_procces - - - NzbDrone.Common.Test.ProcessProviderTests.Should_be_able_to_start_process - - - NzbDrone.Common.Test.ServiceProviderTests.Service_should_be_installed_and_then_uninstalled - - - NzbDrone.Common.Test.ServiceProviderTests.Should_be_able_to_start_and_stop_service - - - NzbDrone\.Common\.Test\.ConfigFileProviderTest\..* - - - NzbDrone\.Common\.Test\.EnvironmentProviderTest\..* - NzbDrone\.Common\.Test\.EventingTests\.ServiceNameFixture\..* - - NzbDrone\.Common\.Test\.ProcessProviderTests\..* - - - NzbDrone\.Common\.Test\.ReportingService_ReportParseError_Fixture\..* - - - NzbDrone\.Common\.Test\.ServiceProviderTests\..* - - - NzbDrone\.Common\.Test\.WebClientTests\..* - \ No newline at end of file diff --git a/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs b/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs new file mode 100644 index 000000000..33a5b8095 --- /dev/null +++ b/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs @@ -0,0 +1,17 @@ +using System; + +namespace NzbDrone.Core.Annotations +{ + [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] + public class FieldDefinitionAttribute : Attribute + { + public FieldDefinitionAttribute(int order) + { + Order = order; + } + + public int Order { get; private set; } + public string Label { get; set; } + public string HelpText { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs b/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs index a24d5d15b..291e7fc7d 100644 --- a/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs +++ b/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs @@ -1,10 +1,14 @@ using System; +using NzbDrone.Core.Annotations; namespace NzbDrone.Core.Indexers.Newznab { public class NewznabSettings : IIndexerSetting { + [FieldDefinition(0, Label = "URL", HelpText = "NewzNab Host Url")] public String Url { get; set; } + + [FieldDefinition(1, Label = "API Key", HelpText = "Your API Key")] public String ApiKey { get; set; } public bool IsValid diff --git a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs b/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs index 70e217ab4..7d21e1171 100644 --- a/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs +++ b/NzbDrone.Core/Indexers/NzbsRUs/NzbsrusSettings.cs @@ -1,12 +1,16 @@ using System; +using NzbDrone.Core.Annotations; namespace NzbDrone.Core.Indexers.NzbsRUs { public class NzbsrusSetting : IIndexerSetting { + [FieldDefinition(0, Label = "UID", HelpText = "Your NzbsRus User ID")] public String Uid { get; set; } + + [FieldDefinition(1, Label = "Hash", HelpText = "Your API Hash Key")] public String Hash { get; set; } - + public bool IsValid { get diff --git a/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsSettings.cs b/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsSettings.cs index 429b1de06..eba7d2d04 100644 --- a/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsSettings.cs +++ b/NzbDrone.Core/Indexers/Omgwtfnzbs/OmgwtfnzbsSettings.cs @@ -1,10 +1,14 @@ using System; +using NzbDrone.Core.Annotations; namespace NzbDrone.Core.Indexers.Omgwtfnzbs { public class OmgwtfnzbsSetting : IIndexerSetting { + [FieldDefinition(0, Label = "Username", HelpText = "Your Username")] public String Username { get; set; } + + [FieldDefinition(1, Label = "API Key", HelpText = "Your API Key")] public String ApiKey { get; set; } public bool IsValid diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 8d1f7652b..fe9ac65ed 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -176,6 +176,7 @@ Properties\SharedAssemblyInfo.cs + diff --git a/NzbDrone.Integration.Test/Client/IndexerClient.cs b/NzbDrone.Integration.Test/Client/IndexerClient.cs new file mode 100644 index 000000000..44f5d4c77 --- /dev/null +++ b/NzbDrone.Integration.Test/Client/IndexerClient.cs @@ -0,0 +1,16 @@ +using NzbDrone.Api.Indexers; +using RestSharp; + +namespace NzbDrone.Integration.Test.Client +{ + public class IndexerClient : ClientBase + { + public IndexerClient(IRestClient restClient) + : base(restClient) + { + } + + + + } +} \ No newline at end of file diff --git a/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs b/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs new file mode 100644 index 000000000..36a416c51 --- /dev/null +++ b/NzbDrone.Integration.Test/IndexerIntegrationFixture.cs @@ -0,0 +1,22 @@ +using System.IO; +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Api.RootFolders; + +namespace NzbDrone.Integration.Test +{ + [TestFixture] + public class IndexerIntegrationFixture : IntegrationTest + { + [Test] + public void should_have_built_in_indexer() + { + var indexers = Indexers.All(); + + + indexers.Should().NotBeEmpty(); + indexers.Should().NotContain(c => string.IsNullOrWhiteSpace(c.Name)); + + } + } +} \ No newline at end of file diff --git a/NzbDrone.Integration.Test/IntegrationTest.cs b/NzbDrone.Integration.Test/IntegrationTest.cs index 2d9bfdbeb..9dcb6417f 100644 --- a/NzbDrone.Integration.Test/IntegrationTest.cs +++ b/NzbDrone.Integration.Test/IntegrationTest.cs @@ -7,6 +7,7 @@ using Nancy.Hosting.Self; using NzbDrone.Api; using NzbDrone.Api.Commands; +using NzbDrone.Api.Indexers; using NzbDrone.Api.RootFolders; using NzbDrone.Common; using NzbDrone.Core.Datastore; @@ -32,6 +33,7 @@ public abstract class IntegrationTest protected ClientBase RootFolders; protected ClientBase Commands; protected ReleaseClient Releases; + protected IndexerClient Indexers; static IntegrationTest() { @@ -89,6 +91,7 @@ public void SmokeTestSetup() Releases = new ReleaseClient(RestClient); RootFolders = new ClientBase(RestClient); Commands = new ClientBase(RestClient); + Indexers = new IndexerClient(RestClient); _host.Start(); } diff --git a/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj b/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj index fa149038b..c5ffa7733 100644 --- a/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj +++ b/NzbDrone.Integration.Test/NzbDrone.Integration.Test.csproj @@ -68,9 +68,11 @@ + +