mirror of https://github.com/Sonarr/Sonarr
Added ignore exception type to ExceptionVerfication
This commit is contained in:
parent
c55ca42c21
commit
287cb03517
|
@ -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.MarkForInconclusive(typeof(WebException));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ namespace NzbDrone.Core.Test.Framework
|
|||
public class ExceptionVerification : Target
|
||||
{
|
||||
private static List<LogEventInfo> _logs = new List<LogEventInfo>();
|
||||
private static List<Type> _inconclusive = new List<Type>();
|
||||
|
||||
protected override void Write(LogEventInfo logEvent)
|
||||
{
|
||||
|
@ -23,6 +24,7 @@ namespace NzbDrone.Core.Test.Framework
|
|||
internal static void Reset()
|
||||
{
|
||||
_logs = new List<LogEventInfo>();
|
||||
_inconclusive = new List<Type>();
|
||||
}
|
||||
|
||||
internal static void AssertNoUnexcpectedLogs()
|
||||
|
@ -72,9 +74,16 @@ namespace NzbDrone.Core.Test.Framework
|
|||
Ignore(LogLevel.Error);
|
||||
}
|
||||
|
||||
internal static void MarkForInconclusive(Type exception)
|
||||
{
|
||||
_inconclusive.Add(exception);
|
||||
}
|
||||
|
||||
private static void Excpected(LogLevel level, int count)
|
||||
{
|
||||
var levelLogs = _logs.Where(l => l.Level == level).ToList();
|
||||
var _inconclusiveLogs = _logs.Where(l => _inconclusive.Any(c => c.IsAssignableFrom(l.Exception.GetType()))).ToList();
|
||||
|
||||
var levelLogs = _logs.Except(_inconclusiveLogs).Where(l => l.Level == level).ToList();
|
||||
|
||||
if (levelLogs.Count != count)
|
||||
{
|
||||
|
@ -82,14 +91,18 @@ namespace NzbDrone.Core.Test.Framework
|
|||
var message = String.Format("{0} {1}(s) were expected but {2} were logged.\n\r{3}",
|
||||
count, level, levelLogs.Count, GetLogsString(levelLogs));
|
||||
|
||||
message =
|
||||
"********************************************************************************************************************************\n\r"
|
||||
message = "********************************************************************************************************************************\n\r"
|
||||
+ message +
|
||||
"\n\r********************************************************************************************************************************";
|
||||
|
||||
Assert.Fail(message);
|
||||
}
|
||||
|
||||
if (_inconclusiveLogs.Count != 0)
|
||||
{
|
||||
Assert.Inconclusive(GetLogsString(_inconclusiveLogs));
|
||||
}
|
||||
|
||||
levelLogs.ForEach(c => _logs.Remove(c));
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,7 @@
|
|||
<Compile Include="BacklogSearchJobTest.cs" />
|
||||
<Compile Include="BannerDownloadJobTest.cs" />
|
||||
<Compile Include="ConfigFileProviderTest.cs" />
|
||||
<Compile Include="Framework\AutoMoq\TestBaseTests.cs" />
|
||||
<Compile Include="PostDownloadProviderTest.cs" />
|
||||
<Compile Include="SortHelperTest.cs" />
|
||||
<Compile Include="EpisodeProviderTest_DeleteInvalidEpisodes.cs" />
|
||||
|
|
Loading…
Reference in New Issue