@@ -22,18 +22,28 @@ public sealed class AggregatedConfigurationTests
2222 [ DataRow ( PlatformConfigurationConstants . PlatformResultDirectory ) ]
2323 [ DataRow ( PlatformConfigurationConstants . PlatformCurrentWorkingDirectory ) ]
2424 [ DataRow ( PlatformConfigurationConstants . PlatformTestHostWorkingDirectory ) ]
25- public void IndexerTest_DirectoryNotSetAndNoConfigurationProviders_DirectoryIsNull ( string key )
26- => Assert . IsNull ( new AggregatedConfiguration ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) [ key ] ) ;
25+ public void IndexerTest_DirectoryNotSetAndNoConfigurationProviders ( string key )
26+ {
27+ _testApplicationModuleInfoMock . Setup ( x => x . GetCurrentTestApplicationFullPath ( ) ) . Returns ( "TestAppDir/test.exe" ) ;
28+ string ? expected = key switch
29+ {
30+ PlatformConfigurationConstants . PlatformResultDirectory => Path . Combine ( "TestAppDir" , "TestResults" ) ,
31+ PlatformConfigurationConstants . PlatformCurrentWorkingDirectory => "TestAppDir" ,
32+ PlatformConfigurationConstants . PlatformTestHostWorkingDirectory => null ,
33+ _ => throw ApplicationStateGuard . Unreachable ( ) ,
34+ } ;
35+
36+ Assert . AreEqual ( expected , new AggregatedConfiguration ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) [ key ] ) ;
37+ }
2738
2839 [ TestMethod ]
29- [ DataRow ( PlatformConfigurationConstants . PlatformResultDirectory ) ]
3040 [ DataRow ( PlatformConfigurationConstants . PlatformCurrentWorkingDirectory ) ]
3141 [ DataRow ( PlatformConfigurationConstants . PlatformTestHostWorkingDirectory ) ]
3242 public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_DirectoryIsNull ( string key )
3343 {
3444 Mock < IConfigurationProvider > mockProvider = new ( ) ;
3545
36- AggregatedConfiguration aggregatedConfiguration = new ( [ mockProvider . Object ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
46+ AggregatedConfiguration aggregatedConfiguration = new ( [ mockProvider . Object ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
3747 Assert . IsNull ( aggregatedConfiguration [ key ] ) ;
3848 }
3949
@@ -43,23 +53,21 @@ public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_Director
4353 [ DataRow ( PlatformConfigurationConstants . PlatformTestHostWorkingDirectory ) ]
4454 public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_DirectoryIsNotNull ( string key )
4555 {
46- AggregatedConfiguration aggregatedConfiguration = new ( [ new FakeConfigurationProvider ( ExpectedPath ) ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
56+ AggregatedConfiguration aggregatedConfiguration = new ( [ new FakeConfigurationProvider ( ExpectedPath ) ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
4757 Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ key ] ) ;
4858 }
4959
5060 [ TestMethod ]
5161 public void IndexerTest_ResultDirectorySet_DirectoryIsNotNull ( )
5262 {
53- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
54-
55- aggregatedConfiguration . SetResultDirectory ( ExpectedPath ) ;
63+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ new CommandLineParseOption ( "results-directory" , [ ExpectedPath ] ) ] , [ ] ) ) ;
5664 Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ PlatformConfigurationConstants . PlatformResultDirectory ] ) ;
5765 }
5866
5967 [ TestMethod ]
6068 public void IndexerTest_CurrentWorkingDirectorySet_DirectoryIsNotNull ( )
6169 {
62- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
70+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
6371
6472 aggregatedConfiguration . SetCurrentWorkingDirectory ( ExpectedPath ) ;
6573 Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ PlatformConfigurationConstants . PlatformCurrentWorkingDirectory ] ) ;
@@ -68,7 +76,7 @@ public void IndexerTest_CurrentWorkingDirectorySet_DirectoryIsNotNull()
6876 [ TestMethod ]
6977 public void IndexerTest_TestHostWorkingDirectorySet_DirectoryIsNotNull ( )
7078 {
71- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
79+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
7280
7381 aggregatedConfiguration . SetTestHostWorkingDirectory ( ExpectedPath ) ;
7482 Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ PlatformConfigurationConstants . PlatformTestHostWorkingDirectory ] ) ;
@@ -86,9 +94,8 @@ public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_Results
8694 Mock < IFileLoggerProvider > mockFileLogger = new ( ) ;
8795 mockFileLogger . Setup ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( It . IsAny < string > ( ) ) ) . Callback ( ( ) => { } ) ;
8896
89- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , mockTestApplicationModuleInfo . Object , mockFileSystem . Object ) ;
90- await aggregatedConfiguration . CheckTestResultsDirectoryOverrideAndCreateItAsync (
91- new FakeCommandLineOptions ( ExpectedPath ) , mockFileLogger . Object ) ;
97+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , mockTestApplicationModuleInfo . Object , mockFileSystem . Object , new ( null , [ new CommandLineParseOption ( "results-directory" , [ ExpectedPath ] ) ] , [ ] ) ) ;
98+ await aggregatedConfiguration . CheckTestResultsDirectoryOverrideAndCreateItAsync ( mockFileLogger . Object ) ;
9299
93100 mockFileSystem . Verify ( x => x . CreateDirectory ( ExpectedPath ) , Times . Once ) ;
94101 mockFileLogger . Verify ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( ExpectedPath ) , Times . Once ) ;
@@ -108,9 +115,8 @@ public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_Results
108115 Mock < IFileLoggerProvider > mockFileLogger = new ( ) ;
109116 mockFileLogger . Setup ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( It . IsAny < string > ( ) ) ) . Callback ( ( ) => { } ) ;
110117
111- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , mockTestApplicationModuleInfo . Object , mockFileSystem . Object ) ;
112- aggregatedConfiguration . SetResultDirectory ( ExpectedPath ) ;
113- await aggregatedConfiguration . CheckTestResultsDirectoryOverrideAndCreateItAsync ( new FakeCommandLineOptions ( ExpectedPath ) , mockFileLogger . Object ) ;
118+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , mockTestApplicationModuleInfo . Object , mockFileSystem . Object , new ( null , [ new CommandLineParseOption ( "results-directory" , [ ExpectedPath ] ) ] , [ ] ) ) ;
119+ await aggregatedConfiguration . CheckTestResultsDirectoryOverrideAndCreateItAsync ( mockFileLogger . Object ) ;
114120
115121 mockFileSystem . Verify ( x => x . CreateDirectory ( ExpectedPath ) , Times . Once ) ;
116122 mockFileLogger . Verify ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( ExpectedPath ) , Times . Once ) ;
@@ -130,9 +136,8 @@ public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_Results
130136 Mock < IFileLoggerProvider > mockFileLogger = new ( ) ;
131137 mockFileLogger . Setup ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( It . IsAny < string > ( ) ) ) . Callback ( ( ) => { } ) ;
132138
133- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , mockTestApplicationModuleInfo . Object , mockFileSystem . Object ) ;
134- await aggregatedConfiguration . CheckTestResultsDirectoryOverrideAndCreateItAsync (
135- new FakeCommandLineOptions ( ExpectedPath , bypass : true ) , mockFileLogger . Object ) ;
139+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , mockTestApplicationModuleInfo . Object , mockFileSystem . Object , new ( null , [ ] , [ ] ) ) ;
140+ await aggregatedConfiguration . CheckTestResultsDirectoryOverrideAndCreateItAsync ( mockFileLogger . Object ) ;
136141
137142 string expectedPath = "a" + Path . DirectorySeparatorChar + "b" + Path . DirectorySeparatorChar + "TestResults" ;
138143 mockFileSystem . Verify ( x => x . CreateDirectory ( expectedPath ) , Times . Once ) ;
@@ -166,35 +171,3 @@ public bool TryGet(string key, out string? value)
166171 }
167172 }
168173}
169-
170- internal sealed class FakeCommandLineOptions : ICommandLineOptions
171- {
172- private readonly string _path ;
173- private readonly bool _bypass ;
174-
175- public FakeCommandLineOptions ( string path , bool bypass = false )
176- {
177- _path = path ;
178- _bypass = bypass ;
179- }
180-
181- public bool IsOptionSet ( string optionName ) => throw new NotImplementedException ( ) ;
182-
183- public bool TryGetOptionArgumentList ( string optionName , [ NotNullWhen ( true ) ] out string [ ] ? arguments )
184- {
185- arguments = null ;
186- if ( _bypass )
187- {
188- return false ;
189- }
190-
191- switch ( optionName )
192- {
193- case PlatformCommandLineProvider . ResultDirectoryOptionKey :
194- arguments = [ _path ] ;
195- return true ;
196- default :
197- return false ;
198- }
199- }
200- }
0 commit comments