Merge branch 'master' of git://github.com/kayone/NzbDrone

This commit is contained in:
Mark McDowall 2011-06-18 12:14:45 -07:00
commit 7d1f0d2c08
14 changed files with 111 additions and 76 deletions

View File

@ -70,7 +70,7 @@ namespace NzbDrone.Core.Test
.With(e => e.AirDate = DateTime.Now.AddDays(offsetDays))
.With(e => e.Ignored = ignored)
.With(e => e.EpisodeFileId = 0)
.With(e => e.GrabDate = DateTime.Now.AddDays(-1))
.With(e => e.GrabDate = DateTime.Now.AddHours(22))
.Build();
if (hasEpisodes)

View File

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

View File

@ -23,17 +23,6 @@ namespace NzbDrone.Core.Test.Framework
get { return new[] { "c:\\tv\\the simpsons", "c:\\tv\\family guy", "c:\\tv\\southpark", "c:\\tv\\24" }; }
}
public static ConfigProvider StandardConfig
{
get
{
var mock = new Mock<ConfigProvider>();
mock.SetupGet(c => c.SeriesRoot).Returns("C:\\");
return mock.Object;
}
}
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
{
Console.WriteLine("Creating an empty PetaPoco database");
@ -83,14 +72,5 @@ namespace NzbDrone.Core.Test.Framework
.With(c => c.CleanTitle = Parser.NormalizeTitle(title))
.Build();
}
public static IList<Episode> GetFakeEpisodes(int seriesId)
{
var epNumber = new SequentialGenerator<int>();
return Builder<Episode>.CreateListOfSize(10)
.WhereAll().Have(c => c.SeriesId = seriesId)
.WhereAll().Have(c => c.EpisodeNumber = epNumber.Generate())
.Build();
}
}
}

View File

@ -84,6 +84,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="FluentTest.cs" />
<Compile Include="LogProviderTest.cs" />
<Compile Include="UpcomingEpisodesProviderTest.cs" />
<Compile Include="MediaFileProvider_ImportNewDownloadTest.cs" />

View File

@ -1,5 +1,4 @@
// ReSharper disable RedundantUsingDirective
using System;
using System;
using System.Linq;
using AutoMoq;
using FizzWare.NBuilder;
@ -15,11 +14,9 @@ using PetaPoco;
using TvdbLib.Data;
// ReSharper disable InconsistentNaming
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SeriesProviderTest : TestBase
{
[Test]
@ -130,10 +127,12 @@ namespace NzbDrone.Core.Test
var db = MockLib.GetEmptyDatabase();
mocker.SetConstant(db);
var fakeSeries = Builder<Series>.CreateNew().With(c => c.QualityProfileId = 1).Build();
var fakeSeries = Builder<Series>.CreateNew()
.With(c => c.QualityProfileId = 1)
.Build();
var fakeQuality = Builder<QualityProfile>.CreateNew().Build();
var id = db.Insert(fakeSeries);
db.Insert(fakeSeries);
db.Insert(fakeQuality);
//Act
@ -141,9 +140,10 @@ namespace NzbDrone.Core.Test
var series = mocker.Resolve<SeriesProvider>().GetSeries(1);
//Assert
series.ShouldHave().AllPropertiesBut(s => s.QualityProfile, s => s.SeriesId);
series.ShouldHave().AllPropertiesBut(s => s.QualityProfile, s => s.SeriesId).EqualTo(fakeSeries);
series.QualityProfile.Should().NotBeNull();
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.AllowedString);
series.QualityProfile.ShouldHave().Properties(q => q.Name, q => q.SonicAllowed, q => q.Cutoff, q => q.SonicAllowed).EqualTo(fakeQuality);
}
[Test]
@ -239,8 +239,5 @@ namespace NzbDrone.Core.Test
Assert.IsFalse(provider.IsMonitored(11));
Assert.IsFalse(provider.IsMonitored(1));
}
}
}

View File

@ -68,7 +68,8 @@ namespace NzbDrone.Core
_kernel = new StandardKernel();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InRequestScope();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto<IJob>().InSingletonScope();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto<IJob>();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto<JobProvider>();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto<SubsonicTarget>().InSingletonScope();
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto<LogProvider>().InRequestScope();
}
@ -76,10 +77,10 @@ namespace NzbDrone.Core
private static void BindIndexers()
{
_kernel.Bind<IndexerBase>().To<NzbsOrg>().InTransientScope();
_kernel.Bind<IndexerBase>().To<NzbMatrix>().InTransientScope();
_kernel.Bind<IndexerBase>().To<NzbsRUs>().InTransientScope();
_kernel.Bind<IndexerBase>().To<Newzbin>().InTransientScope();
_kernel.Bind<IndexerBase>().To<NzbsOrg>();
_kernel.Bind<IndexerBase>().To<NzbMatrix>();
_kernel.Bind<IndexerBase>().To<NzbsRUs>();
_kernel.Bind<IndexerBase>().To<Newzbin>();
var indexers = _kernel.GetAll<IndexerBase>();
_kernel.Get<IndexerProvider>().InitializeIndexers(indexers.ToList());
@ -87,15 +88,15 @@ namespace NzbDrone.Core
private static void BindJobs()
{
_kernel.Bind<IJob>().To<RssSyncJob>().InTransientScope();
_kernel.Bind<IJob>().To<ImportNewSeriesJob>().InTransientScope();
_kernel.Bind<IJob>().To<UpdateInfoJob>().InTransientScope();
_kernel.Bind<IJob>().To<DiskScanJob>().InTransientScope();
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InTransientScope();
_kernel.Bind<IJob>().To<EpisodeSearchJob>().InTransientScope();
_kernel.Bind<IJob>().To<RenameEpisodeJob>().InTransientScope();
_kernel.Bind<IJob>().To<PostDownloadScanJob>().InTransientScope();
_kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InTransientScope();
_kernel.Bind<IJob>().To<RssSyncJob>().InSingletonScope();
_kernel.Bind<IJob>().To<ImportNewSeriesJob>().InSingletonScope();
_kernel.Bind<IJob>().To<UpdateInfoJob>().InSingletonScope();
_kernel.Bind<IJob>().To<DiskScanJob>().InSingletonScope();
_kernel.Bind<IJob>().To<DeleteSeriesJob>().InSingletonScope();
_kernel.Bind<IJob>().To<EpisodeSearchJob>().InSingletonScope();
_kernel.Bind<IJob>().To<RenameEpisodeJob>().InSingletonScope();
_kernel.Bind<IJob>().To<PostDownloadScanJob>().InSingletonScope();
_kernel.Bind<IJob>().To<UpdateSceneMappingsJob>().InSingletonScope();
_kernel.Get<JobProvider>().Initialize();
_kernel.Get<WebTimer>().StartTimer(30);

View File

@ -47,7 +47,7 @@ namespace NzbDrone.Core.Datastore
DbConnection connection = new SQLiteConnection(connectionString);
if (profiled)
{
//connection = ProfiledDbConnection.Get(connection);
connection = ProfiledDbConnection.Get(connection);
}
var db = new Database(connection);

View File

@ -5,10 +5,10 @@ namespace NzbDrone.Core.Datastore
{
public class CustomeMapper : DefaultMapper
{
public override Func<object, object> GetFromDbConverter(DestinationInfo destinationInfo, Type SourceType)
public override Func<object, object> GetFromDbConverter(DestinationInfo destinationInfo, Type sourceType)
{
if ((SourceType == typeof(Int32) || SourceType == typeof(Int64)) && destinationInfo.Type.IsGenericType && destinationInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
if ((sourceType == typeof(Int32) || sourceType == typeof(Int64)) && destinationInfo.Type.IsGenericType && destinationInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
// If it is NULLABLE, then get the underlying type. eg if "Nullable<int>" then this will return just "int"
Type genericArgument = destinationInfo.Type.GetGenericArguments()[0];
@ -18,31 +18,19 @@ namespace NzbDrone.Core.Datastore
{
int value;
Int32.TryParse(s.ToString(), out value);
if (value == 0)
{
return null;
}
return (Nullable<DayOfWeek>)value;
return (DayOfWeek?)value;
};
}
else
{
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
if (value == 0)
{
return null;
}
return value;
};
}
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
return value;
};
}
return base.GetFromDbConverter(destinationInfo, SourceType);
return base.GetFromDbConverter(destinationInfo, sourceType);
}
}
}

22
NzbDrone.Core/Fluent.cs Normal file
View File

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

View File

@ -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" />

View File

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

View File

@ -7,12 +7,12 @@ namespace NzbDrone.Core.Providers
{
public class NotificationProvider
{
private readonly Dictionary<Guid, BasicNotification> _basicNotifications =
private static readonly Dictionary<Guid, BasicNotification> _basicNotifications =
new Dictionary<Guid, BasicNotification>();
private readonly Object _lock = new object();
private static readonly Object _lock = new object();
private readonly Dictionary<Guid, ProgressNotification> _progressNotification =
private static readonly Dictionary<Guid, ProgressNotification> _progressNotification =
new Dictionary<Guid, ProgressNotification>();
public virtual List<BasicNotification> BasicNotifications

View File

@ -41,7 +41,8 @@ namespace NzbDrone.Web
//base.OnApplicationStarted();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
//RegisterRoutes(RouteTable.Routes);
Logger.Debug("Fully initialized and ready.");
}
protected override IKernel CreateKernel()

Binary file not shown.