1- public class OpenCommandTests
1+ using Microsoft . Extensions . DependencyInjection ;
2+ using Spectre . Console . Cli . Testing ;
3+ using Xunit . Abstractions ;
4+
5+ public class OpenCommandTests ( ITestOutputHelper output )
26{
37 [ Fact ]
48 public async Task WaitForFileAsyncFindsExistingFile ( )
59 {
6- await CreateTempProject ( async tempDir =>
10+ await TestUtil . WithinTempDirectoryAsync ( async tempDir =>
711 {
8- string testFile = Path . Combine ( tempDir , "test.sln" ) ;
12+ string testFile = Path . Combine ( tempDir . FullName , "test.sln" ) ;
913 await File . WriteAllTextAsync ( testFile , "content" ) ;
1014
11- string result = await OpenCommand . WaitForFileAsync ( tempDir , "*.sln" ) ;
15+ string result = await OpenCommand . WaitForFileAsync ( tempDir . FullName , "*.sln" ) ;
1216
1317 Assert . Equal ( testFile , result ) ;
1418 } ) ;
@@ -17,11 +21,11 @@ await CreateTempProject(async tempDir =>
1721 [ Fact ]
1822 public async Task WaitForFileAsyncWaitsForNewFile ( )
1923 {
20- await CreateTempProject ( async tempDir =>
24+ await TestUtil . WithinTempDirectoryAsync ( async tempDir =>
2125 {
22- string testFile = Path . Combine ( tempDir , "delayed.sln" ) ;
26+ string testFile = Path . Combine ( tempDir . FullName , "delayed.sln" ) ;
2327
24- Task < string > waitTask = OpenCommand . WaitForFileAsync ( tempDir , "*.sln" ) ;
28+ Task < string > waitTask = OpenCommand . WaitForFileAsync ( tempDir . FullName , "*.sln" ) ;
2529
2630 // Simulate Unity project generating the solution file.
2731 await Task . Delay ( 100 ) ;
@@ -33,18 +37,24 @@ await CreateTempProject(async tempDir =>
3337 } ) ;
3438 }
3539
36- private static async Task CreateTempProject ( Func < string , Task > action )
40+ [ Fact ]
41+ public void Open_DirectPath ( )
3742 {
38- string tempDir = Path . Combine ( Path . GetTempPath ( ) , Guid . NewGuid ( ) . ToString ( ) ) ;
39- Directory . CreateDirectory ( tempDir ) ;
43+ var services = new ServiceCollection ( ) ;
44+ services . AddSingleton ( PlatformSupport . Create ( ) ) ;
45+ services . AddSingleton < UnityHub > ( ) ;
4046
41- try
42- {
43- await action . Invoke ( tempDir ) ;
44- }
45- finally
47+ var registrar = new TypeRegistrar ( services ) ;
48+ var app = new CommandAppTester ( registrar ) ;
49+ app . Configure ( AppConfiguration . Build ) ;
50+
51+ TestUtil . WithinTempDirectory ( tempDir =>
4652 {
47- Directory . Delete ( tempDir , recursive : true ) ;
48- }
53+ string projectPath = Path . Combine ( tempDir . FullName , "MyTestProject" ) ;
54+ app . Run ( "create" , projectPath , "6000.0.64f1" , "--minimal" ) ;
55+ var result = app . Run ( "open" , projectPath , "--dry-run" ) ;
56+ output . WriteLine ( result . Output ) ;
57+ Assert . Equal ( 0 , result . ExitCode ) ;
58+ } ) ;
4959 }
5060}
0 commit comments