New minimum version is `3.0.9.1549`.json-serializing-nullable-fields-issue
parent
19849b33b4
commit
b6de1bf97e
@ -1,14 +0,0 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Recyclarr.Cli.Pipelines.ReleaseProfile.Api.Objects;
|
|
||||||
using Recyclarr.TrashLib.Config;
|
|
||||||
|
|
||||||
namespace Recyclarr.Cli.Pipelines.ReleaseProfile.Api;
|
|
||||||
|
|
||||||
public interface ISonarrReleaseProfileCompatibilityHandler
|
|
||||||
{
|
|
||||||
Task<object> CompatibleReleaseProfileForSending(
|
|
||||||
IServiceConfiguration config,
|
|
||||||
SonarrReleaseProfile profile);
|
|
||||||
|
|
||||||
SonarrReleaseProfile CompatibleReleaseProfileForReceiving(JObject profile);
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
using AutoMapper;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Newtonsoft.Json.Schema;
|
|
||||||
using Recyclarr.Cli.Pipelines.ReleaseProfile.Api.Objects;
|
|
||||||
using Recyclarr.Cli.Pipelines.ReleaseProfile.Api.Schemas;
|
|
||||||
using Recyclarr.TrashLib.Compatibility.Sonarr;
|
|
||||||
using Recyclarr.TrashLib.Config;
|
|
||||||
|
|
||||||
namespace Recyclarr.Cli.Pipelines.ReleaseProfile.Api;
|
|
||||||
|
|
||||||
public class SonarrReleaseProfileCompatibilityHandler : ISonarrReleaseProfileCompatibilityHandler
|
|
||||||
{
|
|
||||||
private readonly ILogger _log;
|
|
||||||
private readonly ISonarrCapabilityFetcher _capabilityFetcher;
|
|
||||||
private readonly IMapper _mapper;
|
|
||||||
|
|
||||||
public SonarrReleaseProfileCompatibilityHandler(
|
|
||||||
ILogger log,
|
|
||||||
ISonarrCapabilityFetcher capabilityFetcher,
|
|
||||||
IMapper mapper)
|
|
||||||
{
|
|
||||||
_log = log;
|
|
||||||
_capabilityFetcher = capabilityFetcher;
|
|
||||||
_mapper = mapper;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<object> CompatibleReleaseProfileForSending(
|
|
||||||
IServiceConfiguration config,
|
|
||||||
SonarrReleaseProfile profile)
|
|
||||||
{
|
|
||||||
var capabilities = await _capabilityFetcher.GetCapabilities(config);
|
|
||||||
|
|
||||||
return capabilities.ArraysNeededForReleaseProfileRequiredAndIgnored
|
|
||||||
? profile
|
|
||||||
: _mapper.Map<SonarrReleaseProfileV1>(profile);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SonarrReleaseProfile CompatibleReleaseProfileForReceiving(JObject profile)
|
|
||||||
{
|
|
||||||
var schema = JSchema.Parse(SonarrReleaseProfileSchema.V2);
|
|
||||||
if (profile.IsValid(schema, out IList<string>? errorMessages))
|
|
||||||
{
|
|
||||||
return profile.ToObject<SonarrReleaseProfile>()
|
|
||||||
?? throw new InvalidDataException("SonarrReleaseProfile V2 parsing failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
_log.Debug("SonarrReleaseProfile is not a match for V2, proceeding to V1: {Reasons}", errorMessages);
|
|
||||||
|
|
||||||
schema = JSchema.Parse(SonarrReleaseProfileSchema.V1);
|
|
||||||
if (profile.IsValid(schema, out errorMessages))
|
|
||||||
{
|
|
||||||
// This will throw if there's an issue during mapping.
|
|
||||||
return _mapper.Map<SonarrReleaseProfile>(profile.ToObject<SonarrReleaseProfileV1>());
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new InvalidDataException(
|
|
||||||
$"SonarrReleaseProfile expected, but no supported schema detected: {errorMessages}");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using System.ComponentModel;
|
|
||||||
using System.Globalization;
|
|
||||||
|
|
||||||
namespace Recyclarr.TrashLib.Config.Parsing.BackwardCompatibility;
|
|
||||||
|
|
||||||
public class ResetUnmatchedScoresYamlTypeConverter : TypeConverter
|
|
||||||
{
|
|
||||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
|
||||||
{
|
|
||||||
return sourceType == typeof(bool) || sourceType == typeof(string);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
|
|
||||||
{
|
|
||||||
var enabledFlag = Convert.ToBoolean(value);
|
|
||||||
return new ResetUnmatchedScoresConfigYaml
|
|
||||||
{
|
|
||||||
FromBool = true,
|
|
||||||
Enabled = enabledFlag
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,92 +0,0 @@
|
|||||||
using Autofac;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
using Recyclarr.Cli.Pipelines.ReleaseProfile.Api;
|
|
||||||
using Recyclarr.Cli.Pipelines.ReleaseProfile.Api.Objects;
|
|
||||||
using Recyclarr.Cli.TestLibrary;
|
|
||||||
using Recyclarr.TestLibrary.Autofac;
|
|
||||||
using Recyclarr.TrashLib.Compatibility.Sonarr;
|
|
||||||
using Recyclarr.TrashLib.Config;
|
|
||||||
|
|
||||||
namespace Recyclarr.Cli.Tests.Pipelines.ReleaseProfile.Api;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
[Parallelizable(ParallelScope.All)]
|
|
||||||
public class SonarrReleaseProfileCompatibilityHandlerTest : CliIntegrationFixture
|
|
||||||
{
|
|
||||||
private static JObject SerializeJson<T>(T obj)
|
|
||||||
{
|
|
||||||
JsonSerializerSettings jsonSettings = new()
|
|
||||||
{
|
|
||||||
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
|
||||||
};
|
|
||||||
|
|
||||||
return JObject.Parse(JsonConvert.SerializeObject(obj, jsonSettings));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void RegisterTypes(ContainerBuilder builder)
|
|
||||||
{
|
|
||||||
base.RegisterTypes(builder);
|
|
||||||
builder.RegisterMockFor<ISonarrCapabilityFetcher>();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Receive_v1_to_v2()
|
|
||||||
{
|
|
||||||
var sut = Resolve<SonarrReleaseProfileCompatibilityHandler>();
|
|
||||||
var dataV1 = new SonarrReleaseProfileV1 {Ignored = "one,two,three"};
|
|
||||||
|
|
||||||
var result = sut.CompatibleReleaseProfileForReceiving(SerializeJson(dataV1));
|
|
||||||
|
|
||||||
result.Should().BeEquivalentTo(new SonarrReleaseProfile
|
|
||||||
{
|
|
||||||
Ignored = new List<string> {"one", "two", "three"}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Receive_v2_to_v2()
|
|
||||||
{
|
|
||||||
var sut = Resolve<SonarrReleaseProfileCompatibilityHandler>();
|
|
||||||
var dataV2 = new SonarrReleaseProfile {Ignored = new List<string> {"one", "two", "three"}};
|
|
||||||
|
|
||||||
var result = sut.CompatibleReleaseProfileForReceiving(SerializeJson(dataV2));
|
|
||||||
|
|
||||||
result.Should().BeEquivalentTo(dataV2);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task Send_v2_to_v1()
|
|
||||||
{
|
|
||||||
var capabilityChecker = Resolve<ISonarrCapabilityFetcher>();
|
|
||||||
capabilityChecker.GetCapabilities(default!).ReturnsForAnyArgs(new SonarrCapabilities
|
|
||||||
{
|
|
||||||
ArraysNeededForReleaseProfileRequiredAndIgnored = false
|
|
||||||
});
|
|
||||||
|
|
||||||
var sut = Resolve<SonarrReleaseProfileCompatibilityHandler>();
|
|
||||||
var data = new SonarrReleaseProfile {Ignored = new List<string> {"one", "two", "three"}};
|
|
||||||
|
|
||||||
var result = await sut.CompatibleReleaseProfileForSending(Substitute.For<IServiceConfiguration>(), data);
|
|
||||||
|
|
||||||
result.Should().BeEquivalentTo(new SonarrReleaseProfileV1 {Ignored = "one,two,three"});
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public async Task Send_v2_to_v2()
|
|
||||||
{
|
|
||||||
var capabilityChecker = Resolve<ISonarrCapabilityFetcher>();
|
|
||||||
capabilityChecker.GetCapabilities(default!).ReturnsForAnyArgs(new SonarrCapabilities
|
|
||||||
{
|
|
||||||
ArraysNeededForReleaseProfileRequiredAndIgnored = true
|
|
||||||
});
|
|
||||||
|
|
||||||
var sut = Resolve<SonarrReleaseProfileCompatibilityHandler>();
|
|
||||||
var data = new SonarrReleaseProfile {Ignored = new List<string> {"one", "two", "three"}};
|
|
||||||
|
|
||||||
var result = await sut.CompatibleReleaseProfileForSending(Substitute.For<IServiceConfiguration>(), data);
|
|
||||||
|
|
||||||
result.Should().BeEquivalentTo(data);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue