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.
57 lines
1.9 KiB
57 lines
1.9 KiB
2 years ago
|
using System.IO.Abstractions;
|
||
1 year ago
|
using System.Text.Json;
|
||
1 year ago
|
using Autofac;
|
||
|
using Recyclarr.TestLibrary.Autofac;
|
||
1 year ago
|
using Recyclarr.Tests.TestLibrary;
|
||
1 year ago
|
using Recyclarr.TrashGuide.CustomFormat;
|
||
2 years ago
|
|
||
1 year ago
|
namespace Recyclarr.IntegrationTests;
|
||
2 years ago
|
|
||
|
[TestFixture]
|
||
1 year ago
|
public class CustomFormatLoaderIntegrationTest : IntegrationTestFixture
|
||
2 years ago
|
{
|
||
1 year ago
|
protected override void RegisterStubsAndMocks(ContainerBuilder builder)
|
||
|
{
|
||
|
base.RegisterStubsAndMocks(builder);
|
||
|
builder.RegisterMockFor<ICustomFormatCategoryParser>();
|
||
|
}
|
||
|
|
||
2 years ago
|
[Test]
|
||
|
public void Get_custom_format_json_works()
|
||
|
{
|
||
1 year ago
|
var sut = Resolve<CustomFormatLoader>();
|
||
1 year ago
|
Fs.AddFile("first.json", new MockFileData("""{"name":"first","trash_id":"1"}"""));
|
||
|
Fs.AddFile("second.json", new MockFileData("""{"name":"second","trash_id":"2"}"""));
|
||
2 years ago
|
Fs.AddFile("collection_of_cfs.md", new MockFileData(""));
|
||
2 years ago
|
|
||
2 years ago
|
var dir = Fs.CurrentDirectory();
|
||
|
var results = sut.LoadAllCustomFormatsAtPaths(new[] {dir}, dir.File("collection_of_cfs.md"));
|
||
2 years ago
|
|
||
|
results.Should().BeEquivalentTo(new[]
|
||
|
{
|
||
1 year ago
|
NewCf.Data("first", "1"),
|
||
|
NewCf.Data("second", "2")
|
||
1 year ago
|
}, o => o.Excluding(x => x.Type == typeof(JsonElement)));
|
||
2 years ago
|
}
|
||
1 year ago
|
|
||
|
[Test]
|
||
|
public void Categorize_by_file_name()
|
||
|
{
|
||
|
var categoryParser = Resolve<ICustomFormatCategoryParser>();
|
||
|
categoryParser.Parse(default!).ReturnsForAnyArgs(new[]
|
||
|
{
|
||
|
new CustomFormatCategoryItem("Streaming Services", "iTunes", "iT")
|
||
|
});
|
||
|
|
||
|
Fs.AddFile("it.json", new MockFileData("""{"name":"iT"}"""));
|
||
|
Fs.AddEmptyFile("collection_of_cfs.md");
|
||
|
|
||
|
var sut = Resolve<CustomFormatLoader>();
|
||
|
|
||
|
var dir = Fs.CurrentDirectory();
|
||
|
var results = sut.LoadAllCustomFormatsAtPaths(new[] {dir}, dir.File("collection_of_cfs.md"));
|
||
|
|
||
|
results.Should().ContainSingle().Which.Category.Should().Be("Streaming Services");
|
||
|
}
|
||
2 years ago
|
}
|