From d41f26a4e744a2ba1f618d64b1cf3ff0305ec646 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 7 Apr 2013 10:58:58 -0700 Subject: [PATCH] moved some of the helper classes to their proper location. --- .../ConvertToDayOfWeekFixture.cs | 64 ----------------- .../XElementHelperTests/ConvertToTFixture.cs | 70 ------------------- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 2 - .../SabnzbdPriorityTypeConverter.cs | 6 +- .../SabnzbdQueueTimeConverter.cs | 4 +- .../Download/Clients/Sabnzbd/SabQueueItem.cs | 1 + NzbDrone.Core/Helpers/SortHelper.cs | 1 - NzbDrone.Core/Helpers/XElementHelper.cs | 49 ------------- .../JsonConverter}/EpochDateTimeConverter.cs | 5 +- NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs | 2 +- NzbDrone.Core/NzbDrone.Core.csproj | 7 +- 11 files changed, 10 insertions(+), 201 deletions(-) delete mode 100644 NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToDayOfWeekFixture.cs delete mode 100644 NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToTFixture.cs rename NzbDrone.Core/{Helpers => Download/Clients/Sabnzbd/JsonConverters}/SabnzbdPriorityTypeConverter.cs (87%) rename NzbDrone.Core/{Helpers => Download/Clients/Sabnzbd/JsonConverters}/SabnzbdQueueTimeConverter.cs (93%) delete mode 100644 NzbDrone.Core/Helpers/XElementHelper.cs rename NzbDrone.Core/{Helpers/Converters => Model/Nzbx/JsonConverter}/EpochDateTimeConverter.cs (92%) diff --git a/NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToDayOfWeekFixture.cs b/NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToDayOfWeekFixture.cs deleted file mode 100644 index 734444eeb..000000000 --- a/NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToDayOfWeekFixture.cs +++ /dev/null @@ -1,64 +0,0 @@ - - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Xml.Linq; -using FluentAssertions; -using NUnit.Framework; -using NzbDrone.Common; -using NzbDrone.Core.Helpers; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Test.Framework; -using NzbDrone.Test.Common; - -namespace NzbDrone.Core.Test.HelperTests.XElementHelperTests -{ - [TestFixture] - - public class ParseDayOfWeekFixture : CoreTest - { - [Test] - public void should_return_null_if_xelement_is_null() - { - XElement test = null; - test.ConvertToDayOfWeek().Should().Be(null); - } - - [Test] - public void should_return_null_if_value_is_null() - { - new XElement("airday", null).ConvertToDayOfWeek().Should().Be(null); - } - - [Test] - public void should_return_null_if_value_is_empty() - { - new XElement("airday", "").ConvertToDayOfWeek().Should().Be(null); - } - - [Test] - public void should_return_null_if_value_is_daily() - { - new XElement("airday", "Daily").ConvertToDayOfWeek().Should().Be(null); - } - - [Test] - public void should_return_null_if_value_is_weekdays() - { - new XElement("airday", "Weekdays").ConvertToDayOfWeek().Should().Be(null); - } - - [TestCase("Sunday", DayOfWeek.Sunday)] - [TestCase("Monday", DayOfWeek.Monday)] - [TestCase("Tuesday", DayOfWeek.Tuesday)] - [TestCase("Wednesday", DayOfWeek.Wednesday)] - [TestCase("Thursday", DayOfWeek.Thursday)] - [TestCase("Friday", DayOfWeek.Friday)] - [TestCase("Saturday", DayOfWeek.Saturday)] - public void should_return_dayOfWeek_when_it_is_valid(string value, DayOfWeek expected) - { - new XElement("airday", value).ConvertToDayOfWeek().Should().Be(expected); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToTFixture.cs b/NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToTFixture.cs deleted file mode 100644 index 0a10e0e7a..000000000 --- a/NzbDrone.Core.Test/HelperTests/XElementHelperTests/ConvertToTFixture.cs +++ /dev/null @@ -1,70 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Xml.Linq; -using FizzWare.NBuilder; -using FluentAssertions; -using Moq; -using NUnit.Framework; -using NzbDrone.Core.Helpers; -using NzbDrone.Core.Model.Notification; -using NzbDrone.Core.Providers; - -using NzbDrone.Core.Test.Framework; - -namespace NzbDrone.Core.Test.HelperTests.XElementHelperTests -{ - [TestFixture] - - public class XElementHelperTest : CoreTest - { - [Test] - public void Int32_should_return_zero_when_xelement_is_null() - { - XElement test = null; - - test.ConvertTo().Should().Be(0); - } - - [Test] - public void Int32_should_return_zero_when_value_is_null() - { - new XElement("test", null).ConvertTo().Should().Be(0); - } - - [Test] - public void Int32_should_return_value_when_value_is_an_int() - { - new XElement("test", 10).ConvertTo().Should().Be(10); - } - - [Test] - public void Nullable_Int32_should_return_null_when_xelement_is_null() - { - XElement test = null; - - test.ConvertTo>().Should().Be(null); - } - - [Test] - public void DateTime_should_return_zero_when_xelement_is_null() - { - XElement test = null; - - test.ConvertTo().Should().Be(DateTime.MinValue); - } - - [Test] - public void DateTime_should_return_zero_when_value_is_null() - { - new XElement("test", null).ConvertTo().Should().Be(DateTime.MinValue); - } - - [Test] - public void DateTime_should_return_value_when_value_is_a_date() - { - var date = DateTime.Today; - new XElement("test", date.ToString()).ConvertTo().Should().Be(date); - } - } -} \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 905b4905f..139dd1129 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -133,7 +133,6 @@ - @@ -144,7 +143,6 @@ - diff --git a/NzbDrone.Core/Helpers/SabnzbdPriorityTypeConverter.cs b/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs similarity index 87% rename from NzbDrone.Core/Helpers/SabnzbdPriorityTypeConverter.cs rename to NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs index e5c0b5b0f..e5c5f8b74 100644 --- a/NzbDrone.Core/Helpers/SabnzbdPriorityTypeConverter.cs +++ b/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdPriorityTypeConverter.cs @@ -1,9 +1,7 @@ -using System; -using System.Linq; +using System; using Newtonsoft.Json; -using NzbDrone.Core.Download.Clients.Sabnzbd; -namespace NzbDrone.Core.Helpers +namespace NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters { public class SabnzbdPriorityTypeConverter : JsonConverter { diff --git a/NzbDrone.Core/Helpers/SabnzbdQueueTimeConverter.cs b/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdQueueTimeConverter.cs similarity index 93% rename from NzbDrone.Core/Helpers/SabnzbdQueueTimeConverter.cs rename to NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdQueueTimeConverter.cs index 2a33f374c..42719b28c 100644 --- a/NzbDrone.Core/Helpers/SabnzbdQueueTimeConverter.cs +++ b/NzbDrone.Core/Download/Clients/Sabnzbd/JsonConverters/SabnzbdQueueTimeConverter.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Linq; using Newtonsoft.Json; -namespace NzbDrone.Core.Helpers +namespace NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters { public class SabnzbdQueueTimeConverter : JsonConverter { diff --git a/NzbDrone.Core/Download/Clients/Sabnzbd/SabQueueItem.cs b/NzbDrone.Core/Download/Clients/Sabnzbd/SabQueueItem.cs index 45b7e1914..35a0b4e94 100644 --- a/NzbDrone.Core/Download/Clients/Sabnzbd/SabQueueItem.cs +++ b/NzbDrone.Core/Download/Clients/Sabnzbd/SabQueueItem.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using Newtonsoft.Json; +using NzbDrone.Core.Download.Clients.Sabnzbd.JsonConverters; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; diff --git a/NzbDrone.Core/Helpers/SortHelper.cs b/NzbDrone.Core/Helpers/SortHelper.cs index bc4f5d11a..bd2192a08 100644 --- a/NzbDrone.Core/Helpers/SortHelper.cs +++ b/NzbDrone.Core/Helpers/SortHelper.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; namespace NzbDrone.Core.Helpers { diff --git a/NzbDrone.Core/Helpers/XElementHelper.cs b/NzbDrone.Core/Helpers/XElementHelper.cs deleted file mode 100644 index bc1c093b2..000000000 --- a/NzbDrone.Core/Helpers/XElementHelper.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.ComponentModel; -using System.Linq; -using System.Xml.Linq; - -namespace NzbDrone.Core.Helpers -{ - public static class XElementHelper - { - public static T ConvertTo(this XElement element) - { - if (element == null) - return default(T); - - if (String.IsNullOrEmpty(element.Value)) - return default(T); - - var converter = TypeDescriptor.GetConverter(typeof(T)); - try - { - return (T)converter.ConvertFromString(element.Value); - } - - catch - { - return default(T); - } - } - - public static DayOfWeek? ConvertToDayOfWeek(this XElement element) - { - if (element == null) - return null; - - if (String.IsNullOrWhiteSpace(element.Value)) - return null; - - try - { - return (DayOfWeek)Enum.Parse(typeof(DayOfWeek), element.Value); - } - catch (Exception) - { - } - - return null; - } - } -} diff --git a/NzbDrone.Core/Helpers/Converters/EpochDateTimeConverter.cs b/NzbDrone.Core/Model/Nzbx/JsonConverter/EpochDateTimeConverter.cs similarity index 92% rename from NzbDrone.Core/Helpers/Converters/EpochDateTimeConverter.cs rename to NzbDrone.Core/Model/Nzbx/JsonConverter/EpochDateTimeConverter.cs index 227e20991..a79540a24 100644 --- a/NzbDrone.Core/Helpers/Converters/EpochDateTimeConverter.cs +++ b/NzbDrone.Core/Model/Nzbx/JsonConverter/EpochDateTimeConverter.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using Newtonsoft.Json; using Newtonsoft.Json.Converters; -namespace NzbDrone.Core.Helpers.Converters +namespace NzbDrone.Core.Model.Nzbx.JsonConverter { public class EpochDateTimeConverter : DateTimeConverterBase { diff --git a/NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs b/NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs index f2464f1c5..522a10a56 100644 --- a/NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs +++ b/NzbDrone.Core/Model/Nzbx/NzbxSearchItem.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; -using NzbDrone.Core.Helpers.Converters; +using NzbDrone.Core.Model.Nzbx.JsonConverter; namespace NzbDrone.Core.Model.Nzbx { diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index a867b202c..0861683a8 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -230,6 +230,8 @@ + + @@ -237,11 +239,8 @@ - - + - -