mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Fixed: Logging Statements and Tests
This commit is contained in:
parent
f395117885
commit
bd374825f1
@ -33,7 +33,6 @@ public void directory_exist_should_not_be_able_to_find_none_existing_folder()
|
||||
protected abstract void SetWritePermissions(string path, bool writable);
|
||||
|
||||
[Test]
|
||||
[Retry(5)]
|
||||
public void FolderWritable_should_return_true_for_writable_directory()
|
||||
{
|
||||
var tempFolder = GetTempFilePath();
|
||||
@ -45,6 +44,7 @@ public void FolderWritable_should_return_true_for_writable_directory()
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Retry(5)]
|
||||
public void FolderWritable_should_return_false_for_unwritable_directory()
|
||||
{
|
||||
var tempFolder = GetTempFilePath();
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FluentAssertions;
|
||||
using System.Globalization;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
||||
@ -16,5 +17,20 @@ public void should_capitalize_first_character(string input, string expected)
|
||||
{
|
||||
input.FirstCharToUpper().Should().Be(expected);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_capitalize_first_character_regardless_of_culture()
|
||||
{
|
||||
var current = CultureInfo.CurrentCulture;
|
||||
CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("tr-TR");
|
||||
try
|
||||
{
|
||||
"infInite".FirstCharToUpper().Should().Be("InfInite");
|
||||
}
|
||||
finally
|
||||
{
|
||||
CultureInfo.CurrentCulture = current;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
using NUnit.Framework;
|
||||
using FluentAssertions;
|
||||
using NzbDrone.Common.Instrumentation.Sentry;
|
||||
using System;
|
||||
using NLog;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace NzbDrone.Common.Test.InstrumentationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SentryTargetFixture : TestBase
|
||||
{
|
||||
private SentryTarget Subject;
|
||||
|
||||
private static LogLevel[] AllLevels = LogLevel.AllLevels.ToArray();
|
||||
private static LogLevel[] SentryLevels = LogLevel.AllLevels.Where(x => x >= LogLevel.Error).ToArray();
|
||||
private static LogLevel[] OtherLevels = AllLevels.Except(SentryLevels).ToArray();
|
||||
|
||||
private static Exception[] FilteredExceptions = new Exception[] {
|
||||
new UnauthorizedAccessException(),
|
||||
new TinyIoC.TinyIoCResolutionException(typeof(string))
|
||||
};
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
Subject = new SentryTarget("https://aaaaaaaaaaaaaaaaaaaaaaaaaa@sentry.io/111111");
|
||||
}
|
||||
|
||||
private LogEventInfo GivenLogEvent(LogLevel level, Exception ex, string message)
|
||||
{
|
||||
return LogEventInfo.Create(level, "SentryTest", ex, CultureInfo.InvariantCulture, message);
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("AllLevels")]
|
||||
public void log_without_error_is_not_sentry_event(LogLevel level)
|
||||
{
|
||||
Subject.IsSentryMessage(GivenLogEvent(level, null, "test")).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("SentryLevels")]
|
||||
public void error_or_worse_with_exception_is_sentry_event(LogLevel level)
|
||||
{
|
||||
Subject.IsSentryMessage(GivenLogEvent(level, new Exception(), "test")).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("OtherLevels")]
|
||||
public void less_than_error_with_exception_is_not_sentry_event(LogLevel level)
|
||||
{
|
||||
Subject.IsSentryMessage(GivenLogEvent(level, new Exception(), "test")).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("FilteredExceptions")]
|
||||
public void should_filter_event_for_filtered_exception_types(Exception ex)
|
||||
{
|
||||
var log = GivenLogEvent(LogLevel.Error, ex, "test");
|
||||
Subject.IsSentryMessage(log).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource("FilteredExceptions")]
|
||||
public void should_not_filter_event_for_filtered_exception_types_if_filtering_disabled(Exception ex)
|
||||
{
|
||||
Subject.FilterEvents = false;
|
||||
var log = GivenLogEvent(LogLevel.Error, ex, "test");
|
||||
Subject.IsSentryMessage(log).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test, TestCaseSource(typeof(SentryTarget), "FilteredExceptionMessages")]
|
||||
public void should_filter_event_for_filtered_exception_messages(string message)
|
||||
{
|
||||
var log = GivenLogEvent(LogLevel.Error, new Exception("aaaaaaa" + message + "bbbbbbb"), "test");
|
||||
Subject.IsSentryMessage(log).Should().BeFalse();
|
||||
}
|
||||
|
||||
[TestCase("A message that isn't filtered")]
|
||||
[TestCase("Error")]
|
||||
public void should_not_filter_event_for_exception_messages_that_are_not_filtered(string message)
|
||||
{
|
||||
var log = GivenLogEvent(LogLevel.Error, new Exception(message), "test");
|
||||
Subject.IsSentryMessage(log).Should().BeTrue();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
@ -19,23 +20,8 @@ public void DownloadString_should_be_able_to_dowload_text_file()
|
||||
}
|
||||
|
||||
[TestCase("")]
|
||||
public void DownloadString_should_throw_on_empty_string(string url)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => Subject.DownloadString(url));
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
// .net 4.6.2 throws NotSupportedException instead of ArgumentException here
|
||||
[TestCase("http://")]
|
||||
public void DownloadString_should_throw_on_not_supported_string_windows(string url)
|
||||
{
|
||||
WindowsOnly();
|
||||
Assert.Throws<NotSupportedException>(() => Subject.DownloadString(url));
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[TestCase("http://")]
|
||||
public void DownloadString_should_throw_on_not_supported_string_mono(string url)
|
||||
public void DownloadString_should_throw_on_error(string url)
|
||||
{
|
||||
Action action = () => Subject.DownloadString(url);
|
||||
action.Should().Throw<Exception>();
|
||||
|
@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using FluentValidation.Results;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.Notifications;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
using NzbDrone.Core.Movies;
|
||||
using NzbDrone.Core.Validation;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class NotificationBaseFixture : TestBase
|
||||
{
|
||||
class TestSetting : IProviderConfig
|
||||
{
|
||||
public NzbDroneValidationResult Validate()
|
||||
{
|
||||
return new NzbDroneValidationResult();
|
||||
}
|
||||
}
|
||||
|
||||
class TestNotificationWithOnDownload : NotificationBase<TestSetting>
|
||||
{
|
||||
public override string Name => "TestNotification";
|
||||
public override string Link => "";
|
||||
|
||||
|
||||
public override ValidationResult Test()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void OnDownload(DownloadMessage downloadMessage)
|
||||
{
|
||||
TestLogger.Info("OnDownload was called");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestNotificationWithAllEvents : NotificationBase<TestSetting>
|
||||
{
|
||||
public override string Name => "TestNotification";
|
||||
public override string Link => "";
|
||||
|
||||
|
||||
public override ValidationResult Test()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void OnGrab(GrabMessage grabMessage)
|
||||
{
|
||||
TestLogger.Info("OnGrab was called");
|
||||
}
|
||||
|
||||
public override void OnDownload(DownloadMessage message)
|
||||
{
|
||||
TestLogger.Info("OnDownload was called");
|
||||
}
|
||||
|
||||
public override void OnMovieRename(Movie movie)
|
||||
{
|
||||
TestLogger.Info("OnRename was called");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TestNotificationWithNoEvents : NotificationBase<TestSetting>
|
||||
{
|
||||
public override string Name => "TestNotification";
|
||||
public override string Link => "";
|
||||
|
||||
|
||||
public override ValidationResult Test()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_support_OnUpgrade_should_link_to_OnDownload()
|
||||
{
|
||||
var notification = new TestNotificationWithOnDownload();
|
||||
|
||||
notification.SupportsOnDownload.Should().BeTrue();
|
||||
notification.SupportsOnUpgrade.Should().BeTrue();
|
||||
|
||||
notification.SupportsOnGrab.Should().BeFalse();
|
||||
notification.SupportsOnRename.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_support_all_if_implemented()
|
||||
{
|
||||
var notification = new TestNotificationWithAllEvents();
|
||||
|
||||
notification.SupportsOnGrab.Should().BeTrue();
|
||||
notification.SupportsOnDownload.Should().BeTrue();
|
||||
notification.SupportsOnUpgrade.Should().BeTrue();
|
||||
notification.SupportsOnRename.Should().BeTrue();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_support_none_if_none_are_implemented()
|
||||
{
|
||||
var notification = new TestNotificationWithNoEvents();
|
||||
|
||||
notification.SupportsOnGrab.Should().BeFalse();
|
||||
notification.SupportsOnDownload.Should().BeFalse();
|
||||
notification.SupportsOnUpgrade.Should().BeFalse();
|
||||
notification.SupportsOnRename.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
39
src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs
Normal file
39
src/NzbDrone.Core.Test/Qualities/QualityFinderFixture.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Core.CustomFormats;
|
||||
using NzbDrone.Core.Qualities;
|
||||
|
||||
namespace NzbDrone.Core.Test.Qualities
|
||||
{
|
||||
[TestFixture]
|
||||
public class QualityFinderFixture
|
||||
{
|
||||
[TestCase(Source.TV, 480, Modifier.NONE)]
|
||||
[TestCase(Source.UNKNOWN, 480, Modifier.NONE)]
|
||||
public void should_return_SDTV(Source source, Resolution resolution, Modifier modifier)
|
||||
{
|
||||
QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.SDTV);
|
||||
}
|
||||
|
||||
[TestCase(Source.TV, 720, Modifier.NONE)]
|
||||
[TestCase(Source.UNKNOWN, 720, Modifier.NONE)]
|
||||
public void should_return_HDTV_720p(Source source, Resolution resolution, Modifier modifier)
|
||||
{
|
||||
QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.HDTV720p);
|
||||
}
|
||||
|
||||
[TestCase(Source.TV, 1080, Modifier.NONE)]
|
||||
[TestCase(Source.UNKNOWN, 1080, Modifier.NONE)]
|
||||
public void should_return_HDTV_1080p(Source source, Resolution resolution, Modifier modifier)
|
||||
{
|
||||
QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.HDTV1080p);
|
||||
}
|
||||
|
||||
[TestCase(Source.BLURAY, 720, Modifier.NONE)]
|
||||
[TestCase(Source.DVD, 720, Modifier.NONE)]
|
||||
public void should_return_Bluray720p(Source source, Resolution resolution, Modifier modifier)
|
||||
{
|
||||
QualityFinder.FindBySourceAndResolution(source, resolution, modifier).Should().Be(Quality.Bluray720p);
|
||||
}
|
||||
}
|
||||
}
|
@ -54,7 +54,7 @@ public void Clean()
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Error(e, "Couldn't validate image " + image.RelativePath);
|
||||
_logger.Error(e, "Couldn't validate image {0}", image.RelativePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ private void Clean()
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "Error running housekeeping task: " + housekeeper.GetType().Name);
|
||||
_logger.Error(ex, "Error running housekeeping task: {0}", housekeeper.GetType().Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ public LocalMovie Aggregate(LocalMovie localMovie, bool otherFiles)
|
||||
}
|
||||
}
|
||||
|
||||
_logger.Trace("Finding quality. Source: {0}. Resolution: {1}", source, resolution);
|
||||
_logger.Trace("Finding quality. Source: {0}. Resolution: {1}. Modifier {2}", source, resolution, modifier);
|
||||
|
||||
var quality = new QualityModel(QualityFinder.FindBySourceAndResolution(source, resolution, modifier), revison);
|
||||
|
||||
|
@ -44,13 +44,13 @@ private void ExecuteCommands()
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "Error occurred while executing task " + command.Name);
|
||||
_logger.Error(ex, "Error occurred while executing task {0}", command.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ThreadAbortException ex)
|
||||
{
|
||||
_logger.Error(ex, "Thread aborted: " + ex.Message);
|
||||
_logger.Error(ex, "Thread aborted");
|
||||
Thread.ResetAbort();
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
@ -59,7 +59,7 @@ private void ExecuteCommands()
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error(ex, "Unknown error in thread: " + ex.Message);
|
||||
_logger.Error(ex, "Unknown error in thread");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
|
@ -108,7 +108,7 @@ public override bool Equals(object obj)
|
||||
public static Quality BRDISK => new Quality(22, "BR-DISK", Source.BLURAY, 0, Modifier.BRDISK); // new
|
||||
|
||||
// Others
|
||||
public static Quality RAWHD => new Quality(10, "Raw-HD", Source.TV, 0, Modifier.RAWHD);
|
||||
public static Quality RAWHD => new Quality(10, "Raw-HD", Source.TV, 1080, Modifier.RAWHD);
|
||||
|
||||
static Quality()
|
||||
{
|
||||
|
@ -18,7 +18,9 @@ public static Quality FindBySourceAndResolution(Source source, Resolution resolu
|
||||
return matchingQuality;
|
||||
}
|
||||
|
||||
var matchingResolution = Quality.All.Where(q => q.Resolution == resolution)
|
||||
var matchingModifier = Quality.All.Where(q => q.Modifier == modifer);
|
||||
|
||||
var matchingResolution = matchingModifier.Where(q => q.Resolution == resolution)
|
||||
.OrderBy(q => q.Source)
|
||||
.ToList();
|
||||
|
||||
@ -33,7 +35,7 @@ public static Quality FindBySourceAndResolution(Source source, Resolution resolu
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Warn("Unable to find exact quality for {0} and {1}. Using {2} as fallback", source, resolution, nearestQuality);
|
||||
Logger.Warn("Unable to find exact quality for {0}, {1}, and {2}. Using {3} as fallback", source, resolution, modifer, nearestQuality);
|
||||
|
||||
return nearestQuality;
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
namespace NzbDrone.Core.Qualities
|
||||
{
|
||||
public enum QualitySource
|
||||
{
|
||||
Unknown,
|
||||
Television,
|
||||
TelevisionRaw,
|
||||
Web,
|
||||
WebRip,
|
||||
DVD,
|
||||
Bluray
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user