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.
74 lines
2.3 KiB
74 lines
2.3 KiB
2 years ago
|
using System.IO.Abstractions;
|
||
|
using Recyclarr.Cli.Console.Settings;
|
||
|
using Recyclarr.Cli.Processors.Config;
|
||
1 year ago
|
using Recyclarr.Platform;
|
||
|
using Recyclarr.TrashGuide;
|
||
2 years ago
|
|
||
|
namespace Recyclarr.Cli.Tests.Processors.Config;
|
||
|
|
||
|
[TestFixture]
|
||
1 year ago
|
public class TemplateConfigCreatorTest
|
||
2 years ago
|
{
|
||
|
[Test, AutoMockData]
|
||
|
public void Can_handle_returns_true_with_templates(
|
||
|
ICreateConfigSettings settings,
|
||
|
TemplateConfigCreator sut)
|
||
|
{
|
||
|
settings.Templates.Returns(new[] {"template1"});
|
||
|
var result = sut.CanHandle(settings);
|
||
|
result.Should().Be(true);
|
||
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Can_handle_returns_false_with_no_templates(
|
||
|
ICreateConfigSettings settings,
|
||
|
TemplateConfigCreator sut)
|
||
|
{
|
||
|
settings.Templates.Returns(Array.Empty<string>());
|
||
|
var result = sut.CanHandle(settings);
|
||
|
result.Should().Be(false);
|
||
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
1 year ago
|
public void No_replace_when_file_exists_and_not_forced(
|
||
2 years ago
|
[Frozen] IConfigTemplateGuideService templates,
|
||
1 year ago
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
|
[Frozen] IAppPaths paths,
|
||
2 years ago
|
ICreateConfigSettings settings,
|
||
|
TemplateConfigCreator sut)
|
||
|
{
|
||
1 year ago
|
var templateFile = fs.CurrentDirectory().File("template-file1.yml");
|
||
|
var destFile = paths.ConfigsDirectory.File(templateFile.Name);
|
||
|
|
||
|
fs.AddFile(templateFile, new MockFileData("a"));
|
||
|
fs.AddFile(destFile, new MockFileData("b"));
|
||
2 years ago
|
|
||
|
settings.Force.Returns(false);
|
||
1 year ago
|
settings.Path.Returns(templateFile.FullName);
|
||
2 years ago
|
|
||
1 year ago
|
sut.Create(settings);
|
||
2 years ago
|
|
||
1 year ago
|
fs.GetFile(destFile).TextContents.Should().Be("b");
|
||
2 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
1 year ago
|
public void No_throw_when_file_exists_and_forced(
|
||
2 years ago
|
[Frozen] IConfigTemplateGuideService templates,
|
||
1 year ago
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
|
[Frozen] IAppPaths paths,
|
||
2 years ago
|
ICreateConfigSettings settings,
|
||
|
TemplateConfigCreator sut)
|
||
|
{
|
||
1 year ago
|
var templateFile = fs.CurrentDirectory().File("template-file1.yml");
|
||
|
fs.AddEmptyFile(templateFile);
|
||
|
fs.AddEmptyFile(paths.ConfigsDirectory.File(templateFile.Name));
|
||
2 years ago
|
|
||
|
settings.Force.Returns(true);
|
||
1 year ago
|
settings.Path.Returns(templateFile.FullName);
|
||
2 years ago
|
|
||
|
var act = () => sut.Create(settings);
|
||
|
|
||
1 year ago
|
act.Should().NotThrow();
|
||
2 years ago
|
}
|
||
|
}
|