Added Fluent.cs to allow string default extention method eg. "Series.Title.WithDefault(series.SeriesId)"

pull/2/head
kay.one 14 years ago
parent ed4976de90
commit b00e437e56

@ -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);
}
}
}

@ -84,6 +84,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FluentTest.cs" />
<Compile Include="LogProviderTest.cs" />
<Compile Include="UpcomingEpisodesProviderTest.cs" />
<Compile Include="MediaFileProvider_ImportNewDownloadTest.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;
}
}
}

@ -165,6 +165,7 @@
<Compile Include="Datastore\CustomeMapper.cs" />
<Compile Include="Datastore\Migrations\Migration.cs" />
<Compile Include="Datastore\SqliteProvider.cs" />
<Compile Include="Fluent.cs" />
<Compile Include="Helpers\EpisodeRenameHelper.cs" />
<Compile Include="Helpers\EpisodeSortingHelper.cs" />
<Compile Include="Helpers\FileSizeFormatHelpercs.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);
}

Loading…
Cancel
Save