1
1
using System ;
2
2
using System . Diagnostics ;
3
3
using System . IO ;
4
+ using System . Reflection ;
4
5
5
6
namespace LibGit2Sharp . Tests . TestHelpers
6
7
{
7
8
public static class Constants
8
9
{
10
+ public static readonly bool IsRunningOnUnix = IsUnixPlatform ( ) ;
9
11
public static readonly string TemporaryReposPath = BuildPath ( ) ;
10
12
public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" ;
11
13
public static readonly Identity Identity = new Identity ( "A. U. Thor" , "[email protected] " ) ;
12
14
public static readonly Signature Signature = new Signature ( Identity , new DateTimeOffset ( 2011 , 06 , 16 , 10 , 58 , 27 , TimeSpan . FromHours ( 2 ) ) ) ;
13
15
16
+ private static bool IsUnixPlatform ( )
17
+ {
18
+ // see http://mono-project.com/FAQ%3a_Technical#Mono_Platforms
19
+ var p = ( int ) Environment . OSVersion . Platform ;
20
+ return ( p == 4 ) || ( p == 6 ) || ( p == 128 ) ;
21
+ }
22
+
14
23
// Populate these to turn on live credential tests: set the
15
24
// PrivateRepoUrl to the URL of a repository that requires
16
25
// authentication. Define PrivateRepoCredentials to return an instance of
@@ -40,19 +49,15 @@ public static string BuildPath()
40
49
{
41
50
string tempPath = null ;
42
51
43
- var unixPath = Type . GetType ( "Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" ) ;
44
-
45
- if ( unixPath != null )
52
+ if ( IsRunningOnUnix )
46
53
{
47
54
// We're running on Mono/*nix. Let's unwrap the path
48
- tempPath = ( string ) unixPath . InvokeMember ( "GetCompleteRealPath" ,
49
- System . Reflection . BindingFlags . Static | System . Reflection . BindingFlags . FlattenHierarchy |
50
- System . Reflection . BindingFlags . InvokeMethod | System . Reflection . BindingFlags . Public ,
51
- null , unixPath , new object [ ] { Path . GetTempPath ( ) } ) ;
55
+ tempPath = UnwrapUnixTempPath ( ) ;
52
56
}
53
57
else
54
58
{
55
59
const string LibGit2TestPath = "LibGit2TestPath" ;
60
+
56
61
// We're running on .Net/Windows
57
62
if ( Environment . GetEnvironmentVariables ( ) . Contains ( LibGit2TestPath ) )
58
63
{
@@ -72,6 +77,16 @@ public static string BuildPath()
72
77
return testWorkingDirectory ;
73
78
}
74
79
80
+ private static string UnwrapUnixTempPath ( )
81
+ {
82
+ var type = Type . GetType ( "Mono.Unix.UnixPath, Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" ) ;
83
+
84
+ return ( string ) type . InvokeMember ( "GetCompleteRealPath" ,
85
+ BindingFlags . Static | BindingFlags . FlattenHierarchy |
86
+ BindingFlags . InvokeMethod | BindingFlags . Public ,
87
+ null , type , new object [ ] { Path . GetTempPath ( ) } ) ;
88
+ }
89
+
75
90
// To help with creating secure strings to test with.
76
91
private static System . Security . SecureString StringToSecureString ( string str )
77
92
{
0 commit comments