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.
118 lines
3.9 KiB
118 lines
3.9 KiB
3 years ago
|
using System.IO.Abstractions;
|
||
2 years ago
|
using Recyclarr.Common;
|
||
1 year ago
|
using Recyclarr.Platform;
|
||
3 years ago
|
|
||
1 year ago
|
namespace Recyclarr.Tests.Platform;
|
||
3 years ago
|
|
||
|
[TestFixture]
|
||
|
[Parallelizable(ParallelScope.All)]
|
||
|
public class DefaultAppDataSetupTest
|
||
|
{
|
||
|
[Test, AutoMockData]
|
||
|
public void Initialize_using_default_path(
|
||
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
|
[Frozen] IEnvironment env,
|
||
|
DefaultAppDataSetup sut)
|
||
|
{
|
||
3 years ago
|
env.GetEnvironmentVariable(default!).ReturnsForAnyArgs((string?) null);
|
||
|
|
||
3 years ago
|
var basePath = fs.CurrentDirectory()
|
||
|
.SubDirectory("base")
|
||
|
.SubDirectory("path");
|
||
3 years ago
|
|
||
3 years ago
|
env.GetFolderPath(default, default).ReturnsForAnyArgs(basePath.FullName);
|
||
3 years ago
|
|
||
3 years ago
|
var paths = sut.CreateAppPaths();
|
||
|
|
||
|
paths.AppDataDirectory.FullName.Should().Be(basePath.SubDirectory("recyclarr").FullName);
|
||
3 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Initialize_using_path_override(
|
||
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
|
DefaultAppDataSetup sut)
|
||
|
{
|
||
3 years ago
|
var overridePath = fs.CurrentDirectory()
|
||
|
.SubDirectory("override")
|
||
|
.SubDirectory("path");
|
||
|
|
||
|
var paths = sut.CreateAppPaths(overridePath.FullName);
|
||
3 years ago
|
|
||
3 years ago
|
paths.AppDataDirectory.FullName.Should().Be(overridePath.FullName);
|
||
3 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Force_creation_uses_correct_behavior_when_disabled(
|
||
3 years ago
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
3 years ago
|
[Frozen] IEnvironment env,
|
||
|
DefaultAppDataSetup sut)
|
||
|
{
|
||
3 years ago
|
var overridePath = fs.CurrentDirectory()
|
||
|
.SubDirectory("override")
|
||
|
.SubDirectory("path");
|
||
|
|
||
3 years ago
|
env.GetEnvironmentVariable(default!).ReturnsForAnyArgs((string?) null);
|
||
3 years ago
|
env.GetFolderPath(default).ReturnsForAnyArgs(overridePath.FullName);
|
||
3 years ago
|
|
||
3 years ago
|
sut.CreateAppPaths(null, false);
|
||
3 years ago
|
|
||
|
env.Received().GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.None);
|
||
3 years ago
|
fs.AllDirectories.Should().NotContain(overridePath.FullName);
|
||
3 years ago
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Force_creation_uses_correct_behavior_when_enabled(
|
||
3 years ago
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
3 years ago
|
[Frozen] IEnvironment env,
|
||
|
DefaultAppDataSetup sut)
|
||
|
{
|
||
3 years ago
|
var overridePath = fs.CurrentDirectory()
|
||
|
.SubDirectory("override")
|
||
|
.SubDirectory("path");
|
||
|
|
||
3 years ago
|
env.GetEnvironmentVariable(default!).ReturnsForAnyArgs((string?) null);
|
||
3 years ago
|
env.GetFolderPath(default).ReturnsForAnyArgs(overridePath.FullName);
|
||
3 years ago
|
|
||
3 years ago
|
sut.CreateAppPaths();
|
||
3 years ago
|
|
||
|
env.Received().GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create);
|
||
3 years ago
|
fs.AllDirectories.Should().NotContain(overridePath.FullName);
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Use_environment_variable_if_override_not_specified(
|
||
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
|
[Frozen] IEnvironment env,
|
||
|
DefaultAppDataSetup sut)
|
||
|
{
|
||
|
var expectedPath = fs.CurrentDirectory()
|
||
|
.SubDirectory("env")
|
||
|
.SubDirectory("var")
|
||
|
.SubDirectory("path").FullName;
|
||
|
|
||
|
env.GetEnvironmentVariable(default!).ReturnsForAnyArgs(expectedPath);
|
||
|
|
||
3 years ago
|
sut.CreateAppPaths();
|
||
3 years ago
|
|
||
|
env.Received().GetEnvironmentVariable("RECYCLARR_APP_DATA");
|
||
|
fs.AllDirectories.Should().Contain(expectedPath);
|
||
|
}
|
||
|
|
||
|
[Test, AutoMockData]
|
||
|
public void Explicit_override_takes_precedence_over_environment_variable(
|
||
|
[Frozen(Matching.ImplementedInterfaces)] MockFileSystem fs,
|
||
|
[Frozen] IEnvironment env,
|
||
|
DefaultAppDataSetup sut)
|
||
|
{
|
||
|
var expectedPath = fs.CurrentDirectory()
|
||
|
.SubDirectory("env")
|
||
|
.SubDirectory("var")
|
||
|
.SubDirectory("path").FullName;
|
||
|
|
||
3 years ago
|
sut.CreateAppPaths(expectedPath);
|
||
3 years ago
|
|
||
|
env.DidNotReceiveWithAnyArgs().GetEnvironmentVariable(default!);
|
||
|
fs.AllDirectories.Should().Contain(expectedPath);
|
||
|
}
|
||
3 years ago
|
}
|