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

Conflicts:
	NzbDrone.Web/NzbDrone.Web.csproj
pull/4/head
Mark McDowall 14 years ago
commit 7deea327b8

@ -3,13 +3,14 @@ using MbUnit.Framework;
using Moq;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class DbConfigControllerTest
public class ConfigProviderTest : TestBase
{
[Test]
public void Overwrite_existing_value()

@ -3,6 +3,7 @@ using System.IO;
using MbUnit.Framework;
using NLog;
using NLog.Config;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
@ -50,6 +51,11 @@ namespace NzbDrone.Core.Test
LogManager.Configuration =
new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false);
LogManager.ThrowExceptions = true;
var exceptionVerification = new ExceptionVerification();
LogManager.Configuration.AddTarget("ExceptionVerification", exceptionVerification);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Info, exceptionVerification));
LogManager.Configuration.Reload();
}
catch (Exception e)
{

@ -10,21 +10,21 @@ namespace AutoMoq.Unity
{
internal class AutoMockingBuilderStrategy : BuilderStrategy
{
private readonly IUnityContainer container;
private readonly MockFactory mockFactory;
private readonly IEnumerable<Type> registeredTypes;
private readonly IUnityContainer _container;
private readonly MockRepository _mockFactory;
private readonly IEnumerable<Type> _registeredTypes;
public AutoMockingBuilderStrategy(IEnumerable<Type> registeredTypes, IUnityContainer container)
{
var autoMoqer = container.Resolve<AutoMoqer>();
mockFactory = new MockFactory(autoMoqer.DefaultBehavior);
this.registeredTypes = registeredTypes;
this.container = container;
_mockFactory = new MockRepository(autoMoqer.DefaultBehavior);
_registeredTypes = registeredTypes;
_container = container;
}
public override void PreBuildUp(IBuilderContext context)
{
var autoMoqer = container.Resolve<AutoMoqer>();
var autoMoqer = _container.Resolve<AutoMoqer>();
var type = GetTheTypeFromTheBuilderContext(context);
if (AMockObjectShouldBeCreatedForThisType(type))
@ -39,7 +39,7 @@ namespace AutoMoq.Unity
private bool AMockObjectShouldBeCreatedForThisType(Type type)
{
var mocker = container.Resolve<AutoMoqer>();
var mocker = _container.Resolve<AutoMoqer>();
return TypeIsNotRegistered(type) && (mocker.ResolveType == null || mocker.ResolveType != type);
//return TypeIsNotRegistered(type) && type.IsInterface;
}
@ -51,7 +51,7 @@ namespace AutoMoq.Unity
private bool TypeIsNotRegistered(Type type)
{
return registeredTypes.Any(x => x.Equals(type)) == false;
return _registeredTypes.Any(x => x.Equals(type)) == false;
}
private Mock CreateAMockObject(Type type)
@ -63,12 +63,12 @@ namespace AutoMoq.Unity
private Mock InvokeTheMockCreationMethod(MethodInfo createMethod)
{
return (Mock)createMethod.Invoke(mockFactory, new object[] { new List<object>().ToArray() });
return (Mock)createMethod.Invoke(_mockFactory, new object[] { new List<object>().ToArray() });
}
private MethodInfo GenerateAnInterfaceMockCreationMethod(Type type)
{
var createMethodWithNoParameters = mockFactory.GetType().GetMethod("Create", EmptyArgumentList());
var createMethodWithNoParameters = _mockFactory.GetType().GetMethod("Create", EmptyArgumentList());
return createMethodWithNoParameters.MakeGenericMethod(new[] { type });
}

@ -0,0 +1,87 @@
using System;
using System.Linq;
using System.Collections.Generic;
using NLog;
using NLog.Targets;
using MbUnit.Framework;
namespace NzbDrone.Core.Test.Framework
{
public class ExceptionVerification : Target
{
private static List<LogEventInfo> _logs = new List<LogEventInfo>();
protected override void Write(LogEventInfo logEvent)
{
if (logEvent.Level >= LogLevel.Warn)
{
_logs.Add(logEvent);
}
}
internal static void Reset()
{
_logs = new List<LogEventInfo>();
}
internal static void AssertNoError()
{
if (_logs.Count != 0)
{
string errors = GetLogsString(_logs);
var message = String.Format("{0} unexpected Fatal/Error/Warning were logged during execution.\n\r Use ExceptionVerification.Excpected methods if errors are excepted for this test.{1}{2}",
_logs.Count,
Environment.NewLine,
errors);
Assert.Fail(message);
}
}
private static string GetLogsString(IEnumerable<LogEventInfo> logs)
{
string errors = "";
foreach (var log in logs)
{
string exception = "";
if (log.Exception != null)
{
exception = log.Exception.ToString();
}
errors += Environment.NewLine + String.Format("[{0}] {1}: {2} {3}", log.Level, log.LoggerName, log.FormattedMessage, exception);
}
return errors;
}
internal static void ExcpectedErrors(int count)
{
Excpected(LogLevel.Error, count);
}
internal static void ExcpectedFatals(int count)
{
Excpected(LogLevel.Fatal, count);
}
internal static void ExcpectedWarns(int count)
{
Excpected(LogLevel.Warn, count);
}
private static void Excpected(LogLevel level, int count)
{
var levelLogs = _logs.Where(l => l.Level == level).ToList();
if (levelLogs.Count != count)
{
var message = String.Format("{0} {1}(s) were expected but {2} were logged.\n\r{3}",
count, level, _logs.Count, GetLogsString(levelLogs));
Assert.Fail(message);
}
levelLogs.ForEach(c => _logs.Remove(c));
}
}
}

@ -11,7 +11,7 @@ using NzbDrone.Core.Repository.Quality;
using SubSonic.DataProviders;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
namespace NzbDrone.Core.Test.Framework
{
/// <summary>
/// Provides the standard Mocks needed for a typical test

@ -0,0 +1,21 @@
using MbUnit.Framework;
namespace NzbDrone.Core.Test.Framework
{
public class TestBase
{
[SetUp]
public void Setup()
{
ExceptionVerification.Reset();
}
[TearDown]
public void TearDown()
{
if (!Assert.IsFailurePending) ExceptionVerification.AssertNoError();
}
}
}

@ -7,28 +7,20 @@ using Moq;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
public class HistoryProviderTest
// ReSharper disable InconsistentNaming
public class HistoryProviderTest : TestBase
{
[Test]
public void AllItems()
{
//Setup
var series = new Series
{
SeriesId = 5656,
CleanTitle = "rock",
Monitored = true,
Overview = "Series Overview",
QualityProfileId = 1,
Title = "30 Rock",
Path = @"C:\Test\TV\30 Rock"
};
var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
Season season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
var episode = new Episode
{
AirDate = DateTime.Today.AddDays(-1),
@ -42,15 +34,17 @@ namespace NzbDrone.Core.Test
SeriesId = 5656
};
var list = new List<History>();
list.Add(new History
{
HistoryId = new int(),
Date = DateTime.Now,
IsProper = false,
Quality = QualityTypes.TV,
EpisodeId = episode.EpisodeId
});
var list = new List<History>
{
new History
{
HistoryId = new int(),
Date = DateTime.Now,
IsProper = false,
Quality = QualityTypes.TV,
EpisodeId = episode.EpisodeId
}
};
var repo = new Mock<IRepository>();
repo.Setup(r => r.All<History>()).Returns(list.AsQueryable());
@ -68,6 +62,7 @@ namespace NzbDrone.Core.Test
[Test]
public void add_item()
{
//Arange
var mocker = new AutoMoqer();
var repo = MockLib.GetEmptyRepository();
@ -82,10 +77,22 @@ namespace NzbDrone.Core.Test
{
Date = DateTime.Now,
EpisodeId = episode.EpisodeId,
NzbTitle = "my title"
NzbTitle = "my title",
Indexer = "Fake Indexer"
};
//Act
mocker.Resolve<HistoryProvider>().Add(history);
//Assert
var storedHistory = repo.All<History>();
var newHistiory = repo.All<History>().First();
Assert.Count(1, storedHistory);
Assert.AreEqual(history.Date, newHistiory.Date);
Assert.AreEqual(history.EpisodeId, newHistiory.EpisodeId);
Assert.AreEqual(history.NzbTitle, newHistiory.NzbTitle);
Assert.AreEqual(history.Indexer, newHistiory.Indexer);
}
[Test]
@ -94,16 +101,6 @@ namespace NzbDrone.Core.Test
{
//Todo: This test fails... Moq Setup doesn't return the expected value
//Setup
var series = new Series
{
SeriesId = 5656,
CleanTitle = "rock",
Monitored = true,
Overview = "Series Overview",
QualityProfileId = 1,
Title = "30 Rock",
Path = @"C:\Test\TV\30 Rock"
};
var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
var episode = new Episode
{
@ -118,16 +115,6 @@ namespace NzbDrone.Core.Test
SeriesId = 5656
};
var list = new List<History>();
list.Add(new History
{
HistoryId = new int(),
Date = DateTime.Now,
IsProper = false,
Quality = QualityTypes.TV,
EpisodeId = episode.EpisodeId
});
var proper = false;
var repo = new Mock<IRepository>();
@ -150,17 +137,7 @@ namespace NzbDrone.Core.Test
//Todo: This test fails... Moq Setup doesn't return the expected value
//Setup
var series = new Series
{
SeriesId = 5656,
CleanTitle = "rock",
Monitored = true,
Overview = "Series Overview",
QualityProfileId = 1,
Title = "30 Rock",
Path = @"C:\Test\TV\30 Rock"
};
var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
var season = new Season { SeasonId = 4321, SeasonNumber = 1, SeriesId = 5656, Monitored = true };
var episode = new Episode
{
AirDate = DateTime.Today.AddDays(-1),
@ -174,15 +151,17 @@ namespace NzbDrone.Core.Test
SeriesId = 5656
};
var list = new List<History>();
list.Add(new History
{
HistoryId = new int(),
Date = DateTime.Now,
IsProper = false,
Quality = QualityTypes.TV,
EpisodeId = episode.EpisodeId
});
var list = new List<History>
{
new History
{
HistoryId = new int(),
Date = DateTime.Now,
IsProper = false,
Quality = QualityTypes.TV,
EpisodeId = episode.EpisodeId
}
};
var repo = new Mock<IRepository>();
repo.Setup(r => r.Exists<History>(h => h.Episode == episode && h.IsProper == list[0].IsProper)).Returns(

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO;
using System.Net;
using System.ServiceModel.Syndication;
using System.Xml;
using AutoMoq;
using FizzWare.NBuilder;
using MbUnit.Framework;
@ -14,13 +13,13 @@ using NzbDrone.Core.Providers.ExternalNotification;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using SubSonic.Repository;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
public class IndexerProviderTest
// ReSharper disable InconsistentNaming
public class IndexerProviderTest : TestBase
{
[Test]
[Row("nzbsorg.xml")]
@ -58,7 +57,7 @@ namespace NzbDrone.Core.Test
{
var mocker = new AutoMoqer();
var summary = "My fake summary";
const string summary = "My fake summary";
var fakeSettings = Builder<IndexerSetting>.CreateNew().Build();
mocker.GetMock<IndexerProvider>()
@ -104,6 +103,7 @@ namespace NzbDrone.Core.Test
var result = mocker.Resolve<CustomParserIndexer>().ParseFeed(fakeRssItem);
Assert.IsNull(result);
ExceptionVerification.ExcpectedWarns(1);
}
@ -130,7 +130,7 @@ namespace NzbDrone.Core.Test
//Act
var indexerProvider = mocker.Resolve<IndexerProvider>();
indexerProvider.InitializeIndexers(new List<IndexerProviderBase>() { mocker.Resolve<MockIndexerProvider>() });
indexerProvider.InitializeIndexers(new List<IndexerProviderBase> { mocker.Resolve<MockIndexerProvider>() });
var indexers = indexerProvider.All();
//Assert

@ -5,12 +5,13 @@ using AutoMoq;
using MbUnit.Framework;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class JobProviderTest
public class JobProviderTest : TestBase
{
[Test]
public void Run_Jobs_Updates_Last_Execution()
@ -53,6 +54,7 @@ namespace NzbDrone.Core.Test
Assert.IsNotEmpty(settings);
Assert.AreNotEqual(DateTime.MinValue, settings[0].LastExecution);
Assert.IsFalse(settings[0].Success);
ExceptionVerification.ExcpectedErrors(1);
}
[Test]
@ -76,27 +78,6 @@ namespace NzbDrone.Core.Test
}
[Test]
//This test will confirm that the concurrency checks are rest
//after execution so the job can successfully run.
public void can_run_broken_job_again()
{
IEnumerable<IJob> fakeJobs = new List<IJob> { new BrokenJob() };
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
var firstRun = timerProvider.RunScheduled();
Thread.Sleep(2000);
var secondRun = timerProvider.RunScheduled();
Assert.IsTrue(firstRun);
Assert.IsTrue(secondRun);
}
[Test]
//This test will confirm that the concurrency checks are rest
//after execution so the job can successfully run.
@ -132,12 +113,14 @@ namespace NzbDrone.Core.Test
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
var firstRun = timerProvider.QueueJob(typeof(FakeJob));
var firstRun = timerProvider.QueueJob(typeof(BrokenJob));
Thread.Sleep(2000);
var secondRun = timerProvider.QueueJob(typeof(FakeJob));
var secondRun = timerProvider.QueueJob(typeof(BrokenJob));
Assert.IsTrue(firstRun);
Assert.IsTrue(secondRun);
Thread.Sleep(2000);
ExceptionVerification.ExcpectedErrors(2);
}
[Test]

@ -1,26 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq.Expressions;
using System.Linq;
using AutoMoq;
using FizzWare.NBuilder;
using MbUnit.Framework;
using Moq;
using Moq.Linq;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class MediaFileProviderTests
public class MediaFileProviderTests : TestBase
{
[Test]
[Description("Verifies that a new file imported properly")]
@ -86,7 +85,7 @@ namespace NzbDrone.Core.Test
//Constants
const string fileName = @"2011.01.10 - Denis Leary - HD TV.mkv";
DateTime airDate = new DateTime(2011, 01, 10);
var airDate = new DateTime(2011, 01, 10);
const int size = 12345;
//Fakes
var fakeSeries = Builder<Series>.CreateNew().Build();
@ -144,9 +143,6 @@ namespace NzbDrone.Core.Test
//Fakes
var fakeSeries = Builder<Series>.CreateNew().Build();
var fakeEpisode = Builder<Episode>.CreateNew()
.With(c => c.SeriesId = fakeSeries.SeriesId)
.With(c => c.EpisodeFileId = 12).Build();
//Mocks
var mocker = new AutoMoqer();
@ -179,7 +175,7 @@ namespace NzbDrone.Core.Test
//Constants
const string fileName = @"2011.01.10 - Denis Leary - sample - HD TV.mkv";
DateTime airDate = new DateTime(2011, 01, 10);
var airDate = new DateTime(2011, 01, 10);
const int size = 12345;
//Fakes
var fakeSeries = Builder<Series>.CreateNew().Build();
@ -275,6 +271,7 @@ namespace NzbDrone.Core.Test
mocker.VerifyAllMocks();
Assert.IsNull(result);
mocker.GetMock<IRepository>().Verify(r => r.Add(result), Times.Never());
ExceptionVerification.ExcpectedWarns(1);
}
[Test]

@ -1,36 +0,0 @@
using System;
using Ninject.Infrastructure;
using Ninject.Injection;
using Ninject.Planning.Bindings;
using Ninject.Syntax;
namespace Ninject.Moq
{
/// <summary>
/// Extensions for the fluent binding syntax API.
/// </summary>
public static class ExtensionsForBindingSyntax
{
/// <summary>
/// Indicates that the service should be bound to a mocked instance of the specified type.
/// </summary>
/// <typeparam name = "T">The service that is being mocked.</typeparam>
/// <param name = "builder">The builder that is building the binding.</param>
public static IBindingWhenInNamedWithOrOnSyntax<T> ToMock<T>(this IBindingToSyntax<T> builder)
{
var haveBinding = builder as IHaveBinding;
if (haveBinding == null)
throw new NotSupportedException(
String.Format(
"The binding builder for {0} is of type {1}, which does not implement IHaveBinding and is therefore not extensible.",
typeof (T), builder.GetType()));
IBinding binding = haveBinding.Binding;
binding.ProviderCallback = ctx => new MockProvider(ctx.Kernel.Components.Get<IInjectorFactory>());
return builder as IBindingWhenInNamedWithOrOnSyntax<T>;
}
}
}

@ -1,80 +0,0 @@
using System;
using System.Collections.Generic;
using Moq;
using Ninject.Activation;
using Ninject.Injection;
namespace Ninject.Moq
{
/// <summary>
/// Creates mocked instances via Moq.
/// </summary>
public class MockProvider : IProvider
{
private static readonly Dictionary<Type, ConstructorInjector> _injectors =
new Dictionary<Type, ConstructorInjector>();
/// <summary>
/// Initializes a new instance of the <see cref = "MockProvider" /> class.
/// </summary>
/// <param name = "injectorFactory">The injector factory component.</param>
public MockProvider(IInjectorFactory injectorFactory)
{
InjectorFactory = injectorFactory;
}
/// <summary>
/// Gets the injector factory component.
/// </summary>
public IInjectorFactory InjectorFactory { get; private set; }
#region IProvider Members
/// <summary>
/// Gets the type (or prototype) of instances the provider creates.
/// </summary>
public Type Type
{
get { return typeof (Mock<>); }
}
/// <summary>
/// Creates an instance within the specified context.
/// </summary>
/// <param name = "context">The context.</param>
/// <returns>The created instance.</returns>
public object Create(IContext context)
{
ConstructorInjector injector = GetInjector(context.Request.Service);
var mock = injector.Invoke() as Mock;
return mock.Object;
}
#endregion
private ConstructorInjector GetInjector(Type service)
{
lock (_injectors)
{
Type mockType = typeof (Mock<>).MakeGenericType(service);
if (_injectors.ContainsKey(mockType))
return _injectors[mockType];
ConstructorInjector injector = InjectorFactory.Create(mockType.GetConstructor(Type.EmptyTypes));
_injectors[mockType] = injector;
return injector;
}
}
/// <summary>
/// Gets a callback that creates an instance of the <see cref = "MockProvider" />.
/// </summary>
/// <returns>The created callback.</returns>
public static Func<IContext, IProvider> GetCreationCallback()
{
return ctx => new MockProvider(ctx.Kernel.Components.Get<IInjectorFactory>());
}
}
}

@ -1,41 +0,0 @@
using System;
using Ninject.Activation.Caching;
using Ninject.Planning.Bindings;
namespace Ninject.Moq
{
/// <summary>
/// A kernel that will create mocked instances (via Moq) for any service that is
/// requested for which no binding is registered.
/// </summary>
public class MockingKernel : StandardKernel
{
/// <summary>
/// Clears the kernel's cache, immediately deactivating all activated instances regardless of scope.
/// This does not remove any modules, extensions, or bindings.
/// </summary>
public void Reset()
{
Components.Get<ICache>().Clear();
}
/// <summary>
/// Attempts to handle a missing binding for a service.
/// </summary>
/// <param name = "service">The service.</param>
/// <returns><c>True</c> if the missing binding can be handled; otherwise <c>false</c>.</returns>
protected override bool HandleMissingBinding(Type service)
{
var binding = new Binding(service)
{
ProviderCallback = MockProvider.GetCreationCallback(),
ScopeCallback = ctx => null,
IsImplicit = true
};
AddBinding(binding);
return true;
}
}
}

@ -85,34 +85,33 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AutoMoq\AutoMoqer.cs" />
<Compile Include="AutoMoq\AutoMoqerTest.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs">
<Compile Include="Framework\AutoMoq\AutoMoqer.cs" />
<Compile Include="Framework\AutoMoq\AutoMoqerTest.cs" />
<Compile Include="Framework\AutoMoq\Unity\AutoMockingBuilderStrategy.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs">
<Compile Include="Framework\AutoMoq\Unity\AutoMockingContainerExtension.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Framework\ExceptionVerification.cs" />
<Compile Include="Framework\TestBase.cs" />
<Compile Include="JobProviderTest.cs" />
<Compile Include="SyncProviderTest.cs" />
<Compile Include="RootDirProviderTest.cs" />
<Compile Include="IndexerProviderTest.cs" />
<Compile Include="HistoryProviderTest.cs" />
<Compile Include="MediaFileProviderTests.cs" />
<Compile Include="DbConfigControllerTest.cs" />
<Compile Include="ConfigProviderTest.cs" />
<Compile Include="EpisodeProviderTest.cs" />
<Compile Include="Fixtures.cs" />
<Compile Include="MockLib.cs" />
<Compile Include="Ninject.Moq\ExtensionsForBindingSyntax.cs" />
<Compile Include="Ninject.Moq\MockingKernel.cs" />
<Compile Include="Ninject.Moq\MockProvider.cs" />
<Compile Include="Framework\MockLib.cs" />
<Compile Include="ParserTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="QualityProfileTest.cs" />
<Compile Include="RepoTest.cs" />
<Compile Include="SabControllerTest.cs" />
<Compile Include="SabProviderTest.cs" />
<Compile Include="SeriesProviderTest.cs" />
<Compile Include="TvDbControllerTest.cs" />
<Compile Include="TvDbProviderTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\NzbDrone.Core\NzbDrone.Core.csproj">
@ -121,7 +120,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="AutoMoq\License.txt" />
<Content Include="Framework\AutoMoq\License.txt" />
<Content Include="Files\Feed.nzbmatrix.com.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

@ -1,13 +1,13 @@
using System;
using System.Threading;
using MbUnit.Framework;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class ParserTest
public class ParserTest : TestBase
{
/*Fucked-up hall of shame,
* WWE.Wrestlemania.27.PPV.HDTV.XviD-KYR
@ -15,6 +15,10 @@ namespace NzbDrone.Core.Test
* Unreported.World.Chinas.Lost.Sons.WS.PDTV.XviD-FTP
*/
[Test]
[Row("Sonny.With.a.Chance.S02E15", "Sonny.With.a.Chance", 2, 15)]
[Row("Two.and.a.Half.Me.103.720p.HDTV.X264-DIMENSION", "Two.and.a.Half.Me", 1, 3)]

@ -5,12 +5,13 @@ using FizzWare.NBuilder;
using MbUnit.Framework;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class QualityProfileTest
public class QualityProfileTest : TestBase
{
///<summary>
/// Test_s the storage.
@ -24,11 +25,11 @@ namespace NzbDrone.Core.Test
{
Name = Guid.NewGuid().ToString(),
Cutoff = QualityTypes.TV,
Allowed = new List<QualityTypes> {QualityTypes.HDTV, QualityTypes.DVD},
Allowed = new List<QualityTypes> { QualityTypes.HDTV, QualityTypes.DVD },
};
//Act
var id = (int) repo.Add(testProfile);
var id = (int)repo.Add(testProfile);
var fetch = repo.Single<QualityProfile>(c => c.QualityProfileId == id);
//Assert
@ -48,20 +49,16 @@ namespace NzbDrone.Core.Test
{
Name = Guid.NewGuid().ToString(),
Cutoff = QualityTypes.TV,
Allowed = new List<QualityTypes> {QualityTypes.HDTV, QualityTypes.DVD},
Allowed = new List<QualityTypes> { QualityTypes.HDTV, QualityTypes.DVD },
};
var profileId = (int) repo.Add(testProfile);
var profileId = (int)repo.Add(testProfile);
var series = Builder<Series>.CreateNew().Build();
series.QualityProfileId = profileId;
var seriesID = (int) repo.Add(series);
var result = repo.All<Series>();
var quality = repo.All<QualityProfile>();
Assert.Count(1, result);
Assert.AreEqual(result.ToList()[0].QualityProfile.Name, testProfile.Name);

@ -6,13 +6,14 @@ using NLog;
using NLog.Config;
using NzbDrone.Core.Instrumentation;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using LogLevel = NLog.LogLevel;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class RepoTest
public class RepoTest : TestBase
{
[Test]
public void to_many__series_to_episode()
@ -93,6 +94,8 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(Logger.Name, logItem.Logger);
Assert.AreEqual(LogLevel.Info.Name, logItem.Level);
Assert.AreEqual("write_log", logItem.Method);
}
[Test]
@ -126,6 +129,7 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(LogLevel.Error.Name, logItem.Level);
Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType);
Assert.AreEqual(ex.ToString(), logItem.Exception);
ExceptionVerification.ExcpectedErrors(1);
}
[Test]
@ -159,6 +163,7 @@ namespace NzbDrone.Core.Test
Assert.AreEqual(LogLevel.Error.Name, logItem.Level);
Assert.AreEqual(ex.GetType().ToString(), logItem.ExceptionType);
Assert.AreEqual(ex.ToString(), logItem.Exception);
ExceptionVerification.ExcpectedErrors(1);
}
}
}

@ -3,13 +3,17 @@ using AutoMoq;
using MbUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using SubSonic.Repository;
namespace NzbDrone.Core.Test
{
[TestFixture]
public class RootDirProviderTest
// ReSharper disable InconsistentNaming
public class RootDirProviderTest : TestBase
{
[Test]
public void GetRootDirs()
{
@ -38,7 +42,7 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
string path = @"C:\TV\";
const string path = @"C:\TV\";
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();
@ -59,7 +63,7 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
string path = @"C:\TV2";
const string path = @"C:\TV2";
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();
@ -80,8 +84,6 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
string path = @"C:\TV2";
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();
rootDirProvider.Add(new RootDir {Path = @"C:\TV"});
@ -99,8 +101,8 @@ namespace NzbDrone.Core.Test
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
int id = 1;
string path = @"C:\TV";
const int id = 1;
const string path = @"C:\TV";
//Act
var rootDirProvider = mocker.Resolve<RootDirProvider>();

@ -7,26 +7,26 @@ using Moq;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SabControllerTest
public class SabProviderTest : TestBase
{
[Test]
public void AddByUrlSuccess()
{
//Setup
string sabHost = "192.168.5.55";
int sabPort = 2222;
string apikey = "5c770e3197e4fe763423ee7c392c25d1";
string username = "admin";
string password = "pass";
var priority = SabnzbdPriorityType.Normal;
string category = "tv";
const string sabHost = "192.168.5.55";
const int sabPort = 2222;
const string apikey = "5c770e3197e4fe763423ee7c392c25d1";
const string username = "admin";
const string password = "pass";
const SabnzbdPriorityType priority = SabnzbdPriorityType.Normal;
const string category = "tv";
var mocker = new AutoMoqer();
@ -101,6 +101,7 @@ namespace NzbDrone.Core.Test
//Assert
Assert.IsFalse(result);
ExceptionVerification.ExcpectedWarns(1);
}
[Test]

@ -4,17 +4,18 @@ using MbUnit.Framework;
using Moq;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class SyncProviderTest
public class SyncProviderTest : TestBase
{
[Test]
public void None_existing_folder_returns_empty_list()
{
string path = "d:\\bad folder";
const string path = "d:\\bad folder";
var mocker = new AutoMoqer();
mocker.GetMock<DiskProvider>(MockBehavior.Strict)

@ -1,12 +1,13 @@
using System;
using MbUnit.Framework;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
public class TvDbControllerTest
public class TvDbProviderTest : TestBase
{
[Test]
[Row("The Simpsons")]

@ -1,6 +1,6 @@
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true">
<targets>
<target name="consoleTarget" xsi:type="ColoredConsole" layout="${logger}: ${message} ${exception:ToString}" />
<target name="consoleTarget" xsi:type="ColoredConsole" layout="[${level}] ${logger}: ${message} ${exception:ToString}" />
<target name="udpTarget" xsi:type="Chainsaw" address="udp://127.0.0.1:20480"
includeCallSite="true" includeSourceInfo="true" includeNLogData="true" includeNDC="true" includeMDC="true">
<parameter name="exception" layout="${exception:format=ToString}" xsi:type="NLogViewerParameterInfo" />

@ -27,10 +27,10 @@ namespace NzbDrone.Core.Model
public override string ToString()
{
if (Episodes == null)
return string.Format("Series:{0} Air Date:{1}", CleanTitle, AirDate.Date);
return string.Format("{0} - {1}", CleanTitle, AirDate.Date);
return string.Format("Series:{0} Season:{1} Episode:{2}", CleanTitle, SeasonNumber,
String.Join(",", Episodes));
return string.Format("{0} - S{1:00}E{2}", CleanTitle, SeasonNumber,
String.Join("-", Episodes));
}
}

@ -184,7 +184,7 @@ namespace NzbDrone.Core.Providers.Indexer
IsProper = parseResult.Proper,
NzbTitle = feedItem.Title.Text,
Quality = parseResult.Quality,
Indexer = GetIndexerType()
Indexer = Name
});
}
@ -247,15 +247,6 @@ namespace NzbDrone.Core.Providers.Indexer
/// <returns>Download link URL</returns>
protected abstract string NzbDownloadUrl(SyndicationItem item);
/// <summary>
/// Gets he IndexerType Enum for this indexer
/// </summary>
/// <returns>IndexerType Enum</returns>
protected virtual IndexerType GetIndexerType()
{
return IndexerType.Unknown;
}
private bool InHistory(IList<Episode> episodes, EpisodeParseResult parseResult, SyndicationItem feedItem)
{
foreach (var episode in episodes)

@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Net;
using System.ServiceModel.Syndication;
using System.Web;
using NzbDrone.Core.Model;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.ExternalNotification;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers.Indexer
{
@ -50,7 +47,7 @@ namespace NzbDrone.Core.Providers.Indexer
protected override string NzbDownloadUrl(SyndicationItem item)
{
return item.Id;
return item.Id + "/nzb";
}
protected override EpisodeParseResult CustomParser(SyndicationItem item, EpisodeParseResult currentResult)
@ -64,9 +61,5 @@ namespace NzbDrone.Core.Providers.Indexer
return currentResult;
}
protected override IndexerType GetIndexerType()
{
return IndexerType.Newzbin;
}
}
}

@ -50,9 +50,5 @@ namespace NzbDrone.Core.Providers.Indexer
return item.Links[0].Uri.ToString();
}
protected override IndexerType GetIndexerType()
{
return IndexerType.NzbMatrix;
}
}
}

@ -46,9 +46,5 @@ namespace NzbDrone.Core.Providers.Indexer
return item.Id;
}
protected override IndexerType GetIndexerType()
{
return IndexerType.NzbsOrg;
}
}
}
}

@ -49,9 +49,5 @@ namespace NzbDrone.Core.Providers.Indexer
return item.Links[0].Uri.ToString();
}
protected override IndexerType GetIndexerType()
{
return IndexerType.NzbsRus;
}
}
}

@ -130,7 +130,7 @@ namespace NzbDrone.Core.Providers.Jobs
{
if (_isRunning)
{
Logger.Trace("Queue is already running. Ignoreing request.");
Logger.Trace("Queue is already running. Ignoring request.");
return true;
}
@ -189,7 +189,7 @@ namespace NzbDrone.Core.Providers.Jobs
}
catch (Exception e)
{
Logger.FatalException("An error has occured while processing queued job.", e);
Logger.FatalException("An error has occurred while processing queued job.", e);
}
finally
{

@ -72,6 +72,7 @@ namespace NzbDrone.Core.Providers
if (!_repository.Exists<EpisodeFile>(e => e.Path == Parser.NormalizePath(filePath)))
{
var parseResult = Parser.ParseEpisodeInfo(filePath);
parseResult.CleanTitle = series.Title;//replaces the nasty path as title to help with logging
if (parseResult == null)
return null;
@ -90,7 +91,7 @@ namespace NzbDrone.Core.Providers
}
else
{
Logger.Warn("Unable to find '{0}' in the database. File:{1}", parseResult, filePath);
Logger.Warn("Unable to find [{0}] in the database.[{1}]", parseResult, filePath);
}
}
else
@ -106,7 +107,7 @@ namespace NzbDrone.Core.Providers
}
else
{
Logger.Warn("Unable to find '{0}' in the database. File:{1}", parseResult, filePath);
Logger.Warn("Unable to find [{0}] in the database.[{1}]", parseResult, filePath);
}
}
}

@ -15,7 +15,7 @@ namespace NzbDrone.Core.Repository
public QualityTypes Quality { get; set; }
public DateTime Date { get; set; }
public bool IsProper { get; set; }
public IndexerType? Indexer { get; set; }
public string Indexer { get; set; }
[SubSonicToOneRelation(ThisClassContainsJoinKey = true)]
public virtual Episode Episode { get; protected set; }

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace NzbDrone.Web.Controllers
{
public class HealthController : Controller
{
//
// GET: /Health/
[HttpGet]
public JsonResult Index()
{
return Json("OK", JsonRequestBehavior.AllowGet);
}
}
}

@ -43,7 +43,7 @@ namespace NzbDrone.Web.Controllers
//TODO: possible subsonic bug, IQuarible causes some issues so ToList() is called
//https://github.com/subsonic/SubSonic-3.0/issues/263
var history = _historyProvider.AllItems().ToList().Select(h => new HistoryModel
{
HistoryId = h.HistoryId,
@ -56,7 +56,7 @@ namespace NzbDrone.Web.Controllers
Quality = h.Quality.ToString(),
IsProper = h.IsProper,
Date = h.Date,
Indexer = String.IsNullOrEmpty(h.Indexer.ToString()) ? "Unknown" : h.Indexer.ToString()
Indexer = h.Indexer
});
return View(new GridModel(history));

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Providers.Jobs;

@ -214,6 +214,7 @@
<DesignTime>True</DesignTime>
<DependentUpon>UploadLocalization.en-US.resx</DependentUpon>
</Compile>
<Compile Include="Controllers\HealthController.cs" />
<Compile Include="Controllers\HistoryController.cs" />
<Compile Include="Controllers\LogController.cs" />
<Compile Include="Controllers\AddSeriesController.cs" />
@ -572,12 +573,21 @@
<Content Include="Content\Images\img02.jpg" />
<Content Include="Content\Images\img03.jpg" />
<Content Include="Content\Images\img07.jpg" />
<Content Include="Content\Images\Indexers\Newzbin.png" />
<Content Include="Content\Images\Indexers\NzbMatrix.png" />
<Content Include="Content\Images\Indexers\NzbsOrg.png" />
<Content Include="Content\Images\Indexers\NzbsRus.png" />
<Content Include="Content\Images\Indexers\Unknown.png" />
<Content Include="Content\Images\Loading.gif" />
<Content Include="Content\Images\Indexers\Newzbin.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Images\Indexers\NzbMatrix.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Images\Indexers\NzbsOrg.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Images\Indexers\NzbsRus.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Images\Indexers\Unknown.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Content\Images\Plus.png" />
<Content Include="Content\Images\spin.gif" />
<Content Include="Content\Images\ui-bg_diagonals-small_0_aaaaaa_40x40.png" />

@ -1,5 +1,6 @@
/// <reference path="jquery-1.5.2-vsdoc.js" />
$(function () {
$(document).ready(function ()
{
var speed = 0;
var isShown = false;
refreshNotifications();

@ -68,7 +68,7 @@
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<glimpse on="true" saveRequestCount="5">
<glimpse on="false" saveRequestCount="5">
<ipAddresses>
<add address="0.0.0.0" />
<!--IPv4-->

@ -3,6 +3,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Remoting;
using System.Timers;
using System.Xml.Linq;
using System.Xml.XPath;
@ -70,8 +71,8 @@ namespace NzbDrone
IISProcess.BeginOutputReadLine();
//Start Ping
_pingTimer = new Timer(10000) { AutoReset = true };
_pingTimer.Elapsed += (Server);
_pingTimer = new Timer(30000) { AutoReset = true };
_pingTimer.Elapsed += (PingServer);
_pingTimer.Start();
return IISProcess;
@ -114,11 +115,16 @@ namespace NzbDrone
StartServer();
}
private static void Server(object sender, ElapsedEventArgs e)
private static void PingServer(object sender, ElapsedEventArgs e)
{
try
{
new WebClient().DownloadString(AppUrl);
var response = new WebClient().DownloadString(AppUrl + "/health");
if (!response.Contains("OK"))
{
throw new ServerException("Health services responded with an invalid response.");
}
if (_pingFailCounter > 0)
{
Logger.Info("Application pool has been successfully recovered.");

Loading…
Cancel
Save