11using System ;
22using System . Diagnostics ;
33using System . IO ;
4+ using System . Reflection ;
45
56namespace LibGit2Sharp . Tests . TestHelpers
67{
78 public static class Constants
89 {
10+ public static readonly bool IsRunningOnUnix = IsUnixPlatform ( ) ;
911 public static readonly string TemporaryReposPath = BuildPath ( ) ;
1012 public const string UnknownSha = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" ;
1113 public static readonly Identity Identity = new Identity ( "A. U. Thor" , "thor@valhalla.asgard.com" ) ;
1214 public static readonly Signature Signature = new Signature ( Identity , new DateTimeOffset ( 2011 , 06 , 16 , 10 , 58 , 27 , TimeSpan . FromHours ( 2 ) ) ) ;
1315
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+
1423 // Populate these to turn on live credential tests: set the
1524 // PrivateRepoUrl to the URL of a repository that requires
1625 // authentication. Define PrivateRepoCredentials to return an instance of
@@ -40,19 +49,15 @@ public static string BuildPath()
4049 {
4150 string tempPath = null ;
4251
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 )
4653 {
4754 // 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 ( ) ;
5256 }
5357 else
5458 {
5559 const string LibGit2TestPath = "LibGit2TestPath" ;
60+
5661 // We're running on .Net/Windows
5762 if ( Environment . GetEnvironmentVariables ( ) . Contains ( LibGit2TestPath ) )
5863 {
@@ -72,6 +77,16 @@ public static string BuildPath()
7277 return testWorkingDirectory ;
7378 }
7479
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+
7590 // To help with creating secure strings to test with.
7691 private static System . Security . SecureString StringToSecureString ( string str )
7792 {
0 commit comments