refactor: Remove unnecessary Reset and factory semantics from steps

pull/138/head
Robert Dailey 2 years ago
parent 87747680ba
commit bdaada1049

@ -52,7 +52,7 @@ public class GuideProcessorTest
{
var ctx = new Context();
var guideService = Substitute.For<IRadarrGuideService>();
var guideProcessor = new GuideProcessor(() => new TestGuideProcessorSteps());
var guideProcessor = new GuideProcessor(new TestGuideProcessorSteps());
// simulate guide data
guideService.GetCustomFormatData().Returns(new[]

@ -27,7 +27,7 @@ public class PersistenceProcessorTest
var deletedCfsInCache = new Collection<TrashIdMapping>();
var profileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
var processor = new PersistenceProcessor(cfApi, qpApi, config, () => steps);
var processor = new PersistenceProcessor(cfApi, qpApi, config, steps);
await processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
steps.JsonTransactionStep.Received().RecordDeletions(Arg.Is(deletedCfsInCache), Arg.Any<List<JObject>>());
@ -46,7 +46,7 @@ public class PersistenceProcessorTest
var deletedCfsInCache = Array.Empty<TrashIdMapping>();
var profileScores = new Dictionary<string, QualityProfileCustomFormatScoreMapping>();
var processor = new PersistenceProcessor(cfApi, qpApi, config, () => steps);
var processor = new PersistenceProcessor(cfApi, qpApi, config, steps);
await processor.PersistCustomFormats(guideCfs, deletedCfsInCache, profileScores);
steps.JsonTransactionStep.DidNotReceive()

@ -60,9 +60,6 @@ internal class CustomFormatUpdater : ICustomFormatUpdater
_cache.Update(_guideProcessor.ProcessedCustomFormats);
_cache.Save();
}
_persistenceProcessor.Reset();
_guideProcessor.Reset();
}
private void PrintQualityProfileUpdates()

@ -15,14 +15,12 @@ public interface IGuideProcessorSteps
internal class GuideProcessor : IGuideProcessor
{
private readonly Func<IGuideProcessorSteps> _stepsFactory;
private IList<CustomFormatData>? _guideCustomFormatJson;
private IGuideProcessorSteps _steps;
private readonly IGuideProcessorSteps _steps;
public GuideProcessor(Func<IGuideProcessorSteps> stepsFactory)
public GuideProcessor(IGuideProcessorSteps steps)
{
_stepsFactory = stepsFactory;
_steps = stepsFactory();
_steps = steps;
}
public IReadOnlyCollection<ProcessedCustomFormatData> ProcessedCustomFormats
@ -79,9 +77,4 @@ internal class GuideProcessor : IGuideProcessor
return Task.CompletedTask;
}
public void Reset()
{
_steps = _stepsFactory();
}
}

@ -19,6 +19,4 @@ internal interface IGuideProcessor
Task BuildGuideDataAsync(IEnumerable<CustomFormatConfig> config, CustomFormatCache? cache,
IGuideService guideService);
void Reset();
}

@ -13,6 +13,4 @@ public interface IPersistenceProcessor
Task PersistCustomFormats(IReadOnlyCollection<ProcessedCustomFormatData> guideCfs,
IEnumerable<TrashIdMapping> deletedCfsInCache,
IDictionary<string, QualityProfileCustomFormatScoreMapping> profileScores);
void Reset();
}

@ -18,20 +18,18 @@ internal class PersistenceProcessor : IPersistenceProcessor
private readonly IServiceConfiguration _config;
private readonly ICustomFormatService _customFormatService;
private readonly IQualityProfileService _qualityProfileService;
private readonly Func<IPersistenceProcessorSteps> _stepsFactory;
private IPersistenceProcessorSteps _steps;
private readonly IPersistenceProcessorSteps _steps;
public PersistenceProcessor(
ICustomFormatService customFormatService,
IQualityProfileService qualityProfileService,
IServiceConfiguration config,
Func<IPersistenceProcessorSteps> stepsFactory)
IPersistenceProcessorSteps steps)
{
_customFormatService = customFormatService;
_qualityProfileService = qualityProfileService;
_stepsFactory = stepsFactory;
_config = config;
_steps = _stepsFactory();
_steps = steps;
}
public CustomFormatTransactionData Transactions
@ -43,11 +41,6 @@ internal class PersistenceProcessor : IPersistenceProcessor
public IReadOnlyCollection<string> InvalidProfileNames
=> _steps.ProfileQualityProfileApiPersister.InvalidProfileNames;
public void Reset()
{
_steps = _stepsFactory();
}
public async Task PersistCustomFormats(IReadOnlyCollection<ProcessedCustomFormatData> guideCfs,
IEnumerable<TrashIdMapping> deletedCfsInCache,
IDictionary<string, QualityProfileCustomFormatScoreMapping> profileScores)

Loading…
Cancel
Save