@ -1,3 +1,5 @@
using System.IO.Abstractions ;
using System.IO.Abstractions.Extensions ;
using System.IO.Abstractions.TestingHelpers ;
using AutoFixture.NUnit3 ;
using Common ;
@ -22,6 +24,8 @@ public class DefaultAppDataSetupTest
[Frozen] IAppPaths paths ,
DefaultAppDataSetup sut )
{
env . GetEnvironmentVariable ( default ! ) . ReturnsForAnyArgs ( ( string? ) null ) ;
paths . DefaultAppDataDirectoryName . Returns ( "app_data" ) ;
env . GetFolderPath ( Arg . Any < Environment . SpecialFolder > ( ) , Arg . Any < Environment . SpecialFolderOption > ( ) )
. Returns ( FileUtils . NormalizePath ( "base/path" ) ) ;
@ -49,6 +53,8 @@ public class DefaultAppDataSetupTest
[Frozen] IEnvironment env ,
DefaultAppDataSetup sut )
{
env . GetEnvironmentVariable ( default ! ) . ReturnsForAnyArgs ( ( string? ) null ) ;
sut . SetupDefaultPath ( null , false ) ;
env . Received ( ) . GetFolderPath ( Environment . SpecialFolder . ApplicationData , Environment . SpecialFolderOption . None ) ;
@ -59,8 +65,46 @@ public class DefaultAppDataSetupTest
[Frozen] IEnvironment env ,
DefaultAppDataSetup sut )
{
env . GetEnvironmentVariable ( default ! ) . ReturnsForAnyArgs ( ( string? ) null ) ;
sut . SetupDefaultPath ( null , true ) ;
env . Received ( ) . GetFolderPath ( Environment . SpecialFolder . ApplicationData , Environment . SpecialFolderOption . Create ) ;
}
[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 ) ;
sut . SetupDefaultPath ( null , true ) ;
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 ;
sut . SetupDefaultPath ( expectedPath , true ) ;
env . DidNotReceiveWithAnyArgs ( ) . GetEnvironmentVariable ( default ! ) ;
fs . AllDirectories . Should ( ) . Contain ( expectedPath ) ;
}
}