diff --git a/NzbDrone.Core.Test/FluentTest.cs b/NzbDrone.Core.Test/FluentTest.cs new file mode 100644 index 000000000..41df8fd38 --- /dev/null +++ b/NzbDrone.Core.Test/FluentTest.cs @@ -0,0 +1,43 @@ +using System; +using System.IO; +using System.Net; +using System.ServiceModel.Syndication; +using AutoMoq; +using FizzWare.NBuilder; +using FluentAssertions; +using Moq; +using NUnit.Framework; +using NzbDrone.Core.Model; +using NzbDrone.Core.Providers; +using NzbDrone.Core.Providers.Core; +using NzbDrone.Core.Providers.Indexer; +using NzbDrone.Core.Repository; +using NzbDrone.Core.Repository.Quality; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test +{ + [TestFixture] + // ReSharper disable InconsistentNaming + public class FluentTest : TestBase + { + [TestCase(null, "def", "def")] + [TestCase("", "def", "def")] + [TestCase("", 1, "1")] + [TestCase(null, "", "")] + [TestCase("actual", "def", "actual")] + public void WithDefault_success(string actual, object defaultValue, string result) + { + actual.WithDefault(defaultValue).Should().Be(result); + } + + [Test] + [ExpectedException(typeof(ArgumentNullException))] + public void WithDefault_Fail() + { + "test".WithDefault(null); + } + + + } +} diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 2181f8ce7..fd96cd025 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -84,6 +84,7 @@ + diff --git a/NzbDrone.Core/Fluent.cs b/NzbDrone.Core/Fluent.cs new file mode 100644 index 000000000..ed165e77c --- /dev/null +++ b/NzbDrone.Core/Fluent.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace NzbDrone.Core +{ + public static class Fluent + { + public static string WithDefault(this string actual, object defaultValue) + { + if (defaultValue == null) + throw new ArgumentNullException("defaultValue"); + if (String.IsNullOrWhiteSpace(actual)) + { + return defaultValue.ToString(); + } + + return actual; + } + } +} diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index d5188af6d..afcb1b07e 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -165,6 +165,7 @@ + diff --git a/NzbDrone.Core/Providers/EpisodeProvider.cs b/NzbDrone.Core/Providers/EpisodeProvider.cs index 66f2e342c..4be99ddc3 100644 --- a/NzbDrone.Core/Providers/EpisodeProvider.cs +++ b/NzbDrone.Core/Providers/EpisodeProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using Ninject; using NLog; using NzbDrone.Core.Model; @@ -96,7 +97,7 @@ namespace NzbDrone.Core.Providers public virtual void RefreshEpisodeInfo(Series series) { - Logger.Info("Starting episode info refresh for series:{0}", series.SeriesId); + Logger.Info("Starting episode info refresh for series: {0}", series.Title.WithDefault(series.SeriesId)); int successCount = 0; int failCount = 0; var tvDbSeriesInfo = _tvDbProvider.GetSeries(series.SeriesId, true); @@ -151,7 +152,7 @@ namespace NzbDrone.Core.Providers catch (Exception e) { Logger.FatalException( - String.Format("An error has occurred while updating episode info for series {0}", series.SeriesId), e); + String.Format("An error has occurred while updating episode info for series {0}", tvDbSeriesInfo.SeriesName), e); failCount++; } } @@ -169,7 +170,7 @@ namespace NzbDrone.Core.Providers } - Logger.Debug("Finished episode refresh for series:{0}. Successful:{1} - Failed:{2} ", + Logger.Info("Finished episode refresh for series: {0}. Successful: {1} - Failed: {2} ", tvDbSeriesInfo.SeriesName, successCount, failCount); }