@@ -16,14 +16,58 @@ public class TfsGitRepositoryInfoTests
1616 /// </summary>
1717 private ExternalLink CreateMockExternalLink ( string uri )
1818 {
19- // Create a mock RegisteredLinkType using reflection
19+ // Try to create a mock RegisteredLinkType using reflection
20+ // First try the two-parameter constructor
2021 var linkTypeConstructor = typeof ( RegisteredLinkType ) . GetConstructor (
2122 BindingFlags . NonPublic | BindingFlags . Instance ,
2223 null ,
2324 new Type [ ] { typeof ( string ) , typeof ( string ) } ,
2425 null ) ;
2526
26- var linkType = ( RegisteredLinkType ) linkTypeConstructor . Invoke ( new object [ ] { "MockLinkType" , "Mock Link Type" } ) ;
27+ RegisteredLinkType linkType = null ;
28+
29+ if ( linkTypeConstructor != null )
30+ {
31+ linkType = ( RegisteredLinkType ) linkTypeConstructor . Invoke ( new object [ ] { "MockLinkType" , "Mock Link Type" } ) ;
32+ }
33+ else
34+ {
35+ // Try alternative constructors if the two-parameter one doesn't exist
36+ var constructors = typeof ( RegisteredLinkType ) . GetConstructors ( BindingFlags . NonPublic | BindingFlags . Instance | BindingFlags . Public ) ;
37+
38+ foreach ( var ctor in constructors )
39+ {
40+ var parameters = ctor . GetParameters ( ) ;
41+ if ( parameters . Length == 1 && parameters [ 0 ] . ParameterType == typeof ( string ) )
42+ {
43+ linkType = ( RegisteredLinkType ) ctor . Invoke ( new object [ ] { "MockLinkType" } ) ;
44+ break ;
45+ }
46+ else if ( parameters . Length == 0 )
47+ {
48+ linkType = ( RegisteredLinkType ) ctor . Invoke ( new object [ ] { } ) ;
49+ break ;
50+ }
51+ }
52+
53+ // If still null, try to find any constructor with minimal parameters
54+ if ( linkType == null && constructors . Length > 0 )
55+ {
56+ var simplestCtor = constructors [ 0 ] ;
57+ var ctorParams = simplestCtor . GetParameters ( ) ;
58+ var args = new object [ ctorParams . Length ] ;
59+ for ( int i = 0 ; i < ctorParams . Length ; i ++ )
60+ {
61+ args [ i ] = ctorParams [ i ] . ParameterType . IsValueType ? Activator . CreateInstance ( ctorParams [ i ] . ParameterType ) : null ;
62+ }
63+ linkType = ( RegisteredLinkType ) simplestCtor . Invoke ( args ) ;
64+ }
65+ }
66+
67+ if ( linkType == null )
68+ {
69+ throw new InvalidOperationException ( "Could not create RegisteredLinkType instance via reflection. Available constructors may have changed." ) ;
70+ }
2771
2872 // Create ExternalLink using the mock link type
2973 return new ExternalLink ( linkType , uri ) ;
0 commit comments