@@ -22,18 +22,28 @@ public sealed class AggregatedConfigurationTests
22
22
[ DataRow ( PlatformConfigurationConstants . PlatformResultDirectory ) ]
23
23
[ DataRow ( PlatformConfigurationConstants . PlatformCurrentWorkingDirectory ) ]
24
24
[ 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
+ }
27
38
28
39
[ TestMethod ]
29
- [ DataRow ( PlatformConfigurationConstants . PlatformResultDirectory ) ]
30
40
[ DataRow ( PlatformConfigurationConstants . PlatformCurrentWorkingDirectory ) ]
31
41
[ DataRow ( PlatformConfigurationConstants . PlatformTestHostWorkingDirectory ) ]
32
42
public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_DirectoryIsNull ( string key )
33
43
{
34
44
Mock < IConfigurationProvider > mockProvider = new ( ) ;
35
45
36
- AggregatedConfiguration aggregatedConfiguration = new ( [ mockProvider . Object ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
46
+ AggregatedConfiguration aggregatedConfiguration = new ( [ mockProvider . Object ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
37
47
Assert . IsNull ( aggregatedConfiguration [ key ] ) ;
38
48
}
39
49
@@ -43,23 +53,21 @@ public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_Director
43
53
[ DataRow ( PlatformConfigurationConstants . PlatformTestHostWorkingDirectory ) ]
44
54
public void IndexerTest_DirectoryNotSetButConfigurationProvidersPresent_DirectoryIsNotNull ( string key )
45
55
{
46
- AggregatedConfiguration aggregatedConfiguration = new ( [ new FakeConfigurationProvider ( ExpectedPath ) ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
56
+ AggregatedConfiguration aggregatedConfiguration = new ( [ new FakeConfigurationProvider ( ExpectedPath ) ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
47
57
Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ key ] ) ;
48
58
}
49
59
50
60
[ TestMethod ]
51
61
public void IndexerTest_ResultDirectorySet_DirectoryIsNotNull ( )
52
62
{
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 ] ) ] , [ ] ) ) ;
56
64
Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ PlatformConfigurationConstants . PlatformResultDirectory ] ) ;
57
65
}
58
66
59
67
[ TestMethod ]
60
68
public void IndexerTest_CurrentWorkingDirectorySet_DirectoryIsNotNull ( )
61
69
{
62
- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
70
+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
63
71
64
72
aggregatedConfiguration . SetCurrentWorkingDirectory ( ExpectedPath ) ;
65
73
Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ PlatformConfigurationConstants . PlatformCurrentWorkingDirectory ] ) ;
@@ -68,7 +76,7 @@ public void IndexerTest_CurrentWorkingDirectorySet_DirectoryIsNotNull()
68
76
[ TestMethod ]
69
77
public void IndexerTest_TestHostWorkingDirectorySet_DirectoryIsNotNull ( )
70
78
{
71
- AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object ) ;
79
+ AggregatedConfiguration aggregatedConfiguration = new ( [ ] , _testApplicationModuleInfoMock . Object , _fileSystemMock . Object , new ( null , [ ] , [ ] ) ) ;
72
80
73
81
aggregatedConfiguration . SetTestHostWorkingDirectory ( ExpectedPath ) ;
74
82
Assert . AreEqual ( ExpectedPath , aggregatedConfiguration [ PlatformConfigurationConstants . PlatformTestHostWorkingDirectory ] ) ;
@@ -86,9 +94,8 @@ public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_Results
86
94
Mock < IFileLoggerProvider > mockFileLogger = new ( ) ;
87
95
mockFileLogger . Setup ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( It . IsAny < string > ( ) ) ) . Callback ( ( ) => { } ) ;
88
96
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 ) ;
92
99
93
100
mockFileSystem . Verify ( x => x . CreateDirectory ( ExpectedPath ) , Times . Once ) ;
94
101
mockFileLogger . Verify ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( ExpectedPath ) , Times . Once ) ;
@@ -108,9 +115,8 @@ public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_Results
108
115
Mock < IFileLoggerProvider > mockFileLogger = new ( ) ;
109
116
mockFileLogger . Setup ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( It . IsAny < string > ( ) ) ) . Callback ( ( ) => { } ) ;
110
117
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 ) ;
114
120
115
121
mockFileSystem . Verify ( x => x . CreateDirectory ( ExpectedPath ) , Times . Once ) ;
116
122
mockFileLogger . Verify ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( ExpectedPath ) , Times . Once ) ;
@@ -130,9 +136,8 @@ public async ValueTask CheckTestResultsDirectoryOverrideAndCreateItAsync_Results
130
136
Mock < IFileLoggerProvider > mockFileLogger = new ( ) ;
131
137
mockFileLogger . Setup ( x => x . CheckLogFolderAndMoveToTheNewIfNeededAsync ( It . IsAny < string > ( ) ) ) . Callback ( ( ) => { } ) ;
132
138
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 ) ;
136
141
137
142
string expectedPath = "a" + Path . DirectorySeparatorChar + "b" + Path . DirectorySeparatorChar + "TestResults" ;
138
143
mockFileSystem . Verify ( x => x . CreateDirectory ( expectedPath ) , Times . Once ) ;
@@ -166,35 +171,3 @@ public bool TryGet(string key, out string? value)
166
171
}
167
172
}
168
173
}
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