From 687f8d93849a54484daffc14bba67faccfe8b449 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 12 May 2013 19:52:55 -0700 Subject: [PATCH] fixed disk scan scheduler. --- NzbDrone.Api/Commands/CommandModule.cs | 2 +- .../Extensions/NancyJsonSerializer.cs | 10 +-- NzbDrone.Api/Extensions/RequestExtensions.cs | 6 +- NzbDrone.Api/SignalR/Serializer.cs | 15 ++--- .../MessageAggregatorCommandTests.cs | 15 +++++ .../Messaging/IMessageAggregator.cs | 5 +- .../Messaging/MessageAggregator.cs | 23 ++++++- NzbDrone.Common/NzbDrone.Common.csproj | 2 +- NzbDrone.Common/Serializer/Json.cs | 58 ++++++++++++++++ NzbDrone.Common/Serializer/JsonSerializer.cs | 66 ------------------- NzbDrone.Common/ServiceFactory.cs | 6 ++ .../Datastore/MappingExtentionFixture.cs | 4 +- .../DailySeries/DailySeriesDataProxy.cs | 6 +- .../Scene/SceneMappingProxy.cs | 8 +-- .../Converters/EmbeddedDocumentConverter.cs | 10 +-- NzbDrone.Core/Datastore/TableMapping.cs | 2 +- NzbDrone.Core/Indexers/IndexerWithSetting.cs | 2 +- NzbDrone.Core/Indexers/Newznab/Newznab.cs | 8 +-- NzbDrone.Core/Jobs/TaskManager.cs | 4 +- .../Client/ClientBase.cs | 7 +- .../{Json => JsonTests}/JsonFixture.cs | 11 ++-- .../NzbDrone.Libraries.Test.csproj | 5 +- NzbDrone.Test.Common/TestBase.cs | 7 +- 23 files changed, 140 insertions(+), 142 deletions(-) create mode 100644 NzbDrone.Common/Serializer/Json.cs delete mode 100644 NzbDrone.Common/Serializer/JsonSerializer.cs rename NzbDrone.Libraries.Test/{Json => JsonTests}/JsonFixture.cs (58%) diff --git a/NzbDrone.Api/Commands/CommandModule.cs b/NzbDrone.Api/Commands/CommandModule.cs index 4db3b0f69..514d3b9e4 100644 --- a/NzbDrone.Api/Commands/CommandModule.cs +++ b/NzbDrone.Api/Commands/CommandModule.cs @@ -25,7 +25,7 @@ private CommandResource RunCommand(CommandResource resource) var commandType = _container.GetImplementations(typeof(ICommand)) .Single(c => c.Name.Replace("Command", "") - .Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase)); + .Equals(resource.Command, StringComparison.InvariantCultureIgnoreCase)); var command = Request.Body.FromJson(commandType); diff --git a/NzbDrone.Api/Extensions/NancyJsonSerializer.cs b/NzbDrone.Api/Extensions/NancyJsonSerializer.cs index 74acedac5..703aaded0 100644 --- a/NzbDrone.Api/Extensions/NancyJsonSerializer.cs +++ b/NzbDrone.Api/Extensions/NancyJsonSerializer.cs @@ -8,14 +8,6 @@ namespace NzbDrone.Api.Extensions { public class NancyJsonSerializer : ISerializer { - private readonly IJsonSerializer _jsonSerializer; - - public NancyJsonSerializer(IJsonSerializer jsonSerializer) - { - _jsonSerializer = jsonSerializer; - } - - public bool CanSerialize(string contentType) { return true; @@ -23,7 +15,7 @@ public bool CanSerialize(string contentType) public void Serialize(string contentType, TModel model, Stream outputStream) { - _jsonSerializer.Serialize(model, outputStream); + Json.Serialize(model, outputStream); } public IEnumerable Extensions { get; private set; } diff --git a/NzbDrone.Api/Extensions/RequestExtensions.cs b/NzbDrone.Api/Extensions/RequestExtensions.cs index 7c25911ac..e72fd86e7 100644 --- a/NzbDrone.Api/Extensions/RequestExtensions.cs +++ b/NzbDrone.Api/Extensions/RequestExtensions.cs @@ -2,15 +2,13 @@ using System.IO; using Nancy; using Nancy.Responses; -using NzbDrone.Common; using NzbDrone.Common.Serializer; namespace NzbDrone.Api.Extensions { public static class JsonExtensions { - private static readonly JsonSerializer Serializer = new JsonSerializer(); - private static readonly NancyJsonSerializer NancySerializer = new NancyJsonSerializer(Serializer); + private static readonly NancyJsonSerializer NancySerializer = new NancyJsonSerializer(); public static T FromJson(this Stream body) where T : class, new() { @@ -22,7 +20,7 @@ public static T FromJson(this Stream body, Type type) var reader = new StreamReader(body, true); body.Position = 0; var value = reader.ReadToEnd(); - return (T)Serializer.Deserialize(value, type); + return (T)Json.Deserialize(value, type); } public static JsonResponse AsResponse(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK) diff --git a/NzbDrone.Api/SignalR/Serializer.cs b/NzbDrone.Api/SignalR/Serializer.cs index efc5d2590..983248bcc 100644 --- a/NzbDrone.Api/SignalR/Serializer.cs +++ b/NzbDrone.Api/SignalR/Serializer.cs @@ -2,27 +2,20 @@ using System.IO; using Microsoft.AspNet.SignalR.Json; using NzbDrone.Common.Composition; +using NzbDrone.Common.Serializer; namespace NzbDrone.Api.SignalR { [Singleton] public class Serializer : IJsonSerializer { - private readonly Common.Serializer.IJsonSerializer _nzbDroneSerializer; - private readonly JsonNetSerializer _signalRSerializer; - - public Serializer(Common.Serializer.IJsonSerializer nzbDroneSerializer) - { - _signalRSerializer = new JsonNetSerializer(); - _nzbDroneSerializer = nzbDroneSerializer; - - } + private readonly JsonNetSerializer _signalRSerializer = new JsonNetSerializer(); public void Serialize(object value, TextWriter writer) { if (value.GetType().FullName.StartsWith("NzbDrone")) { - _nzbDroneSerializer.Serialize(value, writer); + Json.Serialize(value, writer); } else { @@ -35,7 +28,7 @@ public object Parse(string json, Type targetType) { if (targetType.FullName.StartsWith("NzbDrone")) { - return _nzbDroneSerializer.Deserialize(json, targetType); + return Json.Deserialize(json, targetType); } return _signalRSerializer.Parse(json, targetType); diff --git a/NzbDrone.Common.Test/EventingTests/MessageAggregatorCommandTests.cs b/NzbDrone.Common.Test/EventingTests/MessageAggregatorCommandTests.cs index 35f8b036c..a349c37b8 100644 --- a/NzbDrone.Common.Test/EventingTests/MessageAggregatorCommandTests.cs +++ b/NzbDrone.Common.Test/EventingTests/MessageAggregatorCommandTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Moq; using NUnit.Framework; using NzbDrone.Common.Messaging; @@ -38,6 +39,17 @@ public void should_publish_command_to_executor() _executorA.Verify(c => c.Execute(commandA), Times.Once()); } + [Test] + public void should_publish_command_by_with_optional_arg_with_name() + { + Mocker.GetMock().Setup(c => c.GetImplementations(typeof(ICommand))) + .Returns(new List { typeof(CommandA), typeof(CommandB) }); + + Subject.PublishCommand(typeof(CommandA).FullName); + _executorA.Verify(c => c.Execute(It.IsAny()), Times.Once()); + } + + [Test] public void should_not_publish_to_incompatible_executor() { @@ -64,7 +76,10 @@ public void broken_executor_should_throw_the_exception() public class CommandA : ICommand { + public CommandA(int id = 0) + { + } } public class CommandB : ICommand diff --git a/NzbDrone.Common/Messaging/IMessageAggregator.cs b/NzbDrone.Common/Messaging/IMessageAggregator.cs index 0022b5be0..6de5ac3c8 100644 --- a/NzbDrone.Common/Messaging/IMessageAggregator.cs +++ b/NzbDrone.Common/Messaging/IMessageAggregator.cs @@ -5,7 +5,8 @@ /// public interface IMessageAggregator { - void PublishEvent(TEvent @event) where TEvent : IEvent; - void PublishCommand(TCommand command) where TCommand : ICommand; + void PublishEvent(TEvent @event) where TEvent : class, IEvent; + void PublishCommand(TCommand command) where TCommand : class, ICommand; + void PublishCommand(string commandType); } } \ No newline at end of file diff --git a/NzbDrone.Common/Messaging/MessageAggregator.cs b/NzbDrone.Common/Messaging/MessageAggregator.cs index 18dae807c..53965ffb5 100644 --- a/NzbDrone.Common/Messaging/MessageAggregator.cs +++ b/NzbDrone.Common/Messaging/MessageAggregator.cs @@ -1,8 +1,11 @@ using System; +using System.Linq; using System.Reflection; using System.Threading.Tasks; using NLog; using NzbDrone.Common.Composition; +using NzbDrone.Common.EnsureThat; +using NzbDrone.Common.Serializer; namespace NzbDrone.Common.Messaging { @@ -18,8 +21,10 @@ public MessageAggregator(Logger logger, IServiceFactory serviceFactory) _serviceFactory = serviceFactory; } - public void PublishEvent(TEvent @event) where TEvent : IEvent + public void PublishEvent(TEvent @event) where TEvent : class ,IEvent { + Ensure.That(() => @event).IsNotNull(); + var eventName = GetEventName(@event.GetType()); _logger.Trace("Publishing {0}", eventName); @@ -63,8 +68,10 @@ private static string GetEventName(Type eventType) } - public void PublishCommand(TCommand command) where TCommand : ICommand + public void PublishCommand(TCommand command) where TCommand : class, ICommand { + Ensure.That(() => command).IsNotNull(); + var handlerContract = typeof(IExecute<>).MakeGenericType(command.GetType()); _logger.Trace("Publishing {0}", command.GetType().Name); @@ -75,7 +82,7 @@ public void PublishCommand(TCommand command) where TCommand : ICommand try { - handlerContract.GetMethod("Execute").Invoke(handler, new object[] {command}); + handlerContract.GetMethod("Execute").Invoke(handler, new object[] { command }); PublishEvent(new CommandCompletedEvent(command)); } catch (TargetInvocationException e) @@ -95,5 +102,15 @@ public void PublishCommand(TCommand command) where TCommand : ICommand _logger.Debug("{0} <- {1}", command.GetType().Name, handler.GetType().Name); } + + public void PublishCommand(string commandTypeName) + { + var commandType = _serviceFactory.GetImplementations(typeof(ICommand)) + .Single(c => c.FullName.Equals(commandTypeName, StringComparison.InvariantCultureIgnoreCase)); + + //json.net is better at creating objects + var command = Json.Deserialize("{}", commandType); + PublishCommand((ICommand)command); + } } } diff --git a/NzbDrone.Common/NzbDrone.Common.csproj b/NzbDrone.Common/NzbDrone.Common.csproj index 315f7450c..736efac11 100644 --- a/NzbDrone.Common/NzbDrone.Common.csproj +++ b/NzbDrone.Common/NzbDrone.Common.csproj @@ -103,7 +103,7 @@ - + diff --git a/NzbDrone.Common/Serializer/Json.cs b/NzbDrone.Common/Serializer/Json.cs new file mode 100644 index 000000000..2fc8e133e --- /dev/null +++ b/NzbDrone.Common/Serializer/Json.cs @@ -0,0 +1,58 @@ +using System; +using System.IO; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; + +namespace NzbDrone.Common.Serializer +{ + public static class Json + { + private static readonly JsonSerializer JsonNetSerializer; + + + static Json() + { + JsonNetSerializer = new JsonSerializer() + { + DateTimeZoneHandling = DateTimeZoneHandling.Utc, + NullValueHandling = NullValueHandling.Ignore, + Formatting = Formatting.Indented, + DefaultValueHandling = DefaultValueHandling.Include, + ContractResolver = new CamelCasePropertyNamesContractResolver() + }; + + JsonNetSerializer.Converters.Add(new StringEnumConverter { CamelCaseText = true }); + } + + public static T Deserialize(string json) where T : class, new() + { + return JsonConvert.DeserializeObject(json); + } + + public static object Deserialize(string json, Type type) + { + return JsonConvert.DeserializeObject(json, type); + } + + public static string Serialize(object obj) + { + return JsonConvert.SerializeObject(obj); + } + + + public static void Serialize(TModel model, TextWriter outputStream) + { + var jsonTextWriter = new JsonTextWriter(outputStream); + JsonNetSerializer.Serialize(jsonTextWriter, model); + jsonTextWriter.Flush(); + } + + public static void Serialize(TModel model, Stream outputStream) + { + Serialize(model, new StreamWriter(outputStream)); + } + + + } +} \ No newline at end of file diff --git a/NzbDrone.Common/Serializer/JsonSerializer.cs b/NzbDrone.Common/Serializer/JsonSerializer.cs deleted file mode 100644 index 90c39d12a..000000000 --- a/NzbDrone.Common/Serializer/JsonSerializer.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.IO; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; -using Newtonsoft.Json.Serialization; - -namespace NzbDrone.Common.Serializer -{ - public interface IJsonSerializer - { - T Deserialize(string json) where T : class, new(); - string Serialize(object obj); - void Serialize(TModel model, TextWriter textWriter); - void Serialize(TModel model, Stream outputStream); - object Deserialize(string json, Type type); - } - - public class JsonSerializer : IJsonSerializer - { - private readonly Newtonsoft.Json.JsonSerializer _jsonNetSerializer; - - public JsonSerializer() - { - _jsonNetSerializer = new Newtonsoft.Json.JsonSerializer() - { - DateTimeZoneHandling = DateTimeZoneHandling.Utc, - NullValueHandling = NullValueHandling.Ignore, - Formatting = Formatting.Indented, - DefaultValueHandling = DefaultValueHandling.Include, - ContractResolver = new CamelCasePropertyNamesContractResolver() - }; - - _jsonNetSerializer.Converters.Add(new StringEnumConverter { CamelCaseText = true }); - } - - public T Deserialize(string json) where T : class, new() - { - return JsonConvert.DeserializeObject(json); - } - - public object Deserialize(string json, Type type) - { - return JsonConvert.DeserializeObject(json, type); - } - - public string Serialize(object obj) - { - return JsonConvert.SerializeObject(obj); - } - - - public void Serialize(TModel model, TextWriter outputStream) - { - var jsonTextWriter = new JsonTextWriter(outputStream); - _jsonNetSerializer.Serialize(jsonTextWriter, model); - jsonTextWriter.Flush(); - } - - public void Serialize(TModel model, Stream outputStream) - { - Serialize(model, new StreamWriter(outputStream)); - } - - - } -} \ No newline at end of file diff --git a/NzbDrone.Common/ServiceFactory.cs b/NzbDrone.Common/ServiceFactory.cs index 4c91fe5f8..3e1d3aba9 100644 --- a/NzbDrone.Common/ServiceFactory.cs +++ b/NzbDrone.Common/ServiceFactory.cs @@ -10,6 +10,7 @@ public interface IServiceFactory T Build() where T : class; IEnumerable BuildAll() where T : class; object Build(Type contract); + IEnumerable GetImplementations(Type contract); } public class ServiceFactory : IServiceFactory @@ -35,5 +36,10 @@ public object Build(Type contract) { return _container.Resolve(contract); } + + public IEnumerable GetImplementations(Type contract) + { + return _container.GetImplementations(contract); + } } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs b/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs index b6613b071..fb8fe7b56 100644 --- a/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs +++ b/NzbDrone.Core.Test/Datastore/MappingExtentionFixture.cs @@ -41,8 +41,8 @@ public class TypeWithNoMappableProperties [SetUp] public void Setup() { - MapRepository.Instance.RegisterTypeConverter(typeof(List), new EmbeddedDocumentConverter(new JsonSerializer())); - MapRepository.Instance.RegisterTypeConverter(typeof(EmbeddedType), new EmbeddedDocumentConverter(new JsonSerializer())); + MapRepository.Instance.RegisterTypeConverter(typeof(List), new EmbeddedDocumentConverter()); + MapRepository.Instance.RegisterTypeConverter(typeof(EmbeddedType), new EmbeddedDocumentConverter()); MapRepository.Instance.RegisterTypeConverter(typeof(Int32), new Int32Converter()); } diff --git a/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs b/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs index ffe70ee4c..62f6f8503 100644 --- a/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs +++ b/NzbDrone.Core/DataAugmentation/DailySeries/DailySeriesDataProxy.cs @@ -17,14 +17,12 @@ public class DailySeriesDataProxy : IDailySeriesDataProxy { private readonly IHttpProvider _httpProvider; private readonly IConfigService _configService; - private readonly IJsonSerializer _jsonSerializer; private readonly Logger _logger; - public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, IJsonSerializer jsonSerializer, Logger logger) + public DailySeriesDataProxy(IHttpProvider httpProvider, IConfigService configService, Logger logger) { _httpProvider = httpProvider; _configService = configService; - _jsonSerializer = jsonSerializer; _logger = logger; } @@ -34,7 +32,7 @@ public IEnumerable GetDailySeriesIds() { var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds"); - var seriesIds = _jsonSerializer.Deserialize>(dailySeriesIds); + var seriesIds = Json.Deserialize>(dailySeriesIds); return seriesIds; } diff --git a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs index fc5d715bb..c38cb4a58 100644 --- a/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs +++ b/NzbDrone.Core/DataAugmentation/Scene/SceneMappingProxy.cs @@ -14,19 +14,19 @@ public class SceneMappingProxy : ISceneMappingProxy { private readonly IHttpProvider _httpProvider; private readonly IConfigService _configService; - private readonly IJsonSerializer _jsonSerializer; + - public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService, IJsonSerializer jsonSerializer) + public SceneMappingProxy(IHttpProvider httpProvider, IConfigService configService) { _httpProvider = httpProvider; _configService = configService; - _jsonSerializer = jsonSerializer; + } public List Fetch() { var mappingsJson = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/SceneMapping/Active"); - return _jsonSerializer.Deserialize>(mappingsJson); + return Json.Deserialize>(mappingsJson); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs b/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs index 5a49079f1..fa3ce2eee 100644 --- a/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs +++ b/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs @@ -8,12 +8,6 @@ namespace NzbDrone.Core.Datastore.Converters { public class EmbeddedDocumentConverter : IConverter { - private readonly IJsonSerializer _serializer; - - public EmbeddedDocumentConverter(IJsonSerializer serializer) - { - _serializer = serializer; - } public object FromDB(ColumnMap map, object dbValue) { @@ -29,14 +23,14 @@ public object FromDB(ColumnMap map, object dbValue) return null; } - return _serializer.Deserialize(stringValue, map.FieldType); + return Json.Deserialize(stringValue, map.FieldType); } public object ToDB(object clrValue) { if (clrValue == null) return null; - var json = _serializer.Serialize(clrValue); + var json = Json.Serialize(clrValue); return json; } diff --git a/NzbDrone.Core/Datastore/TableMapping.cs b/NzbDrone.Core/Datastore/TableMapping.cs index 239268e01..c8019c0f9 100644 --- a/NzbDrone.Core/Datastore/TableMapping.cs +++ b/NzbDrone.Core/Datastore/TableMapping.cs @@ -91,7 +91,7 @@ private static void RegisterEmbeddedConverter() .Where(c => c.GetInterfaces().Any(i => i == typeof(IEmbeddedDocument))); - var embeddedConvertor = new EmbeddedDocumentConverter(new JsonSerializer()); + var embeddedConvertor = new EmbeddedDocumentConverter(); var genericListDefinition = typeof(List<>).GetGenericTypeDefinition(); foreach (var embeddedType in embeddedTypes) { diff --git a/NzbDrone.Core/Indexers/IndexerWithSetting.cs b/NzbDrone.Core/Indexers/IndexerWithSetting.cs index 21a0aed9f..084a233dc 100644 --- a/NzbDrone.Core/Indexers/IndexerWithSetting.cs +++ b/NzbDrone.Core/Indexers/IndexerWithSetting.cs @@ -9,7 +9,7 @@ namespace NzbDrone.Core.Indexers public TSetting ImportSettingsFromJson(string json) { - Settings = new JsonSerializer().Deserialize(json) ?? new TSetting(); + Settings = Json.Deserialize(json) ?? new TSetting(); return Settings; } diff --git a/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/NzbDrone.Core/Indexers/Newznab/Newznab.cs index d70a26268..805d93c25 100644 --- a/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -8,12 +8,6 @@ namespace NzbDrone.Core.Indexers.Newznab { public class Newznab : IndexerWithSetting { - private readonly IJsonSerializer _jsonSerializer; - - public Newznab() - { - _jsonSerializer = new JsonSerializer(); - } public override IEnumerable DefaultDefinitions @@ -54,7 +48,7 @@ public override IEnumerable DefaultDefinitions private string GetSettings(string url) { - return _jsonSerializer.Serialize(new NewznabSettings { Url = url }); + return Json.Serialize(new NewznabSettings { Url = url }); } public override IEnumerable RecentFeed diff --git a/NzbDrone.Core/Jobs/TaskManager.cs b/NzbDrone.Core/Jobs/TaskManager.cs index 16b06c9ba..71719c4c9 100644 --- a/NzbDrone.Core/Jobs/TaskManager.cs +++ b/NzbDrone.Core/Jobs/TaskManager.cs @@ -5,6 +5,7 @@ using NzbDrone.Common.Messaging; using NzbDrone.Core.Indexers; using NzbDrone.Core.Lifecycle; +using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Providers; namespace NzbDrone.Core.Jobs @@ -36,7 +37,8 @@ public void Handle(ApplicationStartedEvent message) var defaultTasks = new[] { new ScheduledTask{ Interval = 25, TypeName = typeof(RssSyncCommand).FullName}, - new ScheduledTask{ Interval = 24*60, TypeName = typeof(UpdateXemMappings).FullName} + new ScheduledTask{ Interval = 12*60, TypeName = typeof(UpdateXemMappings).FullName}, + new ScheduledTask{ Interval = 6*60, TypeName = typeof(DiskScanCommand).FullName} }; var currentTasks = _scheduledTaskRepository.All(); diff --git a/NzbDrone.Integration.Test/Client/ClientBase.cs b/NzbDrone.Integration.Test/Client/ClientBase.cs index 906178bd7..9f3613b80 100644 --- a/NzbDrone.Integration.Test/Client/ClientBase.cs +++ b/NzbDrone.Integration.Test/Client/ClientBase.cs @@ -15,7 +15,6 @@ namespace NzbDrone.Integration.Test.Client private readonly string _resource; private readonly Logger _logger; - private readonly JsonSerializer _jsonSerializer; public ClientBase(IRestClient restClient, string resource = null) { @@ -27,10 +26,6 @@ public ClientBase(IRestClient restClient, string resource = null) _restClient = restClient; _resource = resource; - _jsonSerializer = new JsonSerializer(); - - - _logger = LogManager.GetLogger("REST"); } @@ -109,7 +104,7 @@ public void Delete(IRestRequest request, HttpStatusCode statusCode = HttpStatusC response.ErrorMessage.Should().BeBlank(); - return _jsonSerializer.Deserialize(response.Content); + return Json.Deserialize(response.Content); } } diff --git a/NzbDrone.Libraries.Test/Json/JsonFixture.cs b/NzbDrone.Libraries.Test/JsonTests/JsonFixture.cs similarity index 58% rename from NzbDrone.Libraries.Test/Json/JsonFixture.cs rename to NzbDrone.Libraries.Test/JsonTests/JsonFixture.cs index 666297861..0b2c83217 100644 --- a/NzbDrone.Libraries.Test/Json/JsonFixture.cs +++ b/NzbDrone.Libraries.Test/JsonTests/JsonFixture.cs @@ -1,12 +1,11 @@ -using NUnit.Framework; -using NzbDrone.Common; +using NUnit.Framework; using NzbDrone.Common.Serializer; using NzbDrone.Test.Common; -namespace NzbDrone.Libraries.Test.Json +namespace NzbDrone.Libraries.Test.JsonTests { [TestFixture] - public class JsonFixture : TestBase + public class JsonFixture : TestBase { public class TypeWithNumbers { @@ -18,9 +17,9 @@ public void should_be_able_to_deserialize_numbers() { var quality = new TypeWithNumbers { Id = 12 }; - var json = Subject.Serialize(quality); + var json = Json.Serialize(quality); - Subject.Deserialize(json); + Json.Deserialize(json); } } } diff --git a/NzbDrone.Libraries.Test/NzbDrone.Libraries.Test.csproj b/NzbDrone.Libraries.Test/NzbDrone.Libraries.Test.csproj index 08acd5be3..ac5063f92 100644 --- a/NzbDrone.Libraries.Test/NzbDrone.Libraries.Test.csproj +++ b/NzbDrone.Libraries.Test/NzbDrone.Libraries.Test.csproj @@ -45,7 +45,7 @@ - + @@ -65,6 +65,9 @@ NzbDrone.Test.Common + + +