refactor: Redesign limit factory to make code more testable

The quality size factory now implements an interface so that tests can
mock it.
pull/312/head
Robert Dailey 3 months ago
parent 042840b8bc
commit e33b75d3f1

@ -0,0 +1,9 @@
using Recyclarr.TrashGuide;
using Recyclarr.TrashGuide.QualitySize;
namespace Recyclarr.Cli.Pipelines.QualitySize.PipelinePhases.Limits;
public interface IQualityItemLimitFactory
{
Task<QualityItemLimits> Create(SupportedServices serviceType, CancellationToken ct);
}

@ -5,6 +5,7 @@ using Recyclarr.TrashGuide.QualitySize;
namespace Recyclarr.Cli.Pipelines.QualitySize.PipelinePhases.Limits;
public class QualityItemLimitFactory(IIndex<SupportedServices, IQualityItemLimitFetcher> limitFactory)
: IQualityItemLimitFactory
{
public async Task<QualityItemLimits> Create(SupportedServices serviceType, CancellationToken ct)
{

@ -11,7 +11,7 @@ public class QualitySizeConfigPhase(
ILogger log,
IQualitySizeGuideService guide,
IServiceConfiguration config,
QualityItemLimitFactory limitFactory)
IQualityItemLimitFactory limitFactory)
: IConfigPipelinePhase<QualitySizePipelineContext>
{
public async Task Execute(QualitySizePipelineContext context, CancellationToken ct)

@ -14,7 +14,7 @@ public class QualitySizeAutofacModule : Module
builder.RegisterType<QualitySizeDataLister>();
// Setup factory for creation of concrete IQualityItemLimits types
builder.RegisterType<QualityItemLimitFactory>();
builder.RegisterType<QualityItemLimitFactory>().As<IQualityItemLimitFactory>();
builder.RegisterType<RadarrQualityItemLimitFetcher>()
.Keyed<IQualityItemLimitFetcher>(SupportedServices.Radarr)
.InstancePerLifetimeScope();

@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\src\Recyclarr.Cli\Recyclarr.Cli.csproj" />
<ProjectReference Include="..\Recyclarr.Tests.TestLibrary\Recyclarr.Tests.TestLibrary.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,16 @@
using Recyclarr.Cli.Pipelines.QualitySize.PipelinePhases.Limits;
using Recyclarr.Tests.TestLibrary;
using Recyclarr.TrashGuide;
using Recyclarr.TrashGuide.QualitySize;
namespace Recyclarr.Cli.TestLibrary;
public class TestQualityItemLimitFactory : IQualityItemLimitFactory
{
public Task<QualityItemLimits> Create(SupportedServices serviceType, CancellationToken ct)
{
return Task.FromResult(new QualityItemLimits(
TestQualityItemLimits.MaxUnlimitedThreshold,
TestQualityItemLimits.PreferredUnlimitedThreshold));
}
}

@ -1,6 +1,7 @@
using NSubstitute.ReturnsExtensions;
using Recyclarr.Cli.Pipelines.QualitySize;
using Recyclarr.Cli.Pipelines.QualitySize.PipelinePhases;
using Recyclarr.Cli.TestLibrary;
using Recyclarr.Config.Models;
using Recyclarr.TrashGuide.QualitySize;
@ -73,6 +74,7 @@ public class QualitySizeConfigPhaseTest
public async Task Preferred_is_set_via_ratio(
[Frozen] IQualitySizeGuideService guide,
[Frozen] IServiceConfiguration config,
[Frozen(Matching.ImplementedInterfaces)] TestQualityItemLimitFactory limitFactory,
QualitySizeConfigPhase sut)
{
config.QualityDefinition.Returns(new QualityDefinitionConfig
@ -107,6 +109,7 @@ public class QualitySizeConfigPhaseTest
public async Task Preferred_is_set_via_guide(
[Frozen] IQualitySizeGuideService guide,
[Frozen] IServiceConfiguration config,
[Frozen(Matching.ImplementedInterfaces)] TestQualityItemLimitFactory limitFactory,
QualitySizeConfigPhase sut)
{
config.QualityDefinition.Returns(new QualityDefinitionConfig

Loading…
Cancel
Save