You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
2.5 KiB
94 lines
2.5 KiB
1 year ago
|
using System.Text.Json;
|
||
|
using Recyclarr.Json;
|
||
1 year ago
|
using Recyclarr.TrashGuide.CustomFormat;
|
||
2 years ago
|
|
||
2 years ago
|
namespace Recyclarr.Cli.Tests.Pipelines.CustomFormat.Models;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
|
public class FieldsArrayJsonConverterTest
|
||
|
{
|
||
|
[Test]
|
||
|
public void Read_multiple_as_array()
|
||
|
{
|
||
1 year ago
|
const string json =
|
||
|
"""
|
||
|
{
|
||
|
"fields": [
|
||
|
{
|
||
|
"order": 0,
|
||
|
"name": "min",
|
||
|
"label": "Minimum Size",
|
||
|
"unit": "GB",
|
||
|
"helpText": "Release must be greater than this size",
|
||
|
"value": 25,
|
||
|
"type": "number",
|
||
|
"advanced": false
|
||
|
},
|
||
|
{
|
||
|
"order": 1,
|
||
|
"name": "max",
|
||
|
"label": "Maximum Size",
|
||
|
"unit": "GB",
|
||
|
"helpText": "Release must be less than or equal to this size",
|
||
|
"value": 40,
|
||
|
"type": "number",
|
||
|
"advanced": false
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
""";
|
||
2 years ago
|
|
||
1 year ago
|
var result =
|
||
|
JsonSerializer.Deserialize<CustomFormatSpecificationData>(json, GlobalJsonSerializerSettings.Services);
|
||
|
|
||
|
result!.Fields.Should().BeEquivalentTo(new[]
|
||
2 years ago
|
{
|
||
1 year ago
|
new CustomFormatFieldData {Value = 25},
|
||
|
new CustomFormatFieldData {Value = 40}
|
||
2 years ago
|
});
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Read_single_as_array()
|
||
|
{
|
||
1 year ago
|
const string json =
|
||
|
"""
|
||
|
{
|
||
|
"fields": {
|
||
|
"order": 0,
|
||
|
"name": "min",
|
||
|
"label": "Minimum Size",
|
||
|
"unit": "GB",
|
||
|
"helpText": "Release must be greater than this size",
|
||
1 year ago
|
"value": "25",
|
||
1 year ago
|
"type": "number",
|
||
|
"advanced": false
|
||
|
}
|
||
|
}
|
||
|
""";
|
||
1 year ago
|
var result =
|
||
|
JsonSerializer.Deserialize<CustomFormatSpecificationData>(json, GlobalJsonSerializerSettings.Services);
|
||
2 years ago
|
|
||
1 year ago
|
result!.Fields.Should().BeEquivalentTo(new[]
|
||
2 years ago
|
{
|
||
1 year ago
|
new CustomFormatFieldData {Value = "25"}
|
||
2 years ago
|
});
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void Read_throws_on_unsupported_token_type()
|
||
|
{
|
||
1 year ago
|
const string json =
|
||
|
"""
|
||
|
{
|
||
|
"fields": 0
|
||
|
}
|
||
|
""";
|
||
2 years ago
|
|
||
1 year ago
|
var act = () => JsonSerializer.Deserialize<CustomFormatSpecificationData>(
|
||
|
json, GlobalJsonSerializerSettings.Services);
|
||
|
|
||
|
act.Should().Throw<JsonException>();
|
||
2 years ago
|
}
|
||
|
}
|