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.
113 lines
3.7 KiB
113 lines
3.7 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using AutoMapper;
|
|
using FluentAssertions;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json.Serialization;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using TrashLib.Sonarr;
|
|
using TrashLib.Sonarr.Api;
|
|
using TrashLib.Sonarr.Api.Objects;
|
|
using TrashLib.Startup;
|
|
|
|
namespace TrashLib.Tests.Sonarr.Api
|
|
{
|
|
[TestFixture]
|
|
[Parallelizable(ParallelScope.All)]
|
|
public class SonarrReleaseProfileCompatibilityHandlerTest
|
|
{
|
|
private class TestContext : IDisposable
|
|
{
|
|
private readonly JsonSerializerSettings _jsonSettings;
|
|
|
|
public TestContext()
|
|
{
|
|
_jsonSettings = new JsonSerializerSettings
|
|
{
|
|
ContractResolver = new CamelCasePropertyNamesContractResolver()
|
|
};
|
|
|
|
Mapper = AutoMapperConfig.Setup();
|
|
}
|
|
|
|
public IMapper Mapper { get; }
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
|
|
public string SerializeJson<T>(T obj)
|
|
{
|
|
return JsonConvert.SerializeObject(obj, _jsonSettings);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void Receive_v1_to_v2()
|
|
{
|
|
using var ctx = new TestContext();
|
|
|
|
var compat = Substitute.For<ISonarrCompatibility>();
|
|
var dataV1 = new SonarrReleaseProfileV1 {Ignored = "one,two,three"};
|
|
var sut = new SonarrReleaseProfileCompatibilityHandler(compat, ctx.Mapper);
|
|
|
|
var result = sut.CompatibleReleaseProfileForReceiving(JObject.Parse(ctx.SerializeJson(dataV1)));
|
|
|
|
_ = compat.DidNotReceive().ArraysNeededForReleaseProfileRequiredAndIgnored;
|
|
result.Should().BeEquivalentTo(new SonarrReleaseProfile
|
|
{
|
|
Ignored = new List<string> {"one", "two", "three"}
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void Receive_v2_to_v2()
|
|
{
|
|
using var ctx = new TestContext();
|
|
|
|
var compat = Substitute.For<ISonarrCompatibility>();
|
|
var dataV2 = new SonarrReleaseProfile {Ignored = new List<string> {"one", "two", "three"}};
|
|
var sut = new SonarrReleaseProfileCompatibilityHandler(compat, ctx.Mapper);
|
|
|
|
var result = sut.CompatibleReleaseProfileForReceiving(JObject.Parse(ctx.SerializeJson(dataV2)));
|
|
|
|
_ = compat.DidNotReceive().ArraysNeededForReleaseProfileRequiredAndIgnored;
|
|
result.Should().BeEquivalentTo(dataV2);
|
|
}
|
|
|
|
[Test]
|
|
public void Send_v2_to_v1()
|
|
{
|
|
using var ctx = new TestContext();
|
|
|
|
var compat = Substitute.For<ISonarrCompatibility>();
|
|
compat.ArraysNeededForReleaseProfileRequiredAndIgnored.Returns(false);
|
|
|
|
var data = new SonarrReleaseProfile {Ignored = new List<string> {"one", "two", "three"}};
|
|
var sut = new SonarrReleaseProfileCompatibilityHandler(compat, ctx.Mapper);
|
|
|
|
var result = sut.CompatibleReleaseProfileForSending(data);
|
|
|
|
result.Should().BeEquivalentTo(new SonarrReleaseProfileV1 {Ignored = "one,two,three"});
|
|
}
|
|
|
|
[Test]
|
|
public void Send_v2_to_v2()
|
|
{
|
|
using var ctx = new TestContext();
|
|
|
|
var compat = Substitute.For<ISonarrCompatibility>();
|
|
compat.ArraysNeededForReleaseProfileRequiredAndIgnored.Returns(true);
|
|
|
|
var data = new SonarrReleaseProfile {Ignored = new List<string> {"one", "two", "three"}};
|
|
var sut = new SonarrReleaseProfileCompatibilityHandler(compat, ctx.Mapper);
|
|
|
|
var result = sut.CompatibleReleaseProfileForSending(data);
|
|
|
|
result.Should().BeEquivalentTo(data);
|
|
}
|
|
}
|
|
}
|