1+ using System ;
12using System . Collections . Generic ;
3+ using GitCredentialManager . Interop . Posix ;
24using GitCredentialManager . Interop . Windows ;
35using GitCredentialManager . Tests . Objects ;
46using Xunit ;
@@ -7,62 +9,116 @@ namespace GitCredentialManager.Tests
79{
810 public class EnvironmentTests
911 {
12+ private const string WindowsPathVar = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows" ;
13+ private const string WindowsExecName = "foo.exe" ;
14+ private const string PosixPathVar = "/home/john.doe/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" ;
15+ private const string PosixExecName = "foo" ;
16+
1017 [ PlatformFact ( Platforms . Windows ) ]
1118 public void WindowsEnvironment_TryLocateExecutable_NotExists_ReturnFalse ( )
1219 {
13- string pathVar = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows" ;
14- string execName = "foo.exe" ;
1520 var fs = new TestFileSystem ( ) ;
16- var envars = new Dictionary < string , string > { [ "PATH" ] = pathVar } ;
21+ var envars = new Dictionary < string , string > { [ "PATH" ] = WindowsPathVar } ;
1722 var env = new WindowsEnvironment ( fs , envars ) ;
1823
19- bool actualResult = env . TryLocateExecutable ( execName , out string actualPath ) ;
24+ bool actualResult = env . TryLocateExecutable ( WindowsExecName , out string actualPath ) ;
2025
2126 Assert . False ( actualResult ) ;
2227 Assert . Null ( actualPath ) ;
2328 }
2429
2530 [ PlatformFact ( Platforms . Windows ) ]
26- public void WindowsEnvironment_TryLocateExecutable_Windows_Exists_ReturnTrueAndPath ( )
31+ public void WindowsEnvironment_TryLocateExecutable_Exists_ReturnTrueAndPath ( )
2732 {
28- string pathVar = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows" ;
29- string execName = "foo.exe" ;
3033 string expectedPath = @"C:\Windows\system32\foo.exe" ;
3134 var fs = new TestFileSystem
3235 {
3336 Files = new Dictionary < string , byte [ ] >
3437 {
35- [ @"C:\Windows\system32\foo.exe" ] = new byte [ 0 ] ,
38+ [ expectedPath ] = Array . Empty < byte > ( )
3639 }
3740 } ;
38- var envars = new Dictionary < string , string > { [ "PATH" ] = pathVar } ;
41+ var envars = new Dictionary < string , string > { [ "PATH" ] = WindowsPathVar } ;
3942 var env = new WindowsEnvironment ( fs , envars ) ;
4043
41- bool actualResult = env . TryLocateExecutable ( execName , out string actualPath ) ;
44+ bool actualResult = env . TryLocateExecutable ( WindowsExecName , out string actualPath ) ;
4245
4346 Assert . True ( actualResult ) ;
4447 Assert . Equal ( expectedPath , actualPath ) ;
4548 }
4649
4750 [ PlatformFact ( Platforms . Windows ) ]
48- public void WindowsEnvironment_TryLocateExecutable_Windows_ExistsMultiple_ReturnTrueAndFirstPath ( )
51+ public void WindowsEnvironment_TryLocateExecutable_ExistsMultiple_ReturnTrueAndFirstPath ( )
4952 {
50- string pathVar = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows" ;
51- string execName = "foo.exe" ;
5253 string expectedPath = @"C:\Users\john.doe\bin\foo.exe" ;
5354 var fs = new TestFileSystem
5455 {
5556 Files = new Dictionary < string , byte [ ] >
5657 {
57- [ @"C:\Users\john.doe\bin\foo.exe" ] = new byte [ 0 ] ,
58- [ @"C:\Windows\system32\foo.exe" ] = new byte [ 0 ] ,
59- [ @"C:\Windows\foo.exe" ] = new byte [ 0 ] ,
58+ [ expectedPath ] = Array . Empty < byte > ( ) ,
59+ [ @"C:\Windows\system32\foo.exe" ] = Array . Empty < byte > ( ) ,
60+ [ @"C:\Windows\foo.exe" ] = Array . Empty < byte > ( ) ,
6061 }
6162 } ;
62- var envars = new Dictionary < string , string > { [ "PATH" ] = pathVar } ;
63+ var envars = new Dictionary < string , string > { [ "PATH" ] = WindowsPathVar } ;
6364 var env = new WindowsEnvironment ( fs , envars ) ;
6465
65- bool actualResult = env . TryLocateExecutable ( execName , out string actualPath ) ;
66+ bool actualResult = env . TryLocateExecutable ( WindowsExecName , out string actualPath ) ;
67+
68+ Assert . True ( actualResult ) ;
69+ Assert . Equal ( expectedPath , actualPath ) ;
70+ }
71+
72+ [ PlatformFact ( Platforms . Posix ) ]
73+ public void PosixEnvironment_TryLocateExecutable_NotExists_ReturnFalse ( )
74+ {
75+ var fs = new TestFileSystem ( ) ;
76+ var envars = new Dictionary < string , string > { [ "PATH" ] = PosixPathVar } ;
77+ var env = new PosixEnvironment ( fs , envars ) ;
78+
79+ bool actualResult = env . TryLocateExecutable ( PosixExecName , out string actualPath ) ;
80+
81+ Assert . False ( actualResult ) ;
82+ Assert . Null ( actualPath ) ;
83+ }
84+
85+ [ PlatformFact ( Platforms . Posix ) ]
86+ public void PosixEnvironment_TryLocateExecutable_Exists_ReturnTrueAndPath ( )
87+ {
88+ string expectedPath = "/usr/local/bin/foo" ;
89+ var fs = new TestFileSystem
90+ {
91+ Files = new Dictionary < string , byte [ ] >
92+ {
93+ [ expectedPath ] = Array . Empty < byte > ( ) ,
94+ }
95+ } ;
96+ var envars = new Dictionary < string , string > { [ "PATH" ] = PosixPathVar } ;
97+ var env = new PosixEnvironment ( fs , envars ) ;
98+
99+ bool actualResult = env . TryLocateExecutable ( PosixExecName , out string actualPath ) ;
100+
101+ Assert . True ( actualResult ) ;
102+ Assert . Equal ( expectedPath , actualPath ) ;
103+ }
104+
105+ [ PlatformFact ( Platforms . Posix ) ]
106+ public void PosixEnvironment_TryLocateExecutable_ExistsMultiple_ReturnTrueAndFirstPath ( )
107+ {
108+ string expectedPath = "/home/john.doe/bin/foo" ;
109+ var fs = new TestFileSystem
110+ {
111+ Files = new Dictionary < string , byte [ ] >
112+ {
113+ [ expectedPath ] = Array . Empty < byte > ( ) ,
114+ [ "/usr/local/bin/foo" ] = Array . Empty < byte > ( ) ,
115+ [ "/bin/foo" ] = Array . Empty < byte > ( ) ,
116+ }
117+ } ;
118+ var envars = new Dictionary < string , string > { [ "PATH" ] = PosixPathVar } ;
119+ var env = new PosixEnvironment ( fs , envars ) ;
120+
121+ bool actualResult = env . TryLocateExecutable ( PosixExecName , out string actualPath ) ;
66122
67123 Assert . True ( actualResult ) ;
68124 Assert . Equal ( expectedPath , actualPath ) ;
0 commit comments