refactor: convert to file-scoped namespaces

pull/47/head
Robert Dailey 2 years ago
parent e67b4296b3
commit 593740900a

@ -3,12 +3,12 @@ using Common.Extensions;
using FluentAssertions;
using NUnit.Framework;
namespace Common.Tests.Extensions
namespace Common.Tests.Extensions;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class DictionaryExtensionsTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class DictionaryExtensionsTest
{
private class MySampleValue
{
}
@ -59,5 +59,4 @@ namespace Common.Tests.Extensions
dict.Should().HaveCount(1).And.Contain(100, sample);
theValue.Should().Be(sample);
}
}
}

@ -2,12 +2,12 @@
using FluentAssertions;
using NUnit.Framework;
namespace Common.Tests
namespace Common.Tests;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ResourceDataReaderTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ResourceDataReaderTest
{
[Test]
public void GetResourceData_DefaultDir_ReturnResourceData()
{
@ -34,5 +34,4 @@ namespace Common.Tests
var data = testData.ReadData("DataFile.txt");
data.Trim().Should().Be("DataFile");
}
}
}

@ -2,10 +2,10 @@ using System;
using System.Collections;
using System.Collections.Generic;
namespace Common.Extensions
namespace Common.Extensions;
public static class CollectionExtensions
{
public static class CollectionExtensions
{
// From: https://stackoverflow.com/a/34362585/157971
public static IReadOnlyCollection<T> AsReadOnly<T>(this ICollection<T> source)
{
@ -34,5 +34,4 @@ namespace Common.Extensions
destination.Add(item);
}
}
}
}

@ -1,9 +1,9 @@
using System.Collections.Generic;
namespace Common.Extensions
namespace Common.Extensions;
public static class DictionaryExtensions
{
public static class DictionaryExtensions
{
public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
where TValue : new()
{
@ -20,5 +20,4 @@ namespace Common.Extensions
{
return dict.TryGetValue(key, out var val) ? val : default;
}
}
}

@ -4,10 +4,10 @@ using System.Threading.Tasks;
using FluentValidation;
using FluentValidation.Validators;
namespace Common.Extensions
namespace Common.Extensions;
public static class FluentValidationExtensions
{
public static class FluentValidationExtensions
{
// From: https://github.com/FluentValidation/FluentValidation/issues/1648
public static IRuleBuilderOptions<T, TProperty?> SetNonNullableValidator<T, TProperty>(
this IRuleBuilder<T, TProperty?> ruleBuilder, IValidator<TProperty> validator, params string[] ruleSets)
@ -39,5 +39,4 @@ namespace Common.Extensions
return base.IsValid(context, value!);
}
}
}
}

@ -1,10 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
namespace Common.Extensions
namespace Common.Extensions;
public static class RegexExtensions
{
public static class RegexExtensions
{
[SuppressMessage("Design", "CA1021:Avoid out parameters",
Justification =
"The out param has a very specific design purpose. It's to allow regex match expressions " +
@ -14,5 +14,4 @@ namespace Common.Extensions
match = re.Match(strToCheck);
return match.Success;
}
}
}

@ -3,10 +3,10 @@ using System.Reactive.Disposables;
using System.Reactive.Linq;
using Serilog;
namespace Common.Extensions
namespace Common.Extensions;
public static class RxExtensions
{
public static class RxExtensions
{
public static IObservable<T> Spy<T>(this IObservable<T> source, ILogger log, string? opName = null)
{
opName ??= "IObservable";
@ -44,5 +44,4 @@ namespace Common.Extensions
}
});
}
}
}

@ -1,10 +1,10 @@
using System;
using System.Globalization;
namespace Common.Extensions
namespace Common.Extensions;
public static class StringExtensions
{
public static class StringExtensions
{
public static bool ContainsIgnoreCase(this string value, string searchFor)
{
return value.Contains(searchFor, StringComparison.OrdinalIgnoreCase);
@ -29,5 +29,4 @@ namespace Common.Extensions
{
return string.Format(value, args);
}
}
}

@ -1,10 +1,10 @@
using System;
using Newtonsoft.Json.Linq;
namespace Common
namespace Common;
public static class JsonNetExtensions
{
public static class JsonNetExtensions
{
public static JEnumerable<T> Children<T>(this JToken token, string key)
where T : JToken
{
@ -22,5 +22,4 @@ namespace Common
return value;
}
}
}

@ -3,10 +3,10 @@ using System.IO;
using System.Reflection;
using System.Text;
namespace Common
namespace Common;
public class ResourceDataReader
{
public class ResourceDataReader
{
private readonly Assembly? _assembly;
private readonly string? _namespace;
private readonly string _subdirectory;
@ -39,5 +39,4 @@ namespace Common
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}
}

@ -2,16 +2,15 @@ using System;
using System.Collections;
using System.ComponentModel.DataAnnotations;
namespace Common.YamlDotNet
namespace Common.YamlDotNet;
[AttributeUsage(AttributeTargets.Property)]
public sealed class CannotBeEmptyAttribute : RequiredAttribute
{
[AttributeUsage(AttributeTargets.Property)]
public sealed class CannotBeEmptyAttribute : RequiredAttribute
{
public override bool IsValid(object? value)
{
return base.IsValid(value) &&
value is IEnumerable list &&
list.GetEnumerator().MoveNext();
}
}
}

@ -3,10 +3,10 @@ using System.ComponentModel.DataAnnotations;
using YamlDotNet.Core;
using YamlDotNet.Serialization;
namespace Common.YamlDotNet
namespace Common.YamlDotNet;
internal class ValidatingDeserializer : INodeDeserializer
{
internal class ValidatingDeserializer : INodeDeserializer
{
private readonly INodeDeserializer _nodeDeserializer;
public ValidatingDeserializer(INodeDeserializer nodeDeserializer)
@ -41,5 +41,4 @@ namespace Common.YamlDotNet
return true;
}
}
}

@ -2,10 +2,10 @@
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NodeDeserializers;
namespace Common.YamlDotNet
namespace Common.YamlDotNet;
public static class YamlDotNetExtensions
{
public static class YamlDotNetExtensions
{
public static T? DeserializeType<T>(this IDeserializer deserializer, string data)
where T : class
{
@ -26,5 +26,4 @@ namespace Common.YamlDotNet
{
public T? RootObject { get; }
}
}
}

@ -3,12 +3,12 @@ using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
namespace Common.YamlDotNet
namespace Common.YamlDotNet;
// A workaround for nullable enums in YamlDotNet taken from:
// https://github.com/aaubry/YamlDotNet/issues/544#issuecomment-778062351
public class YamlNullableEnumTypeConverter : IYamlTypeConverter
{
// A workaround for nullable enums in YamlDotNet taken from:
// https://github.com/aaubry/YamlDotNet/issues/544#issuecomment-778062351
public class YamlNullableEnumTypeConverter : IYamlTypeConverter
{
public bool Accepts(Type type)
{
return Nullable.GetUnderlyingType(type)?.IsEnum ?? false;
@ -68,5 +68,4 @@ namespace Common.YamlDotNet
var value = scalar.Value;
return value is "" or "~" or "null" or "Null" or "NULL";
}
}
}

@ -1,17 +1,16 @@
using FluentAssertions;
using NUnit.Framework;
namespace TestLibrary.Tests
namespace TestLibrary.Tests;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class StreamBuilderTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class StreamBuilderTest
{
[Test]
public void FromString_UsingString_ShouldOutputSameString()
{
var stream = StreamBuilder.FromString("test");
stream.ReadToEnd().Should().Be("test");
}
}
}

@ -1,17 +1,16 @@
using FluentAssertions;
using NUnit.Framework;
namespace TestLibrary.Tests
namespace TestLibrary.Tests;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class StringUtilsTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class StringUtilsTest
{
[Test]
public void TrimmedString_Newlines_AreStripped()
{
var testStr = "\r\ntest\r\n";
StringUtils.TrimmedString(testStr).Should().Be("test");
}
}
}

@ -2,10 +2,10 @@ using FluentAssertions.Equivalency;
using FluentAssertions.Json;
using Newtonsoft.Json.Linq;
namespace TestLibrary.FluentAssertions
namespace TestLibrary.FluentAssertions;
public class JsonEquivalencyStep : IEquivalencyStep
{
public class JsonEquivalencyStep : IEquivalencyStep
{
public EquivalencyResult Handle(Comparands comparands, IEquivalencyValidationContext context,
IEquivalencyValidator nestedValidator)
{
@ -20,5 +20,4 @@ namespace TestLibrary.FluentAssertions
return EquivalencyResult.AssertionCompleted;
}
}
}

@ -4,10 +4,10 @@ using System.Linq;
using FluentAssertions.Execution;
using NSubstitute.Core.Arguments;
namespace TestLibrary.NSubstitute
namespace TestLibrary.NSubstitute;
public static class Verify
{
public static class Verify
{
public static T That<T>(Action<T> action)
{
return ArgumentMatcher.Enqueue(new AssertionMatcher<T>(action));
@ -37,5 +37,4 @@ namespace TestLibrary.NSubstitute
return false;
}
}
}
}

@ -1,14 +1,13 @@
using System.IO;
using System.Text;
namespace TestLibrary
namespace TestLibrary;
public static class StreamBuilder
{
public static class StreamBuilder
{
public static StreamReader FromString(string data)
{
var stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
return new StreamReader(stream);
}
}
}

@ -1,7 +1,6 @@
namespace TestLibrary
namespace TestLibrary;
public static class StringUtils
{
public static class StringUtils
{
public static string TrimmedString(string value) => value.Trim('\r', '\n');
}
}

@ -8,12 +8,12 @@ using Trash.Command;
// ReSharper disable MethodHasAsyncOverload
namespace Trash.Tests.Command
namespace Trash.Tests.Command;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CreateConfigCommandTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CreateConfigCommandTest
{
[Test]
public async Task CreateConfig_DefaultPath_FileIsCreated()
{
@ -42,5 +42,4 @@ namespace Trash.Tests.Command
filesystem.File.Received().Exists(Arg.Is("some/other/path.yml"));
filesystem.File.Received().WriteAllText(Arg.Is("some/other/path.yml"), Arg.Any<string>());
}
}
}

@ -5,12 +5,12 @@ using FluentAssertions;
using NUnit.Framework;
using Trash.Command.Helpers;
namespace Trash.Tests.Command.Helpers
namespace Trash.Tests.Command.Helpers;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CliTypeActivatorTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CliTypeActivatorTest
{
private class NonServiceCommandType
{
}
@ -53,5 +53,4 @@ namespace Trash.Tests.Command.Helpers
activeCommand.Should().BeSameAs(createdType);
activeCommand.Should().BeOfType<StubCommand>();
}
}
}

@ -5,12 +5,12 @@ using Autofac.Core;
using FluentAssertions;
using NUnit.Framework;
namespace Trash.Tests
namespace Trash.Tests;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CompositionRootTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CompositionRootTest
{
private sealed class ConcreteTypeEnumerator : IEnumerable
{
private readonly IContainer _container;
@ -37,5 +37,4 @@ namespace Trash.Tests
.Should().NotThrow()
.And.NotBeNull();
}
}
}

@ -19,12 +19,12 @@ using TrashLib.Sonarr.Config;
using TrashLib.Sonarr.ReleaseProfile;
using YamlDotNet.Serialization.ObjectFactories;
namespace Trash.Tests.Config
namespace Trash.Tests.Config;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ConfigurationLoaderTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ConfigurationLoaderTest
{
private static TextReader GetResourceData(string file)
{
var testData = new ResourceDataReader(typeof(ConfigurationLoaderTest), "Data");
@ -171,5 +171,4 @@ fubar:
Action act = () => configLoader.LoadFromStream(new StringReader(testYml), "fubar");
act.Should().NotThrow();
}
}
}

@ -2,12 +2,12 @@ using System.IO.Abstractions;
using NSubstitute;
using NUnit.Framework;
namespace Trash.Tests
namespace Trash.Tests;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class LogJanitorTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class LogJanitorTest
{
[Test]
public void Keep_correct_number_of_newest_log_files()
{
@ -37,5 +37,4 @@ namespace Trash.Tests
testFileInfoList[2].DidNotReceive().Delete();
testFileInfoList[3].DidNotReceive().Delete();
}
}
}

@ -1,10 +1,10 @@
using System;
using System.IO;
namespace Trash
namespace Trash;
internal static class AppPaths
{
internal static class AppPaths
{
public static string AppDataPath { get; } =
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "trash-updater");
@ -13,5 +13,4 @@ namespace Trash
public static string LogDirectory { get; } = Path.Combine(AppDataPath, "logs");
public static string RepoDirectory { get; } = Path.Combine(AppDataPath, "repo");
}
}

@ -8,12 +8,12 @@ using Common;
using JetBrains.Annotations;
using Serilog;
namespace Trash.Command
namespace Trash.Command;
[Command("create-config", Description = "Create a starter YAML configuration file")]
[UsedImplicitly]
public class CreateConfigCommand : ICommand
{
[Command("create-config", Description = "Create a starter YAML configuration file")]
[UsedImplicitly]
public class CreateConfigCommand : ICommand
{
private readonly IFileSystem _fileSystem;
public CreateConfigCommand(ILogger logger, IFileSystem fileSystem)
@ -45,5 +45,4 @@ namespace Trash.Command
Log.Information("Created configuration at: {Path}", Path);
return default;
}
}
}

@ -1,9 +1,9 @@
using System;
namespace Trash.Command.Helpers
namespace Trash.Command.Helpers;
public class ActiveServiceCommandProvider : IActiveServiceCommandProvider
{
public class ActiveServiceCommandProvider : IActiveServiceCommandProvider
{
private IServiceCommand? _activeCommand;
public IServiceCommand ActiveCommand
@ -12,5 +12,4 @@ namespace Trash.Command.Helpers
throw new InvalidOperationException("The active command has not yet been determined");
set => _activeCommand = value;
}
}
}

@ -1,9 +1,9 @@
using TrashLib.Cache;
namespace Trash.Command.Helpers
namespace Trash.Command.Helpers;
public class CacheStoragePath : ICacheStoragePath
{
public class CacheStoragePath : ICacheStoragePath
{
private readonly IActiveServiceCommandProvider _serviceCommandProvider;
public CacheStoragePath(IActiveServiceCommandProvider serviceCommandProvider)
@ -12,5 +12,4 @@ namespace Trash.Command.Helpers
}
public string Path => _serviceCommandProvider.ActiveCommand.CacheStoragePath;
}
}

@ -1,10 +1,10 @@
using System;
using Autofac;
namespace Trash.Command.Helpers
namespace Trash.Command.Helpers;
internal static class CliTypeActivator
{
internal static class CliTypeActivator
{
public static object ResolveType(IContainer container, Type typeToResolve)
{
var instance = container.Resolve(typeToResolve);
@ -16,5 +16,4 @@ namespace Trash.Command.Helpers
return instance;
}
}
}

@ -1,8 +1,7 @@
namespace Trash.Command.Helpers
namespace Trash.Command.Helpers;
public enum ExitCode
{
public enum ExitCode
{
Success = 0,
Failure = 1
}
}

@ -1,7 +1,6 @@
namespace Trash.Command.Helpers
namespace Trash.Command.Helpers;
public interface IActiveServiceCommandProvider
{
public interface IActiveServiceCommandProvider
{
IServiceCommand ActiveCommand { get; set; }
}
}

@ -1,12 +1,11 @@
using System.Collections.Generic;
namespace Trash.Command.Helpers
namespace Trash.Command.Helpers;
public interface IServiceCommand
{
public interface IServiceCommand
{
bool Preview { get; }
bool Debug { get; }
ICollection<string>? Config { get; }
string CacheStoragePath { get; }
}
}

@ -15,10 +15,10 @@ using Serilog.Events;
using TrashLib.Extensions;
using YamlDotNet.Core;
namespace Trash.Command.Helpers
namespace Trash.Command.Helpers;
public abstract class ServiceCommand : ICommand, IServiceCommand
{
public abstract class ServiceCommand : ICommand, IServiceCommand
{
private readonly ILogger _log;
private readonly LoggingLevelSwitch _loggingLevelSwitch;
private readonly ILogJanitor _logJanitor;
@ -119,5 +119,4 @@ namespace Trash.Command.Helpers
{
throw new CommandException("Exiting due to previous exception");
}
}
}

@ -12,12 +12,12 @@ using TrashLib.Radarr.Config;
using TrashLib.Radarr.CustomFormat;
using TrashLib.Radarr.QualityDefinition;
namespace Trash.Command
namespace Trash.Command;
[Command("radarr", Description = "Perform operations on a Radarr instance")]
[UsedImplicitly]
public class RadarrCommand : ServiceCommand
{
[Command("radarr", Description = "Perform operations on a Radarr instance")]
[UsedImplicitly]
public class RadarrCommand : ServiceCommand
{
private readonly IConfigurationLoader<RadarrConfiguration> _configLoader;
private readonly Func<ICustomFormatUpdater> _customFormatUpdaterFactory;
private readonly ILogger _log;
@ -64,5 +64,4 @@ namespace Trash.Command
ExitDueToFailure();
}
}
}
}

@ -12,12 +12,12 @@ using TrashLib.Sonarr.Config;
using TrashLib.Sonarr.QualityDefinition;
using TrashLib.Sonarr.ReleaseProfile;
namespace Trash.Command
namespace Trash.Command;
[Command("sonarr", Description = "Perform operations on a Sonarr instance")]
[UsedImplicitly]
public class SonarrCommand : ServiceCommand
{
[Command("sonarr", Description = "Perform operations on a Sonarr instance")]
[UsedImplicitly]
public class SonarrCommand : ServiceCommand
{
private readonly IConfigurationLoader<SonarrConfiguration> _configLoader;
private readonly ILogger _log;
private readonly Func<IReleaseProfileUpdater> _profileUpdaterFactory;
@ -64,5 +64,4 @@ namespace Trash.Command
ExitDueToFailure();
}
}
}
}

@ -17,10 +17,10 @@ using TrashLib.Sonarr;
using TrashLib.Startup;
using YamlDotNet.Serialization;
namespace Trash
namespace Trash;
public static class CompositionRoot
{
public static class CompositionRoot
{
private static void SetupLogging(ContainerBuilder builder)
{
builder.RegisterType<LogJanitor>().As<ILogJanitor>();
@ -95,5 +95,4 @@ namespace Trash
return builder.Build();
}
}
}

@ -5,11 +5,11 @@ using System.Runtime.Serialization;
using System.Text;
using FluentValidation.Results;
namespace Trash.Config
namespace Trash.Config;
[Serializable]
public class ConfigurationException : Exception
{
[Serializable]
public class ConfigurationException : Exception
{
protected ConfigurationException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
@ -52,5 +52,4 @@ namespace Trash.Config
return builder.ToString();
}
}
}

@ -10,11 +10,11 @@ using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;
namespace Trash.Config
{
public class ConfigurationLoader<T> : IConfigurationLoader<T>
namespace Trash.Config;
public class ConfigurationLoader<T> : IConfigurationLoader<T>
where T : IServiceConfiguration
{
{
private readonly IConfigurationProvider _configProvider;
private readonly IDeserializer _deserializer;
private readonly IFileSystem _fileSystem;
@ -100,5 +100,4 @@ namespace Trash.Config
yield return config;
}
}
}
}

@ -2,13 +2,12 @@
using System.IO;
using TrashLib.Config;
namespace Trash.Config
{
public interface IConfigurationLoader<out T>
namespace Trash.Config;
public interface IConfigurationLoader<out T>
where T : IServiceConfiguration
{
{
IEnumerable<T> Load(string propertyName, string configSection);
IEnumerable<T> LoadFromStream(TextReader stream, string configSection);
IEnumerable<T> LoadMany(IEnumerable<string> configFiles, string configSection);
}
}

@ -3,10 +3,10 @@ using Autofac;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.ObjectFactories;
namespace Trash.Config
namespace Trash.Config;
public class ObjectFactory : IObjectFactory
{
public class ObjectFactory : IObjectFactory
{
private readonly ILifetimeScope _container;
private readonly DefaultObjectFactory _defaultFactory = new();
@ -19,5 +19,4 @@ namespace Trash.Config
{
return _container.IsRegistered(type) ? _container.Resolve(type) : _defaultFactory.Create(type);
}
}
}

@ -1,7 +1,6 @@
namespace Trash
namespace Trash;
public interface ILogJanitor
{
public interface ILogJanitor
{
void DeleteOldestLogFiles(int numberOfNewestToKeep);
}
}

@ -1,10 +1,10 @@
using System.IO.Abstractions;
using System.Linq;
namespace Trash
namespace Trash;
public class LogJanitor : ILogJanitor
{
public class LogJanitor : ILogJanitor
{
private readonly IFileSystem _fileSystem;
public LogJanitor(IFileSystem fileSystem)
@ -21,5 +21,4 @@ namespace Trash
file.Delete();
}
}
}
}

@ -3,10 +3,10 @@ using Autofac;
using CliFx;
using Trash.Command.Helpers;
namespace Trash
namespace Trash;
internal static class Program
{
internal static class Program
{
private static IContainer? _container;
public static async Task<int> Main()
@ -20,5 +20,4 @@ namespace Trash
.Build()
.RunAsync();
}
}
}

@ -1,9 +1,8 @@
using TrashLib.Radarr.Config;
namespace Trash
namespace Trash;
public class ResourcePaths : IResourcePaths
{
public class ResourcePaths : IResourcePaths
{
public string RepoPath => AppPaths.RepoDirectory;
}
}

@ -1,14 +1,13 @@
using System.Linq;
using TrashLib.Radarr.CustomFormat.Models;
namespace Trash.TestLibrary
namespace Trash.TestLibrary;
public static class CfTestUtils
{
public static class CfTestUtils
{
public static QualityProfileCustomFormatScoreMapping NewMapping(params FormatMappingEntry[] entries)
=> new(false) {Mapping = entries.ToList()};
public static QualityProfileCustomFormatScoreMapping NewMappingWithReset(params FormatMappingEntry[] entries)
=> new(true) {Mapping = entries.ToList()};
}
}

@ -12,12 +12,12 @@ using TestLibrary.NSubstitute;
using TrashLib.Cache;
using TrashLib.Config;
namespace TrashLib.Tests.Cache
namespace TrashLib.Tests.Cache;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ServiceCacheTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ServiceCacheTest
{
private class Context
{
public Context(IFileSystem? fs = null)
@ -152,7 +152,7 @@ namespace TrashLib.Tests.Cache
{
var ctx = new Context();
Action act = () => ctx.Cache.Save(new ObjectWithAttributeInvalidChars());
var act = () => ctx.Cache.Save(new ObjectWithAttributeInvalidChars());
act.Should()
.Throw<ArgumentException>()
@ -164,7 +164,7 @@ namespace TrashLib.Tests.Cache
{
var ctx = new Context();
Action act = () => ctx.Cache.Save(new ObjectWithoutAttribute());
var act = () => ctx.Cache.Save(new ObjectWithoutAttribute());
act.Should()
.Throw<ArgumentException>()
@ -208,5 +208,4 @@ namespace TrashLib.Tests.Cache
act.Should().NotThrow();
}
}
}

@ -11,12 +11,12 @@ using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace TrashLib.Tests.Radarr.CustomFormat
namespace TrashLib.Tests.Radarr.CustomFormat;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CachePersisterTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CachePersisterTest
{
private class Context
{
public Context()
@ -149,5 +149,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat
ctx.Persister.Update(new List<ProcessedCustomFormatData>());
ctx.Persister.CfCache.Should().NotBeNull();
}
}
}

@ -15,12 +15,12 @@ using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Processors;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors
namespace TrashLib.Tests.Radarr.CustomFormat.Processors;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class GuideProcessorTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class GuideProcessorTest
{
private class TestGuideProcessorSteps : IGuideProcessorSteps
{
public ICustomFormatStep CustomFormat { get; } = new CustomFormatStep();
@ -157,5 +157,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors
.Using(new JsonEquivalencyStep())
.ComparingByMembers<FormatMappingEntry>());
}
}
}

@ -7,12 +7,12 @@ using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ConfigStepTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ConfigStepTest
{
[Test]
public void Cache_names_are_used_instead_of_name_in_json_data()
{
@ -221,5 +221,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
.Using<JToken>(jctx => jctx.Subject.Should().BeEquivalentTo(jctx.Expectation))
.WhenTypeIs<JToken>());
}
}
}

@ -11,12 +11,12 @@ using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CustomFormatStepTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CustomFormatStepTest
{
private class Context
{
public List<string> TestGuideData { get; } = new()
@ -385,5 +385,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
},
op => op.Using(new JsonEquivalencyStep()));
}
}
}

@ -8,12 +8,12 @@ using TrashLib.Radarr.Config;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Processors.GuideSteps;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class QualityProfileStepTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class QualityProfileStepTest
{
[Test]
public void No_score_used_if_no_score_in_config_or_guide()
{
@ -130,5 +130,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.GuideSteps
processor.CustomFormatsWithoutScore.Should().BeEmpty();
}
}
}

@ -11,12 +11,12 @@ using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors
namespace TrashLib.Tests.Radarr.CustomFormat.Processors;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class PersistenceProcessorTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class PersistenceProcessorTest
{
[Test]
public void Custom_formats_are_deleted_if_deletion_option_is_enabled_in_config()
{
@ -81,5 +81,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors
steps.JsonTransactionStep.Received(1)
.RecordDeletions(Arg.Any<IEnumerable<TrashIdMapping>>(), Arg.Any<List<JObject>>());
}
}
}

@ -8,12 +8,12 @@ using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CustomFormatApiPersistenceStepTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class CustomFormatApiPersistenceStepTest
{
private static ProcessedCustomFormatData QuickMakeCf(string cfName, string trashId, int cfId)
{
return new ProcessedCustomFormatData(cfName, trashId, new JObject())
@ -43,5 +43,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
api.DeleteCustomFormat(4);
});
}
}
}

@ -37,12 +37,12 @@ using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
}
*/
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class JsonTransactionStepTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class JsonTransactionStepTest
{
[TestCase(1, "cf2")]
[TestCase(2, "cf1")]
[TestCase(null, "cf1")]
@ -423,5 +423,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
processor.Transactions.UnchangedCustomFormats.First().CacheEntry.Should()
.BeEquivalentTo(new TrashIdMapping("", "no_change", 2));
}
}
}

@ -12,12 +12,12 @@ using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class QualityProfileApiPersistenceStepTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class QualityProfileApiPersistenceStepTest
{
[Test]
public void Do_not_invoke_api_if_no_scores_to_update()
{
@ -262,5 +262,4 @@ namespace TrashLib.Tests.Radarr.CustomFormat.Processors.PersistenceSteps
new("asdf2", 102, FormatScoreUpdateReason.Updated)
});
}
}
}

@ -2,12 +2,12 @@ using FluentAssertions;
using NUnit.Framework;
using TrashLib.Radarr.QualityDefinition;
namespace TrashLib.Tests.Radarr.QualityDefinition
namespace TrashLib.Tests.Radarr.QualityDefinition;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class RadarrQualityDataTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class RadarrQualityDataTest
{
private static readonly object[] PreferredTestValues =
{
new object?[] {100m, 100m, false},
@ -117,5 +117,4 @@ namespace TrashLib.Tests.Radarr.QualityDefinition
var data = new RadarrQualityData {Preferred = 0};
data.PreferredForApi.Should().Be(0);
}
}
}

@ -10,12 +10,12 @@ using TrashLib.Radarr;
using TrashLib.Radarr.Config;
using TrashLib.Radarr.QualityDefinition;
namespace TrashLib.Tests.Radarr
namespace TrashLib.Tests.Radarr;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class RadarrConfigurationTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class RadarrConfigurationTest
{
private IContainer _container = default!;
[OneTimeSetUp]
@ -107,5 +107,4 @@ namespace TrashLib.Tests.Radarr
result.IsValid.Should().BeTrue();
result.Errors.Should().BeEmpty();
}
}
}

@ -14,12 +14,12 @@ using TrashLib.Sonarr.Api;
using TrashLib.Sonarr.Api.Objects;
using TrashLib.Startup;
namespace TrashLib.Tests.Sonarr.Api
namespace TrashLib.Tests.Sonarr.Api;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class SonarrReleaseProfileCompatibilityHandlerTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class SonarrReleaseProfileCompatibilityHandlerTest
{
private class TestContext : IDisposable
{
private readonly JsonSerializerSettings _jsonSettings;
@ -114,5 +114,4 @@ namespace TrashLib.Tests.Sonarr.Api
result.Should().BeEquivalentTo(data);
}
}
}

@ -2,12 +2,12 @@ using FluentAssertions;
using NUnit.Framework;
using TrashLib.Sonarr.QualityDefinition;
namespace TrashLib.Tests.Sonarr.QualityDefinition
namespace TrashLib.Tests.Sonarr.QualityDefinition;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class SonarrQualityDataTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class SonarrQualityDataTest
{
private static readonly object[] MaxTestValues =
{
new object?[] {100m, 100m, false},
@ -98,5 +98,4 @@ namespace TrashLib.Tests.Sonarr.QualityDefinition
var data = new SonarrQualityData {Max = 0};
data.MaxForApi.Should().Be(0);
}
}
}

@ -4,12 +4,12 @@ using NUnit.Framework;
using TrashLib.Sonarr.Config;
using TrashLib.Sonarr.ReleaseProfile;
namespace TrashLib.Tests.Sonarr.ReleaseProfile
namespace TrashLib.Tests.Sonarr.ReleaseProfile;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class FilteredProfileDataTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class FilteredProfileDataTest
{
[Test]
public void Filter_ExcludeOptional_HasNoOptionalItems()
{
@ -88,5 +88,4 @@ namespace TrashLib.Tests.Sonarr.ReleaseProfile
}
});
}
}
}

@ -9,12 +9,12 @@ using TestLibrary;
using TrashLib.Sonarr.Config;
using TrashLib.Sonarr.ReleaseProfile;
namespace TrashLib.Tests.Sonarr.ReleaseProfile
namespace TrashLib.Tests.Sonarr.ReleaseProfile;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ReleaseProfileParserTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ReleaseProfileParserTest
{
[OneTimeSetUp]
public void Setup()
{
@ -266,7 +266,7 @@ not-optional1
[Test]
public void Parse_PotentialScore_WarningLogged()
{
string markdown = StringUtils.TrimmedString(@"
var markdown = StringUtils.TrimmedString(@"
# First Release Profile
The below line should be a score but isn't because it's missing the word 'score'.
@ -420,5 +420,4 @@ skipped2
results.Should().BeEquivalentTo(expectedResults);
}
}
}

@ -2,12 +2,12 @@
using NUnit.Framework;
using TrashLib.Sonarr.ReleaseProfile;
namespace TrashLib.Tests.Sonarr.ReleaseProfile
namespace TrashLib.Tests.Sonarr.ReleaseProfile;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ScopedStateTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ScopedStateTest
{
[Test]
public void AccessValue_MultipleScopes_ScopeValuesReturned()
{
@ -127,5 +127,4 @@ namespace TrashLib.Tests.Sonarr.ReleaseProfile
state.ActiveScope.Should().BeNull();
state.Value.Should().Be(50);
}
}
}

@ -6,12 +6,12 @@ using TrashLib.Sonarr.Api;
using TrashLib.Sonarr.Config;
using TrashLib.Sonarr.ReleaseProfile;
namespace TrashLib.Tests.Sonarr
namespace TrashLib.Tests.Sonarr;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ReleaseProfileUpdaterTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ReleaseProfileUpdaterTest
{
private class Context
{
public IReleaseProfileGuideParser Parser { get; } = Substitute.For<IReleaseProfileGuideParser>();
@ -47,5 +47,4 @@ namespace TrashLib.Tests.Sonarr
context.Parser.Received().ParseMarkdown(config.ReleaseProfiles[0], "theMarkdown");
}
}
}

@ -9,12 +9,12 @@ using TrashLib.Sonarr;
using TrashLib.Sonarr.Config;
using TrashLib.Sonarr.ReleaseProfile;
namespace TrashLib.Tests.Sonarr
namespace TrashLib.Tests.Sonarr;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class SonarrConfigurationTest
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class SonarrConfigurationTest
{
private IContainer _container = default!;
[OneTimeSetUp]
@ -66,5 +66,4 @@ namespace TrashLib.Tests.Sonarr
result.IsValid.Should().BeTrue();
result.Errors.Should().BeEmpty();
}
}
}

@ -1,13 +1,12 @@
using Autofac;
namespace TrashLib.Cache
namespace TrashLib.Cache;
public class CacheAutofacModule : Module
{
public class CacheAutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
// Clients must register their own implementation of ICacheStoragePath
builder.RegisterType<ServiceCache>().As<IServiceCache>();
}
}
}

@ -1,15 +1,14 @@
using System;
namespace TrashLib.Cache
namespace TrashLib.Cache;
[AttributeUsage(AttributeTargets.Class)]
internal sealed class CacheObjectNameAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Class)]
internal sealed class CacheObjectNameAttribute : Attribute
{
public CacheObjectNameAttribute(string name)
{
Name = name;
}
public string Name { get; }
}
}

@ -1,7 +1,6 @@
namespace TrashLib.Cache
namespace TrashLib.Cache;
public interface ICacheStoragePath
{
public interface ICacheStoragePath
{
string Path { get; }
}
}

@ -1,8 +1,7 @@
namespace TrashLib.Cache
namespace TrashLib.Cache;
public interface IServiceCache
{
public interface IServiceCache
{
T? Load<T>() where T : class;
void Save<T>(T obj) where T : class;
}
}

@ -11,10 +11,10 @@ using Newtonsoft.Json.Serialization;
using Serilog;
using TrashLib.Config;
namespace TrashLib.Cache
namespace TrashLib.Cache;
internal class ServiceCache : IServiceCache
{
internal class ServiceCache : IServiceCache
{
private static readonly Regex AllowedObjectNameCharacters = new(@"^[\w-]+$", RegexOptions.Compiled);
private readonly IConfigurationProvider _configProvider;
private readonly IFileSystem _fileSystem;
@ -97,5 +97,4 @@ namespace TrashLib.Cache
return Path.Combine(_storagePath.Path, BuildServiceGuid(), objectName + ".json");
}
}
}

@ -3,10 +3,10 @@ using Autofac;
using FluentValidation;
using Module = Autofac.Module;
namespace TrashLib.Config
namespace TrashLib.Config;
public class ConfigAutofacModule : Module
{
public class ConfigAutofacModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<ConfigurationProvider>()
@ -17,5 +17,4 @@ namespace TrashLib.Config
.AsClosedTypesOf(typeof(IValidator<>))
.AsImplementedInterfaces();
}
}
}

@ -1,9 +1,9 @@
using System;
namespace TrashLib.Config
namespace TrashLib.Config;
internal class ConfigurationProvider : IConfigurationProvider
{
internal class ConfigurationProvider : IConfigurationProvider
{
private IServiceConfiguration? _activeConfiguration;
public IServiceConfiguration ActiveConfiguration
@ -11,5 +11,4 @@ namespace TrashLib.Config
get => _activeConfiguration ?? throw new NullReferenceException("Active configuration has not been set");
set => _activeConfiguration = value;
}
}
}

@ -1,7 +1,6 @@
namespace TrashLib.Config
namespace TrashLib.Config;
public interface IConfigurationProvider
{
public interface IConfigurationProvider
{
IServiceConfiguration ActiveConfiguration { get; set; }
}
}

@ -1,9 +1,8 @@
using Flurl.Http;
namespace TrashLib.Config
namespace TrashLib.Config;
public interface IServerInfo
{
public interface IServerInfo
{
IFlurlRequest BuildRequest();
}
}

@ -1,8 +1,7 @@
namespace TrashLib.Config
namespace TrashLib.Config;
public interface IServiceConfiguration
{
public interface IServiceConfiguration
{
string BaseUrl { get; }
string ApiKey { get; }
}
}

@ -3,10 +3,10 @@ using Flurl.Http;
using Serilog;
using TrashLib.Extensions;
namespace TrashLib.Config
namespace TrashLib.Config;
internal class ServerInfo : IServerInfo
{
internal class ServerInfo : IServerInfo
{
private readonly IConfigurationProvider _config;
private readonly ILogger _log;
@ -26,5 +26,4 @@ namespace TrashLib.Config
.SetQueryParams(new {apikey = apiKey})
.SanitizedLogging(_log);
}
}
}

@ -1,8 +1,7 @@
namespace TrashLib.Config
namespace TrashLib.Config;
public abstract class ServiceConfiguration : IServiceConfiguration
{
public abstract class ServiceConfiguration : IServiceConfiguration
{
public string BaseUrl { get; init; } = "";
public string ApiKey { get; init; } = "";
}
}

@ -1,11 +1,11 @@
using System;
using System.Runtime.Serialization;
namespace TrashLib.ExceptionTypes
namespace TrashLib.ExceptionTypes;
[Serializable]
public class VersionException : Exception
{
[Serializable]
public class VersionException : Exception
{
public VersionException(string msg)
: base(msg)
{
@ -15,5 +15,4 @@ namespace TrashLib.ExceptionTypes
: base(info, context)
{
}
}
}

@ -3,10 +3,10 @@ using Flurl;
using Flurl.Http;
using Serilog;
namespace TrashLib.Extensions
namespace TrashLib.Extensions;
public static class FlurlExtensions
{
public static class FlurlExtensions
{
public static IFlurlRequest SanitizedLogging(this Uri url, ILogger log)
=> new FlurlRequest(url).SanitizedLogging(log);
@ -32,5 +32,4 @@ namespace TrashLib.Extensions
return url;
}
}
}

@ -3,10 +3,10 @@ using Flurl;
using Flurl.Http.Configuration;
using Serilog;
namespace TrashLib.Extensions
namespace TrashLib.Extensions;
public static class FlurlLogging
{
public static class FlurlLogging
{
public static void SetupLogging(FlurlHttpSettings settings, ILogger log, Func<Url, Url>? urlInterceptor = null)
{
urlInterceptor ??= url => url;
@ -24,5 +24,4 @@ namespace TrashLib.Extensions
log.Debug("HTTP Response {Status} from {Url}", statusCode, url);
};
}
}
}

@ -1,11 +1,10 @@
namespace TrashLib.Radarr.Config
namespace TrashLib.Radarr.Config;
public interface IRadarrValidationMessages
{
public interface IRadarrValidationMessages
{
string BaseUrl { get; }
string ApiKey { get; }
string CustomFormatNamesAndIds { get; }
string QualityProfileName { get; }
string QualityDefinitionType { get; }
}
}

@ -1,7 +1,6 @@
namespace TrashLib.Radarr.Config
namespace TrashLib.Radarr.Config;
public interface IResourcePaths
{
public interface IResourcePaths
{
string RepoPath { get; }
}
}

@ -3,39 +3,38 @@ using JetBrains.Annotations;
using TrashLib.Config;
using TrashLib.Radarr.QualityDefinition;
namespace TrashLib.Radarr.Config
namespace TrashLib.Radarr.Config;
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class RadarrConfiguration : ServiceConfiguration
{
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class RadarrConfiguration : ServiceConfiguration
{
public QualityDefinitionConfig? QualityDefinition { get; init; }
public ICollection<CustomFormatConfig> CustomFormats { get; init; } = new List<CustomFormatConfig>();
public bool DeleteOldCustomFormats { get; init; }
}
}
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class CustomFormatConfig
{
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class CustomFormatConfig
{
public ICollection<string> Names { get; init; } = new List<string>();
public ICollection<string> TrashIds { get; init; } = new List<string>();
public ICollection<QualityProfileConfig> QualityProfiles { get; init; } = new List<QualityProfileConfig>();
}
}
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class QualityProfileConfig
{
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class QualityProfileConfig
{
public string Name { get; init; } = "";
public int? Score { get; init; }
public bool ResetUnmatchedScores { get; init; }
}
}
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class QualityDefinitionConfig
{
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public class QualityDefinitionConfig
{
// -1 does not map to a valid enumerator. this is to force validation to fail if it is not set from YAML.
// All of this craziness is to avoid making the enum type nullable.
public RadarrQualityDefinitionType Type { get; init; } = (RadarrQualityDefinitionType) (-1);
public decimal PreferredRatio { get; set; } = 1.0m;
}
}

@ -2,11 +2,11 @@ using Common.Extensions;
using FluentValidation;
using JetBrains.Annotations;
namespace TrashLib.Radarr.Config
namespace TrashLib.Radarr.Config;
[UsedImplicitly]
internal class RadarrConfigurationValidator : AbstractValidator<RadarrConfiguration>
{
[UsedImplicitly]
internal class RadarrConfigurationValidator : AbstractValidator<RadarrConfiguration>
{
public RadarrConfigurationValidator(
IRadarrValidationMessages messages,
IValidator<QualityDefinitionConfig> qualityDefinitionConfigValidator,
@ -17,11 +17,11 @@ namespace TrashLib.Radarr.Config
RuleFor(x => x.QualityDefinition).SetNonNullableValidator(qualityDefinitionConfigValidator);
RuleForEach(x => x.CustomFormats).SetValidator(customFormatConfigValidator);
}
}
}
[UsedImplicitly]
internal class CustomFormatConfigValidator : AbstractValidator<CustomFormatConfig>
{
[UsedImplicitly]
internal class CustomFormatConfigValidator : AbstractValidator<CustomFormatConfig>
{
public CustomFormatConfigValidator(
IRadarrValidationMessages messages,
IValidator<QualityProfileConfig> qualityProfileConfigValidator)
@ -30,23 +30,22 @@ namespace TrashLib.Radarr.Config
.WithMessage(messages.CustomFormatNamesAndIds);
RuleForEach(x => x.QualityProfiles).SetValidator(qualityProfileConfigValidator);
}
}
}
[UsedImplicitly]
internal class QualityProfileConfigValidator : AbstractValidator<QualityProfileConfig>
{
[UsedImplicitly]
internal class QualityProfileConfigValidator : AbstractValidator<QualityProfileConfig>
{
public QualityProfileConfigValidator(IRadarrValidationMessages messages)
{
RuleFor(x => x.Name).NotEmpty().WithMessage(messages.QualityProfileName);
}
}
}
[UsedImplicitly]
internal class QualityDefinitionConfigValidator : AbstractValidator<QualityDefinitionConfig>
{
[UsedImplicitly]
internal class QualityDefinitionConfigValidator : AbstractValidator<QualityDefinitionConfig>
{
public QualityDefinitionConfigValidator(IRadarrValidationMessages messages)
{
RuleFor(x => x.Type).IsInEnum().WithMessage(messages.QualityDefinitionType);
}
}
}

@ -1,7 +1,7 @@
namespace TrashLib.Radarr.Config
namespace TrashLib.Radarr.Config;
internal class RadarrValidationMessages : IRadarrValidationMessages
{
internal class RadarrValidationMessages : IRadarrValidationMessages
{
public string BaseUrl =>
"Property 'base_url' is required";
@ -16,5 +16,4 @@ namespace TrashLib.Radarr.Config
public string QualityDefinitionType =>
"'type' is required for 'quality_definition'";
}
}

@ -5,10 +5,10 @@ using Newtonsoft.Json.Linq;
using TrashLib.Config;
using TrashLib.Radarr.CustomFormat.Models;
namespace TrashLib.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api;
internal class CustomFormatService : ICustomFormatService
{
internal class CustomFormatService : ICustomFormatService
{
private readonly IServerInfo _serverInfo;
public CustomFormatService(IServerInfo serverInfo)
@ -52,5 +52,4 @@ namespace TrashLib.Radarr.CustomFormat.Api
}
private IFlurlRequest BuildRequest() => _serverInfo.BuildRequest();
}
}

@ -3,13 +3,12 @@ using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using TrashLib.Radarr.CustomFormat.Models;
namespace TrashLib.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api;
public interface ICustomFormatService
{
public interface ICustomFormatService
{
Task<List<JObject>> GetCustomFormats();
Task CreateCustomFormat(ProcessedCustomFormatData cf);
Task UpdateCustomFormat(ProcessedCustomFormatData cf);
Task DeleteCustomFormat(int customFormatId);
}
}

@ -2,11 +2,10 @@
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace TrashLib.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api;
public interface IQualityProfileService
{
public interface IQualityProfileService
{
Task<List<JObject>> GetQualityProfiles();
Task<JObject> UpdateQualityProfile(JObject profileJson, int id);
}
}

@ -4,10 +4,10 @@ using Flurl.Http;
using Newtonsoft.Json.Linq;
using TrashLib.Config;
namespace TrashLib.Radarr.CustomFormat.Api
namespace TrashLib.Radarr.CustomFormat.Api;
internal class QualityProfileService : IQualityProfileService
{
internal class QualityProfileService : IQualityProfileService
{
private readonly IServerInfo _serverInfo;
public QualityProfileService(IServerInfo serverInfo)
@ -31,5 +31,4 @@ namespace TrashLib.Radarr.CustomFormat.Api
}
private IFlurlRequest BuildRequest() => _serverInfo.BuildRequest();
}
}

@ -1,10 +1,9 @@
namespace TrashLib.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat;
public enum ApiOperationType
{
public enum ApiOperationType
{
Create,
Update,
NoChange,
Delete
}
}

@ -6,10 +6,10 @@ using TrashLib.Cache;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace TrashLib.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat;
internal class CachePersister : ICachePersister
{
internal class CachePersister : ICachePersister
{
private readonly IServiceCache _cache;
public CachePersister(ILogger log, IServiceCache cache)
@ -64,5 +64,4 @@ namespace TrashLib.Radarr.CustomFormat
.Where(cf => cf.CacheEntry != null)
.Select(cf => cf.CacheEntry!));
}
}
}

@ -7,10 +7,10 @@ using TrashLib.Radarr.Config;
using TrashLib.Radarr.CustomFormat.Processors;
using TrashLib.Radarr.CustomFormat.Processors.PersistenceSteps;
namespace TrashLib.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat;
internal class CustomFormatUpdater : ICustomFormatUpdater
{
internal class CustomFormatUpdater : ICustomFormatUpdater
{
private readonly ICachePersister _cache;
private readonly IGuideProcessor _guideProcessor;
private readonly IPersistenceProcessor _persistenceProcessor;
@ -268,5 +268,4 @@ namespace TrashLib.Radarr.CustomFormat
Console.WriteLine("");
}
}
}

@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace TrashLib.Radarr.CustomFormat.Guide
namespace TrashLib.Radarr.CustomFormat.Guide;
public interface IRadarrGuideService
{
public interface IRadarrGuideService
{
Task<IEnumerable<string>> GetCustomFormatJsonAsync();
}
}

@ -2,13 +2,12 @@ using System.Collections.Generic;
using TrashLib.Radarr.CustomFormat.Models;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace TrashLib.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat;
public interface ICachePersister
{
public interface ICachePersister
{
CustomFormatCache? CfCache { get; }
void Load();
void Save();
void Update(IEnumerable<ProcessedCustomFormatData> customFormats);
}
}

@ -1,10 +1,9 @@
using System.Threading.Tasks;
using TrashLib.Radarr.Config;
namespace TrashLib.Radarr.CustomFormat
namespace TrashLib.Radarr.CustomFormat;
public interface ICustomFormatUpdater
{
public interface ICustomFormatUpdater
{
Task Process(bool isPreview, RadarrConfiguration config);
}
}

@ -1,19 +1,19 @@
using System.Collections.ObjectModel;
using TrashLib.Cache;
namespace TrashLib.Radarr.CustomFormat.Models.Cache
namespace TrashLib.Radarr.CustomFormat.Models.Cache;
[CacheObjectName("custom-format-cache")]
public class CustomFormatCache
{
[CacheObjectName("custom-format-cache")]
public class CustomFormatCache
{
public const int LatestVersion = 1;
public int Version { get; init; } = LatestVersion;
public Collection<TrashIdMapping> TrashIdMappings { get; init; } = new();
}
}
public class TrashIdMapping
{
public class TrashIdMapping
{
public TrashIdMapping(string trashId, string customFormatName, int customFormatId = default)
{
CustomFormatName = customFormatName;
@ -24,5 +24,4 @@ namespace TrashLib.Radarr.CustomFormat.Models.Cache
public string CustomFormatName { get; set; }
public string TrashId { get; }
public int CustomFormatId { get; set; }
}
}

@ -1,14 +1,13 @@
using System.Collections.Generic;
using TrashLib.Radarr.Config;
namespace TrashLib.Radarr.CustomFormat.Models
namespace TrashLib.Radarr.CustomFormat.Models;
public class ProcessedConfigData
{
public class ProcessedConfigData
{
public ICollection<ProcessedCustomFormatData> CustomFormats { get; init; }
= new List<ProcessedCustomFormatData>();
public ICollection<QualityProfileConfig> QualityProfiles { get; init; }
= new List<QualityProfileConfig>();
}
}

@ -3,10 +3,10 @@ using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json.Linq;
using TrashLib.Radarr.CustomFormat.Models.Cache;
namespace TrashLib.Radarr.CustomFormat.Models
namespace TrashLib.Radarr.CustomFormat.Models;
public class ProcessedCustomFormatData
{
public class ProcessedCustomFormatData
{
public ProcessedCustomFormatData(string name, string trashId, JObject json)
{
Name = name;
@ -32,5 +32,4 @@ namespace TrashLib.Radarr.CustomFormat.Models
public int GetCustomFormatId()
=> CacheEntry?.CustomFormatId ??
throw new InvalidOperationException("CacheEntry must exist to obtain custom format ID");
}
}

@ -1,11 +1,11 @@
using System.Collections.Generic;
namespace TrashLib.Radarr.CustomFormat.Models
{
public record FormatMappingEntry(ProcessedCustomFormatData CustomFormat, int Score);
namespace TrashLib.Radarr.CustomFormat.Models;
public class QualityProfileCustomFormatScoreMapping
{
public record FormatMappingEntry(ProcessedCustomFormatData CustomFormat, int Score);
public class QualityProfileCustomFormatScoreMapping
{
public QualityProfileCustomFormatScoreMapping(bool resetUnmatchedScores)
{
ResetUnmatchedScores = resetUnmatchedScores;
@ -13,5 +13,4 @@ namespace TrashLib.Radarr.CustomFormat.Models
public bool ResetUnmatchedScores { get; }
public ICollection<FormatMappingEntry> Mapping { get; init; } = new List<FormatMappingEntry>();
}
}

@ -1,13 +1,12 @@
namespace TrashLib.Radarr.CustomFormat.Models
namespace TrashLib.Radarr.CustomFormat.Models;
public enum FormatScoreUpdateReason
{
public enum FormatScoreUpdateReason
{
Updated,
Reset
}
}
public record UpdatedFormatScore(
public record UpdatedFormatScore(
string CustomFormatName,
int Score,
FormatScoreUpdateReason Reason);
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save