1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-27 02:07:41 +00:00

fixed broken test, cleaned up some code around config contracts.

This commit is contained in:
kayone 2013-09-24 17:01:03 -07:00
parent eaed756655
commit e8b2d1fda0
7 changed files with 26 additions and 5 deletions

View file

@ -57,6 +57,8 @@ namespace NzbDrone.Api.ClientSchema
public static object ReadFormSchema(List<Field> fields, Type targetType)
{
Ensure.That(() => targetType).IsNotNull();
var properties = targetType.GetSimpleProperties();
var target = Activator.CreateInstance(targetType);

View file

@ -62,7 +62,7 @@ namespace NzbDrone.Common.Reflection
public static Type FindTypeByName(this Assembly assembly, string name)
{
return assembly.GetTypes().Single(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
return assembly.GetTypes().SingleOrDefault(c => c.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase));
}
public static bool HasAttribute<TAttribute>(this Type type)

View file

@ -71,6 +71,7 @@ namespace NzbDrone.Core.Test.IndexerTests
var existingIndexers = Builder<IndexerDefinition>.CreateNew().BuildNew();
existingIndexers.ConfigContract = typeof (NewznabSettings).Name;
repo.Insert(existingIndexers);

View file

@ -23,11 +23,15 @@ namespace NzbDrone.Core.Datastore.Converters
}
var ordinal = context.DataRecord.GetOrdinal("ConfigContract");
var implementation = context.DataRecord.GetString(ordinal);
var contract = context.DataRecord.GetString(ordinal);
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(implementation);
var impType = typeof (IProviderConfig).Assembly.FindTypeByName(contract);
if (impType == null)
{
throw new ConfigContractNotFoundException(contract);
}
return Json.Deserialize(stringValue, impType);
}

View file

@ -414,6 +414,7 @@
<Compile Include="Parser\Parser.cs" />
<Compile Include="Parser\ParsingService.cs" />
<Compile Include="Parser\QualityParser.cs" />
<Compile Include="ThingiProvider\ConfigContractNotFoundException.cs" />
<Compile Include="ThingiProvider\IProvider.cs" />
<Compile Include="Qualities\QualityProfileInUseException.cs" />
<Compile Include="Qualities\QualitySizeRepository.cs" />

View file

@ -0,0 +1,13 @@
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Core.ThingiProvider
{
public class ConfigContractNotFoundException : NzbDroneException
{
public ConfigContractNotFoundException(string contract)
: base("Couldn't find config contract " + contract)
{
}
}
}

View file

@ -48,7 +48,7 @@ namespace NzbDrone.Core.ThingiProvider
{
ConfigContract = p.ConfigContract.Name,
Implementation = p.GetType().Name,
Settings = (IProviderConfig)Activator.CreateInstance(ReflectionExtensions.CoreAssembly.FindTypeByName(p.ConfigContract.Name))
Settings = (IProviderConfig)Activator.CreateInstance(p.ConfigContract)
}).ToList();
}