mirror of
https://github.com/Sonarr/Sonarr.git
synced 2025-01-10 23:29:53 +02:00
Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus
This commit is contained in:
commit
714bcee5cb
61
NzbDrone.Core.Test/Framework/AutoMoq/TestBaseTests.cs
Normal file
61
NzbDrone.Core.Test/Framework/AutoMoq/TestBaseTests.cs
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using NLog;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Framework.AutoMoq
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
class TestBaseTests : TestBase
|
||||||
|
{
|
||||||
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_should_pass_when_no_exceptions_are_logged()
|
||||||
|
{
|
||||||
|
Logger.Info("Everything is fine and dandy!");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_should_pass_when_errors_are_excpected()
|
||||||
|
{
|
||||||
|
Logger.Error("I knew this would happer");
|
||||||
|
ExceptionVerification.ExcpectedErrors(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_should_pass_when_warns_are_excpected()
|
||||||
|
{
|
||||||
|
Logger.Warn("I knew this would happer");
|
||||||
|
ExceptionVerification.ExcpectedWarns(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_should_pass_when_warns_are_ignored()
|
||||||
|
{
|
||||||
|
Logger.Warn("I knew this would happer");
|
||||||
|
Logger.Warn("I knew this would happer");
|
||||||
|
Logger.Warn("I knew this would happer");
|
||||||
|
ExceptionVerification.IgnoreWarns();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_should_pass_when_errors_are_ignored()
|
||||||
|
{
|
||||||
|
Logger.Error("I knew this would happer");
|
||||||
|
Logger.Error("I knew this would happer");
|
||||||
|
Logger.Error("I knew this would happer");
|
||||||
|
ExceptionVerification.IgnoreErrors();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Test_should_pass_when_exception_type_is_ignored()
|
||||||
|
{
|
||||||
|
Logger.ErrorException("bad exception", new WebException("Test"));
|
||||||
|
ExceptionVerification.MarkInconclusive(typeof(WebException));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -72,8 +72,22 @@ internal static void IgnoreErrors()
|
|||||||
Ignore(LogLevel.Error);
|
Ignore(LogLevel.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void MarkInconclusive(Type exception)
|
||||||
|
{
|
||||||
|
var inconclusiveLogs = _logs.Where(l => l.Exception.GetType() == exception).ToList();
|
||||||
|
|
||||||
|
if (inconclusiveLogs.Count != 0)
|
||||||
|
{
|
||||||
|
inconclusiveLogs.ForEach(c => _logs.Remove(c));
|
||||||
|
Assert.Inconclusive(GetLogsString(inconclusiveLogs));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void Excpected(LogLevel level, int count)
|
private static void Excpected(LogLevel level, int count)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
||||||
|
|
||||||
if (levelLogs.Count != count)
|
if (levelLogs.Count != count)
|
||||||
@ -82,8 +96,7 @@ private static void Excpected(LogLevel level, int count)
|
|||||||
var message = String.Format("{0} {1}(s) were expected but {2} were logged.\n\r{3}",
|
var message = String.Format("{0} {1}(s) were expected but {2} were logged.\n\r{3}",
|
||||||
count, level, levelLogs.Count, GetLogsString(levelLogs));
|
count, level, levelLogs.Count, GetLogsString(levelLogs));
|
||||||
|
|
||||||
message =
|
message = "********************************************************************************************************************************\n\r"
|
||||||
"********************************************************************************************************************************\n\r"
|
|
||||||
+ message +
|
+ message +
|
||||||
"\n\r********************************************************************************************************************************";
|
"\n\r********************************************************************************************************************************";
|
||||||
|
|
||||||
|
@ -21,8 +21,7 @@ public void SetUp()
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
LogManager.Configuration =
|
LogManager.Configuration = new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false);
|
||||||
new XmlLoggingConfiguration(Path.Combine(CentralDispatch.AppPath, "log.config"), false);
|
|
||||||
LogManager.ThrowExceptions = true;
|
LogManager.ThrowExceptions = true;
|
||||||
|
|
||||||
var exceptionVerification = new ExceptionVerification();
|
var exceptionVerification = new ExceptionVerification();
|
||||||
@ -35,7 +34,6 @@ public void SetUp()
|
|||||||
Console.WriteLine("Unable to configure logging. " + e);
|
Console.WriteLine("Unable to configure logging. " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
var filesToDelete = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.sdf", SearchOption.AllDirectories);
|
||||||
foreach (var file in filesToDelete)
|
foreach (var file in filesToDelete)
|
||||||
{
|
{
|
||||||
@ -45,6 +43,8 @@ public void SetUp()
|
|||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MockLib.CreateDataBaseTemplate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,20 +17,19 @@ namespace NzbDrone.Core.Test.Framework
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal static class MockLib
|
internal static class MockLib
|
||||||
{
|
{
|
||||||
public static string[] StandardSeries
|
private const string DbTemplateName = "_dbtemplate.sdf";
|
||||||
{
|
|
||||||
get { return new[] { "c:\\tv\\the simpsons", "c:\\tv\\family guy", "c:\\tv\\southpark", "c:\\tv\\24" }; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
|
public static IDatabase GetEmptyDatabase(bool enableLogging = false, string fileName = "")
|
||||||
{
|
{
|
||||||
Console.WriteLine("Creating an empty PetaPoco database");
|
Console.WriteLine("Cloning database from template.");
|
||||||
|
|
||||||
if (String.IsNullOrWhiteSpace(fileName))
|
if (String.IsNullOrWhiteSpace(fileName))
|
||||||
{
|
{
|
||||||
fileName = Guid.NewGuid() + ".sdf";
|
fileName = Guid.NewGuid() + ".sdf";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File.Copy(DbTemplateName, fileName);
|
||||||
|
|
||||||
var connectionString = Connection.GetConnectionString(fileName);
|
var connectionString = Connection.GetConnectionString(fileName);
|
||||||
|
|
||||||
var database = Connection.GetPetaPocoDb(connectionString);
|
var database = Connection.GetPetaPocoDb(connectionString);
|
||||||
@ -38,7 +37,15 @@ public static IDatabase GetEmptyDatabase(bool enableLogging = false, string file
|
|||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Series GetFakeSeries(int id, string title)
|
public static void CreateDataBaseTemplate()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Creating an empty PetaPoco database");
|
||||||
|
var connectionString = Connection.GetConnectionString(DbTemplateName);
|
||||||
|
var database = Connection.GetPetaPocoDb(connectionString);
|
||||||
|
database.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Series GetFakeSeries(int id, string title)
|
||||||
{
|
{
|
||||||
return Builder<Series>.CreateNew()
|
return Builder<Series>.CreateNew()
|
||||||
.With(c => c.SeriesId = id)
|
.With(c => c.SeriesId = id)
|
||||||
|
@ -66,7 +66,7 @@ public void newzbin_parses_languae()
|
|||||||
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
|
.Setup(h => h.DownloadStream(It.IsAny<String>(), It.IsAny<NetworkCredential>()))
|
||||||
.Returns(File.OpenRead(".\\Files\\Rss\\newbin_none_english.xml"));
|
.Returns(File.OpenRead(".\\Files\\Rss\\newbin_none_english.xml"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var newzbin = mocker.Resolve<Newzbin>();
|
var newzbin = mocker.Resolve<Newzbin>();
|
||||||
var parseResults = newzbin.FetchRss();
|
var parseResults = newzbin.FetchRss();
|
||||||
@ -204,6 +204,8 @@ public void nzbsorg_search_returns_valid_results(string title, int season, int e
|
|||||||
|
|
||||||
var result = mocker.Resolve<NzbsOrg>().FetchEpisode(title, season, episode);
|
var result = mocker.Resolve<NzbsOrg>().FetchEpisode(title, season, episode);
|
||||||
|
|
||||||
|
ExceptionVerification.MarkInconclusive(typeof(WebException));
|
||||||
|
|
||||||
result.Should().NotBeEmpty();
|
result.Should().NotBeEmpty();
|
||||||
result.Should().OnlyContain(r => r.CleanTitle == Parser.NormalizeTitle(title));
|
result.Should().OnlyContain(r => r.CleanTitle == Parser.NormalizeTitle(title));
|
||||||
result.Should().OnlyContain(r => r.SeasonNumber == season);
|
result.Should().OnlyContain(r => r.SeasonNumber == season);
|
||||||
@ -229,6 +231,8 @@ public void newzbin_search_returns_valid_results(string title, int season, int e
|
|||||||
|
|
||||||
var result = mocker.Resolve<Newzbin>().FetchEpisode(title, season, episode);
|
var result = mocker.Resolve<Newzbin>().FetchEpisode(title, season, episode);
|
||||||
|
|
||||||
|
ExceptionVerification.MarkInconclusive(typeof(WebException));
|
||||||
|
|
||||||
result.Should().NotBeEmpty();
|
result.Should().NotBeEmpty();
|
||||||
result.Should().OnlyContain(r => r.CleanTitle == Parser.NormalizeTitle(title));
|
result.Should().OnlyContain(r => r.CleanTitle == Parser.NormalizeTitle(title));
|
||||||
result.Should().OnlyContain(r => r.SeasonNumber == season);
|
result.Should().OnlyContain(r => r.SeasonNumber == season);
|
||||||
@ -252,6 +256,8 @@ public void nzbmatrix_search_returns_valid_results()
|
|||||||
|
|
||||||
var result = mocker.Resolve<NzbMatrix>().FetchEpisode("Simpsons", 21, 23);
|
var result = mocker.Resolve<NzbMatrix>().FetchEpisode("Simpsons", 21, 23);
|
||||||
|
|
||||||
|
ExceptionVerification.MarkInconclusive(typeof(WebException));
|
||||||
|
|
||||||
result.Should().NotBeEmpty();
|
result.Should().NotBeEmpty();
|
||||||
result.Should().OnlyContain(r => r.CleanTitle == "simpsons");
|
result.Should().OnlyContain(r => r.CleanTitle == "simpsons");
|
||||||
result.Should().OnlyContain(r => r.SeasonNumber == 21);
|
result.Should().OnlyContain(r => r.SeasonNumber == 21);
|
||||||
@ -275,11 +281,12 @@ public void nzbsorg_multi_word_search_returns_valid_results()
|
|||||||
|
|
||||||
var result = mocker.Resolve<NzbsOrg>().FetchEpisode("Blue Bloods", 1, 19);
|
var result = mocker.Resolve<NzbsOrg>().FetchEpisode("Blue Bloods", 1, 19);
|
||||||
|
|
||||||
|
ExceptionVerification.MarkInconclusive(typeof(WebException));
|
||||||
|
|
||||||
result.Should().NotBeEmpty();
|
result.Should().NotBeEmpty();
|
||||||
result.Should().OnlyContain(r => r.CleanTitle == "bluebloods");
|
result.Should().OnlyContain(r => r.CleanTitle == "bluebloods");
|
||||||
result.Should().OnlyContain(r => r.SeasonNumber == 1);
|
result.Should().OnlyContain(r => r.SeasonNumber == 1);
|
||||||
result.Should().OnlyContain(r => r.EpisodeNumbers.Contains(19));
|
result.Should().OnlyContain(r => r.EpisodeNumbers.Contains(19));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -299,6 +306,8 @@ public void nzbmatrix_multi_word_search_returns_valid_results()
|
|||||||
|
|
||||||
var result = mocker.Resolve<NzbMatrix>().FetchEpisode("Blue Bloods", 1, 19);
|
var result = mocker.Resolve<NzbMatrix>().FetchEpisode("Blue Bloods", 1, 19);
|
||||||
|
|
||||||
|
ExceptionVerification.MarkInconclusive(typeof(WebException));
|
||||||
|
|
||||||
result.Should().NotBeEmpty();
|
result.Should().NotBeEmpty();
|
||||||
result.Should().OnlyContain(r => r.CleanTitle == "bluebloods");
|
result.Should().OnlyContain(r => r.CleanTitle == "bluebloods");
|
||||||
result.Should().OnlyContain(r => r.SeasonNumber == 1);
|
result.Should().OnlyContain(r => r.SeasonNumber == 1);
|
||||||
|
@ -91,6 +91,7 @@
|
|||||||
<Compile Include="BacklogSearchJobTest.cs" />
|
<Compile Include="BacklogSearchJobTest.cs" />
|
||||||
<Compile Include="BannerDownloadJobTest.cs" />
|
<Compile Include="BannerDownloadJobTest.cs" />
|
||||||
<Compile Include="ConfigFileProviderTest.cs" />
|
<Compile Include="ConfigFileProviderTest.cs" />
|
||||||
|
<Compile Include="Framework\AutoMoq\TestBaseTests.cs" />
|
||||||
<Compile Include="PostDownloadProviderTest.cs" />
|
<Compile Include="PostDownloadProviderTest.cs" />
|
||||||
<Compile Include="SortHelperTest.cs" />
|
<Compile Include="SortHelperTest.cs" />
|
||||||
<Compile Include="EpisodeProviderTest_DeleteInvalidEpisodes.cs" />
|
<Compile Include="EpisodeProviderTest_DeleteInvalidEpisodes.cs" />
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
namespace NzbDrone.Core.Test
|
namespace NzbDrone.Core.Test
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
|
[Category("Benchmark")]
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public class DbBenchmark : TestBase
|
public class DbBenchmark : TestBase
|
||||||
{
|
{
|
||||||
|
@ -20,7 +20,7 @@ public static void Run(string connetionString, bool trace)
|
|||||||
|
|
||||||
EnsureDatabase(connetionString);
|
EnsureDatabase(connetionString);
|
||||||
|
|
||||||
Logger.Info("Preparing to run database migration");
|
Logger.Trace("Preparing to run database migration");
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics;
|
|
||||||
using Exceptioneer.WindowsFormsClient;
|
using Exceptioneer.WindowsFormsClient;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
@ -12,17 +11,18 @@ public class ExceptioneerTarget : Target
|
|||||||
|
|
||||||
protected override void Write(LogEventInfo logEvent)
|
protected override void Write(LogEventInfo logEvent)
|
||||||
{
|
{
|
||||||
if (!Debugger.IsAttached)
|
if (logEvent == null || logEvent.Exception == null) return;
|
||||||
{
|
if (Debugger.IsAttached || Process.GetCurrentProcess().ProcessName.Contains("JetBrains")) return;
|
||||||
Logger.Trace("Sending Exception to Exceptioneer");
|
|
||||||
|
Logger.Trace("Sending Exception to Exceptioneer. {0}", Process.GetCurrentProcess().ProcessName);
|
||||||
|
|
||||||
|
new Client
|
||||||
|
{
|
||||||
|
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
||||||
|
ApplicationName = "NZBDrone",
|
||||||
|
CurrentException = logEvent.Exception
|
||||||
|
}.Submit();
|
||||||
|
|
||||||
new Client
|
|
||||||
{
|
|
||||||
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
|
||||||
ApplicationName = "NZBDrone",
|
|
||||||
CurrentException = logEvent.Exception
|
|
||||||
}.Submit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -23,8 +23,8 @@ public static void Setup()
|
|||||||
|
|
||||||
public static void StartDbLogging()
|
public static void StartDbLogging()
|
||||||
{
|
{
|
||||||
|
#if DEBUG
|
||||||
#if RELEASE
|
#else
|
||||||
var exTarget = new ExceptioneerTarget();
|
var exTarget = new ExceptioneerTarget();
|
||||||
LogManager.Configuration.AddTarget("Exceptioneer", exTarget);
|
LogManager.Configuration.AddTarget("Exceptioneer", exTarget);
|
||||||
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Error, exTarget));
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", NLog.LogLevel.Error, exTarget));
|
||||||
|
@ -1,16 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using NLog;
|
|
||||||
using Ninject;
|
using Ninject;
|
||||||
|
using NzbDrone.Providers;
|
||||||
|
|
||||||
namespace NzbDrone
|
namespace NzbDrone
|
||||||
{
|
{
|
||||||
public static class AppMain
|
public static class AppMain
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private static readonly Logger Logger = LogManager.GetLogger("Host.Main");
|
|
||||||
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -21,8 +17,7 @@ public static void Main(string[] args)
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e.ToString());
|
MonitoringProvider.AppDomainException(e);
|
||||||
Logger.Fatal(e.ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.Remoting;
|
using System.Runtime.Remoting;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
using Exceptioneer.WindowsFormsClient;
|
||||||
using NLog;
|
using NLog;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public MonitoringProvider()
|
|||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e));
|
AppDomain.CurrentDomain.UnhandledException += ((s, e) => AppDomainException(e.ExceptionObject as Exception));
|
||||||
|
|
||||||
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
|
AppDomain.CurrentDomain.ProcessExit += ProgramExited;
|
||||||
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
|
AppDomain.CurrentDomain.DomainUnload += ProgramExited;
|
||||||
@ -42,7 +43,7 @@ public void Start()
|
|||||||
prioCheckTimer.Elapsed += EnsurePriority;
|
prioCheckTimer.Elapsed += EnsurePriority;
|
||||||
prioCheckTimer.Enabled = true;
|
prioCheckTimer.Enabled = true;
|
||||||
|
|
||||||
_pingTimer = new Timer(60000) {AutoReset = true};
|
_pingTimer = new Timer(60000) { AutoReset = true };
|
||||||
_pingTimer.Elapsed += (PingServer);
|
_pingTimer.Elapsed += (PingServer);
|
||||||
_pingTimer.Start();
|
_pingTimer.Start();
|
||||||
}
|
}
|
||||||
@ -101,12 +102,12 @@ private void ProgramExited(object sender, EventArgs e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void AppDomainException(object excepion)
|
public static void AppDomainException(Exception excepion)
|
||||||
{
|
{
|
||||||
Console.WriteLine("EPIC FAIL: {0}", excepion);
|
Console.WriteLine("EPIC FAIL: {0}", excepion);
|
||||||
Logger.Fatal("EPIC FAIL: {0}", excepion);
|
|
||||||
|
|
||||||
#if RELEASE
|
#if DEBUG
|
||||||
|
#else
|
||||||
new Client
|
new Client
|
||||||
{
|
{
|
||||||
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
ApiKey = "43BBF60A-EB2A-4C1C-B09E-422ADF637265",
|
||||||
@ -114,6 +115,8 @@ private static void AppDomainException(object excepion)
|
|||||||
CurrentException = excepion as Exception
|
CurrentException = excepion as Exception
|
||||||
}.Submit();
|
}.Submit();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Logger.Fatal("EPIC FAIL: {0}", excepion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user