1
+ using System ;
1
2
using System . Collections . Generic ;
3
+ using GitCredentialManager . Interop . Posix ;
2
4
using GitCredentialManager . Interop . Windows ;
3
5
using GitCredentialManager . Tests . Objects ;
4
6
using Xunit ;
@@ -7,62 +9,116 @@ namespace GitCredentialManager.Tests
7
9
{
8
10
public class EnvironmentTests
9
11
{
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
+
10
17
[ PlatformFact ( Platforms . Windows ) ]
11
18
public void WindowsEnvironment_TryLocateExecutable_NotExists_ReturnFalse ( )
12
19
{
13
- string pathVar = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows" ;
14
- string execName = "foo.exe" ;
15
20
var fs = new TestFileSystem ( ) ;
16
- var envars = new Dictionary < string , string > { [ "PATH" ] = pathVar } ;
21
+ var envars = new Dictionary < string , string > { [ "PATH" ] = WindowsPathVar } ;
17
22
var env = new WindowsEnvironment ( fs , envars ) ;
18
23
19
- bool actualResult = env . TryLocateExecutable ( execName , out string actualPath ) ;
24
+ bool actualResult = env . TryLocateExecutable ( WindowsExecName , out string actualPath ) ;
20
25
21
26
Assert . False ( actualResult ) ;
22
27
Assert . Null ( actualPath ) ;
23
28
}
24
29
25
30
[ PlatformFact ( Platforms . Windows ) ]
26
- public void WindowsEnvironment_TryLocateExecutable_Windows_Exists_ReturnTrueAndPath ( )
31
+ public void WindowsEnvironment_TryLocateExecutable_Exists_ReturnTrueAndPath ( )
27
32
{
28
- string pathVar = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows" ;
29
- string execName = "foo.exe" ;
30
33
string expectedPath = @"C:\Windows\system32\foo.exe" ;
31
34
var fs = new TestFileSystem
32
35
{
33
36
Files = new Dictionary < string , byte [ ] >
34
37
{
35
- [ @"C:\Windows\system32\foo.exe" ] = new byte [ 0 ] ,
38
+ [ expectedPath ] = Array . Empty < byte > ( )
36
39
}
37
40
} ;
38
- var envars = new Dictionary < string , string > { [ "PATH" ] = pathVar } ;
41
+ var envars = new Dictionary < string , string > { [ "PATH" ] = WindowsPathVar } ;
39
42
var env = new WindowsEnvironment ( fs , envars ) ;
40
43
41
- bool actualResult = env . TryLocateExecutable ( execName , out string actualPath ) ;
44
+ bool actualResult = env . TryLocateExecutable ( WindowsExecName , out string actualPath ) ;
42
45
43
46
Assert . True ( actualResult ) ;
44
47
Assert . Equal ( expectedPath , actualPath ) ;
45
48
}
46
49
47
50
[ PlatformFact ( Platforms . Windows ) ]
48
- public void WindowsEnvironment_TryLocateExecutable_Windows_ExistsMultiple_ReturnTrueAndFirstPath ( )
51
+ public void WindowsEnvironment_TryLocateExecutable_ExistsMultiple_ReturnTrueAndFirstPath ( )
49
52
{
50
- string pathVar = @"C:\Users\john.doe\bin;C:\Windows\system32;C:\Windows" ;
51
- string execName = "foo.exe" ;
52
53
string expectedPath = @"C:\Users\john.doe\bin\foo.exe" ;
53
54
var fs = new TestFileSystem
54
55
{
55
56
Files = new Dictionary < string , byte [ ] >
56
57
{
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 > ( ) ,
60
61
}
61
62
} ;
62
- var envars = new Dictionary < string , string > { [ "PATH" ] = pathVar } ;
63
+ var envars = new Dictionary < string , string > { [ "PATH" ] = WindowsPathVar } ;
63
64
var env = new WindowsEnvironment ( fs , envars ) ;
64
65
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 ) ;
66
122
67
123
Assert . True ( actualResult ) ;
68
124
Assert . Equal ( expectedPath , actualPath ) ;
0 commit comments