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.
86 lines
2.6 KiB
86 lines
2.6 KiB
3 years ago
|
using System.IO.Abstractions;
|
||
1 year ago
|
using Recyclarr.Json;
|
||
1 year ago
|
using Recyclarr.Repo;
|
||
2 years ago
|
using Recyclarr.TestLibrary;
|
||
1 year ago
|
using Recyclarr.TrashGuide.ReleaseProfile;
|
||
3 years ago
|
|
||
1 year ago
|
namespace Recyclarr.Tests.TrashGuide.ReleaseProfile;
|
||
3 years ago
|
|
||
|
[TestFixture]
|
||
2 years ago
|
public class ReleaseProfileGuideServiceTest
|
||
3 years ago
|
{
|
||
|
[Test, AutoMockData]
|
||
2 years ago
|
public void Get_release_profile_json_works(
|
||
3 years ago
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
2 years ago
|
[Frozen] IRepoMetadataBuilder metadataBuilder,
|
||
|
ReleaseProfileGuideService sut)
|
||
3 years ago
|
{
|
||
2 years ago
|
static ReleaseProfileData MakeMockObject(string term)
|
||
3 years ago
|
{
|
||
2 years ago
|
return new ReleaseProfileData
|
||
3 years ago
|
{
|
||
2 years ago
|
Name = "name",
|
||
|
TrashId = "123",
|
||
|
Required = new TermData[]
|
||
|
{
|
||
|
new() {Term = term}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
3 years ago
|
var mockData1 = MakeMockObject("first");
|
||
|
var mockData2 = MakeMockObject("second");
|
||
2 years ago
|
var baseDir = fs.CurrentDirectory().SubDirectory("files");
|
||
|
baseDir.Create();
|
||
3 years ago
|
|
||
1 year ago
|
fs.AddFile(baseDir.File("first.json").FullName,
|
||
|
MockData.FromJson(mockData1, GlobalJsonSerializerSettings.Services));
|
||
|
|
||
|
fs.AddFile(baseDir.File("second.json").FullName,
|
||
|
MockData.FromJson(mockData2, GlobalJsonSerializerSettings.Services));
|
||
3 years ago
|
|
||
2 years ago
|
metadataBuilder.ToDirectoryInfoList(default!).ReturnsForAnyArgs(new[] {baseDir});
|
||
2 years ago
|
|
||
3 years ago
|
var results = sut.GetReleaseProfileData();
|
||
|
|
||
|
results.Should().BeEquivalentTo(new[]
|
||
|
{
|
||
|
mockData1,
|
||
|
mockData2
|
||
|
});
|
||
|
}
|
||
3 years ago
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Json_exceptions_do_not_interrupt_parsing_other_files(
|
||
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
2 years ago
|
[Frozen] IRepoMetadataBuilder metadataBuilder,
|
||
|
ReleaseProfileGuideService sut)
|
||
3 years ago
|
{
|
||
2 years ago
|
var rootPath = fs.CurrentDirectory().SubDirectory("files");
|
||
|
rootPath.Create();
|
||
3 years ago
|
|
||
|
var badData = "# comment";
|
||
|
var goodData = new ReleaseProfileData
|
||
|
{
|
||
|
Name = "name",
|
||
|
TrashId = "123",
|
||
|
Required = new TermData[]
|
||
|
{
|
||
|
new() {Term = "abc"}
|
||
|
}
|
||
|
};
|
||
|
|
||
1 year ago
|
fs.AddFile(rootPath.File("0_bad_data.json").FullName,
|
||
|
MockData.FromString(badData));
|
||
|
|
||
|
fs.AddFile(rootPath.File("1_good_data.json").FullName,
|
||
|
MockData.FromJson(goodData, GlobalJsonSerializerSettings.Services));
|
||
3 years ago
|
|
||
2 years ago
|
metadataBuilder.ToDirectoryInfoList(default!).ReturnsForAnyArgs(new[] {rootPath});
|
||
2 years ago
|
|
||
3 years ago
|
var results = sut.GetReleaseProfileData();
|
||
|
|
||
|
results.Should().BeEquivalentTo(new[] {goodData});
|
||
|
}
|
||
3 years ago
|
}
|