fix: Exception when either Sonarr or Radarr configs are empty

pull/201/head
Robert Dailey 2 years ago
parent d072e77b3c
commit adeb478777

@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Environment variables may now be used in YAML configuration (#145).
### Fixed
- Exception when there's not configuration for both Sonarr and Radarr together.
## [4.2.0] - 2023-01-13
### Added

@ -0,0 +1,42 @@
using FluentAssertions;
using NUnit.Framework;
using Recyclarr.TrashLib.Config;
using Recyclarr.TrashLib.Config.Parsing;
using Recyclarr.TrashLib.Services.Radarr.Config;
using Recyclarr.TrashLib.Services.Sonarr.Config;
namespace Recyclarr.TrashLib.Tests.Config.Parsing;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class ConfigRegistryTest
{
[Test]
public void Get_configs_by_type()
{
var configs = new[]
{
new SonarrConfiguration {InstanceName = "one"},
new SonarrConfiguration {InstanceName = "two"}
};
var sut = new ConfigRegistry();
sut.Add(SupportedServices.Sonarr, configs[0]);
sut.Add(SupportedServices.Sonarr, configs[1]);
var result = sut.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr);
result.Should().Equal(configs);
}
[Test]
public void Get_empty_collection_when_no_configs_of_type()
{
var sut = new ConfigRegistry();
sut.Add(SupportedServices.Sonarr, new SonarrConfiguration());
var result = sut.GetConfigsOfType<RadarrConfiguration>(SupportedServices.Radarr);
result.Should().BeEmpty();
}
}

@ -14,7 +14,12 @@ public class ConfigRegistry : IConfigRegistry
public IReadOnlyCollection<T> GetConfigsOfType<T>(SupportedServices serviceType) where T : ServiceConfiguration
{
return _configs[serviceType].Cast<T>().ToList();
if (_configs.TryGetValue(serviceType, out var configs))
{
return configs.Cast<T>().ToList();
}
return Array.Empty<T>();
}
public bool DoesConfigExist(string name)

Loading…
Cancel
Save