1313
1414namespace LibGit2Sharp . Tests
1515{
16- public class MetaFixture
16+ public partial class MetaFixture
1717 {
1818 private static readonly HashSet < Type > explicitOnlyInterfaces = new HashSet < Type >
1919 {
@@ -28,8 +28,8 @@ public void PublicTestMethodsAreFactsOrTheories()
2828 "LibGit2Sharp.Tests.FilterBranchFixture.Dispose" ,
2929 } ;
3030
31- var fixtures = from t in Assembly . GetAssembly ( typeof ( MetaFixture ) ) . GetExportedTypes ( )
32- where t . IsPublic && ! t . IsNested
31+ var fixtures = from t in typeof ( MetaFixture ) . GetTypeInfo ( ) . Assembly . GetExportedTypes ( )
32+ where t . GetTypeInfo ( ) . IsPublic && ! t . IsNested
3333 where t . Namespace != typeof ( BaseFixture ) . Namespace // Exclude helpers
3434 let methods = t . GetMethods ( BindingFlags . DeclaredOnly | BindingFlags . Instance | BindingFlags . Public )
3535 from m in methods
@@ -49,12 +49,12 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
4949 {
5050 var typesWithDebuggerDisplayAndInvalidImplPattern = new List < Type > ( ) ;
5151
52- IEnumerable < Type > libGit2SharpTypes = Assembly . GetAssembly ( typeof ( IRepository ) ) . GetExportedTypes ( )
53- . Where ( t => t . GetCustomAttributes ( typeof ( DebuggerDisplayAttribute ) , false ) . Any ( ) ) ;
52+ IEnumerable < Type > libGit2SharpTypes = typeof ( IRepository ) . GetTypeInfo ( ) . Assembly . GetExportedTypes ( )
53+ . Where ( t => t . GetTypeInfo ( ) . GetCustomAttributes ( typeof ( DebuggerDisplayAttribute ) , false ) . Any ( ) ) ;
5454
5555 foreach ( Type type in libGit2SharpTypes )
5656 {
57- var debuggerDisplayAttribute = ( DebuggerDisplayAttribute ) type . GetCustomAttributes ( typeof ( DebuggerDisplayAttribute ) , false ) . Single ( ) ;
57+ var debuggerDisplayAttribute = ( DebuggerDisplayAttribute ) type . GetTypeInfo ( ) . GetCustomAttributes ( typeof ( DebuggerDisplayAttribute ) , false ) . Single ( ) ;
5858
5959 if ( debuggerDisplayAttribute . Value != "{DebuggerDisplay,nq}" )
6060 {
@@ -89,12 +89,12 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
8989 {
9090 var nonTestableTypes = new Dictionary < Type , IEnumerable < string > > ( ) ;
9191
92- IEnumerable < Type > libGit2SharpTypes = Assembly . GetAssembly ( typeof ( IRepository ) ) . GetExportedTypes ( )
92+ IEnumerable < Type > libGit2SharpTypes = typeof ( IRepository ) . GetTypeInfo ( ) . Assembly . GetExportedTypes ( )
9393 . Where ( t => MustBeMockable ( t ) && t . Namespace == typeof ( IRepository ) . Namespace ) ;
9494
9595 foreach ( Type type in libGit2SharpTypes )
9696 {
97- if ( type . IsInterface || type . IsEnum || IsStatic ( type ) )
97+ if ( type . GetTypeInfo ( ) . IsInterface || type . GetTypeInfo ( ) . IsEnum || IsStatic ( type ) )
9898 continue ;
9999
100100 var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames ( type ) . ToList ( ) ;
@@ -109,14 +109,14 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
109109 nonTestableTypes . Add ( type , new List < string > ( ) ) ;
110110 }
111111
112- if ( type . IsAbstract )
112+ if ( type . GetTypeInfo ( ) . IsAbstract )
113113 {
114114 continue ;
115115 }
116116
117117 try
118118 {
119- if ( type . ContainsGenericParameters )
119+ if ( type . GetTypeInfo ( ) . ContainsGenericParameters )
120120 {
121121 var constructType = type . MakeGenericType ( Enumerable . Repeat ( typeof ( object ) , type . GetGenericArguments ( ) . Length ) . ToArray ( ) ) ;
122122 Activator . CreateInstance ( constructType , true ) ;
@@ -140,62 +140,27 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
140140
141141 private static bool MustBeMockable ( Type type )
142142 {
143- if ( type . IsSealed )
143+ if ( type . GetTypeInfo ( ) . IsSealed )
144144 {
145145 return false ;
146146 }
147147
148- if ( type . IsAbstract )
148+ if ( type . GetTypeInfo ( ) . IsAbstract )
149149 {
150- return ! type . Assembly . GetExportedTypes ( )
151- . Where ( t => t . IsSubclassOf ( type ) )
152- . All ( t => t . IsAbstract || t . IsSealed ) ;
150+ return ! type . GetTypeInfo ( ) . Assembly . GetExportedTypes ( )
151+ . Where ( t => t . GetTypeInfo ( ) . IsSubclassOf ( type ) )
152+ . All ( t => t . GetTypeInfo ( ) . IsAbstract || t . GetTypeInfo ( ) . IsSealed ) ;
153153 }
154154
155155 return true ;
156156 }
157157
158- [ Fact ]
159- public void LibGit2SharpPublicInterfacesCoverAllPublicMembers ( )
160- {
161- var methodsMissingFromInterfaces =
162- from t in Assembly . GetAssembly ( typeof ( IRepository ) ) . GetExportedTypes ( )
163- where ! t . IsInterface
164- where t . GetInterfaces ( ) . Any ( i => i . IsPublic && i . Namespace == typeof ( IRepository ) . Namespace && ! explicitOnlyInterfaces . Contains ( i ) )
165- let interfaceTargetMethods = from i in t . GetInterfaces ( )
166- from im in t . GetInterfaceMap ( i ) . TargetMethods
167- select im
168- from tm in t . GetMethods ( BindingFlags . DeclaredOnly | BindingFlags . Public | BindingFlags . Instance )
169- where ! interfaceTargetMethods . Contains ( tm )
170- select t . Name + " has extra method " + tm . Name ;
171-
172- Assert . Equal ( "" , string . Join ( Environment . NewLine ,
173- methodsMissingFromInterfaces . ToArray ( ) ) ) ;
174- }
175-
176- [ Fact ]
177- public void LibGit2SharpExplicitOnlyInterfacesAreIndeedExplicitOnly ( )
178- {
179- var methodsMissingFromInterfaces =
180- from t in Assembly . GetAssembly ( typeof ( IRepository ) ) . GetExportedTypes ( )
181- where t . GetInterfaces ( ) . Any ( explicitOnlyInterfaces . Contains )
182- let interfaceTargetMethods = from i in t . GetInterfaces ( )
183- where explicitOnlyInterfaces . Contains ( i )
184- from im in t . GetInterfaceMap ( i ) . TargetMethods
185- select im
186- from tm in t . GetMethods ( BindingFlags . DeclaredOnly | BindingFlags . Public | BindingFlags . Instance )
187- where interfaceTargetMethods . Contains ( tm )
188- select t . Name + " has public method " + tm . Name + " which should be explicitly implemented." ;
189-
190- Assert . Equal ( "" , string . Join ( Environment . NewLine ,
191- methodsMissingFromInterfaces . ToArray ( ) ) ) ;
192- }
193158
194159 [ Fact ]
195160 public void EnumsWithFlagsHaveMutuallyExclusiveValues ( )
196161 {
197- var flagsEnums = Assembly . GetAssembly ( typeof ( IRepository ) ) . GetExportedTypes ( )
198- . Where ( t => t . IsEnum && t . GetCustomAttributes ( typeof ( FlagsAttribute ) , false ) . Any ( ) ) ;
162+ var flagsEnums = typeof ( IRepository ) . GetTypeInfo ( ) . Assembly . GetExportedTypes ( )
163+ . Where ( t => t . GetTypeInfo ( ) . IsEnum && t . GetTypeInfo ( ) . GetCustomAttributes ( typeof ( FlagsAttribute ) , false ) . Any ( ) ) ;
199164
200165 var overlaps = from t in flagsEnums
201166 from int x in Enum . GetValues ( t )
@@ -259,19 +224,19 @@ private static bool HasEmptyPublicOrProtectedConstructor(Type type)
259224
260225 private static bool IsStatic ( Type type )
261226 {
262- return type . IsAbstract && type . IsSealed ;
227+ return type . GetTypeInfo ( ) . IsAbstract && type . GetTypeInfo ( ) . IsSealed ;
263228 }
264229
265230 // Related to https://github.com/libgit2/libgit2sharp/issues/644 and https://github.com/libgit2/libgit2sharp/issues/645
266231 [ Fact ]
267232 public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability ( )
268233 {
269- var nonVirtualGetEnumeratorMethods = Assembly . GetAssembly ( typeof ( IRepository ) )
234+ var nonVirtualGetEnumeratorMethods = typeof ( IRepository ) . GetTypeInfo ( ) . Assembly
270235 . GetExportedTypes ( )
271236 . Where ( t =>
272237 t . Namespace == typeof ( IRepository ) . Namespace &&
273- ! t . IsSealed &&
274- ! t . IsAbstract &&
238+ ! t . GetTypeInfo ( ) . IsSealed &&
239+ ! t . GetTypeInfo ( ) . IsAbstract &&
275240 t . GetInterfaces ( ) . Any ( i => i . IsAssignableFrom ( typeof ( IEnumerable < > ) ) ) )
276241 . Select ( t => t . GetMethod ( "GetEnumerator" ) )
277242 . Where ( m =>
@@ -298,7 +263,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
298263 {
299264 const string coreNamespace = "LibGit2Sharp.Core" ;
300265
301- var types = Assembly . GetAssembly ( typeof ( IRepository ) )
266+ var types = typeof ( IRepository ) . GetTypeInfo ( ) . Assembly
302267 . GetExportedTypes ( )
303268 . Where ( t => t . FullName . StartsWith ( coreNamespace + "." ) )
304269
@@ -326,7 +291,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
326291 public void NoOptionalParametersinMethods ( )
327292 {
328293 IEnumerable < string > mis =
329- from t in Assembly . GetAssembly ( typeof ( IRepository ) )
294+ from t in typeof ( IRepository ) . GetTypeInfo ( ) . Assembly
330295 . GetExportedTypes ( )
331296 from m in t . GetMethods ( )
332297 where ! m . IsObsolete ( )
@@ -349,7 +314,7 @@ where p.IsOptional
349314 public void NoOptionalParametersinConstructors ( )
350315 {
351316 IEnumerable < string > mis =
352- from t in Assembly . GetAssembly ( typeof ( IRepository ) )
317+ from t in typeof ( IRepository ) . GetTypeInfo ( ) . Assembly
353318 . GetExportedTypes ( )
354319 from c in t . GetConstructors ( )
355320 from p in c . GetParameters ( )
@@ -389,12 +354,12 @@ from m in GetInvalidPublicExtensionMethods()
389354
390355 static IEnumerable < MethodInfo > GetInvalidPublicExtensionMethods ( )
391356 {
392- var query = from type in ( Assembly . GetAssembly ( typeof ( IRepository ) ) ) . GetTypes ( )
393- where type . IsSealed && ! type . IsGenericType && ! type . IsNested && type . IsPublic
357+ var query = from type in typeof ( IRepository ) . GetTypeInfo ( ) . Assembly . GetTypes ( )
358+ where type . GetTypeInfo ( ) . IsSealed && ! type . GetTypeInfo ( ) . IsGenericType && ! type . IsNested && type . GetTypeInfo ( ) . IsPublic
394359 from method in type . GetMethods ( BindingFlags . Static | BindingFlags . Public )
395360 where method . IsDefined ( typeof ( ExtensionAttribute ) , false )
396361 let parameterType = method . GetParameters ( ) [ 0 ] . ParameterType
397- where parameterType != null && ! parameterType . IsInterface && ! parameterType . IsEnum
362+ where parameterType != null && ! parameterType . GetTypeInfo ( ) . IsInterface && ! parameterType . GetTypeInfo ( ) . IsEnum
398363 select method ;
399364 return query ;
400365 }
@@ -405,8 +370,8 @@ public void AllIDiffResultsAreInChangesBuilder()
405370 var diff = typeof ( Diff ) . GetField ( "ChangesBuilders" , BindingFlags . NonPublic | BindingFlags . Static ) ;
406371 var changesBuilders = ( System . Collections . IDictionary ) diff . GetValue ( null ) ;
407372
408- IEnumerable < Type > diffResults = typeof ( Diff ) . Assembly . GetExportedTypes ( )
409- . Where ( type => type . GetInterface ( "IDiffResult" ) != null ) ;
373+ IEnumerable < Type > diffResults = typeof ( Diff ) . GetTypeInfo ( ) . Assembly . GetExportedTypes ( )
374+ . Where ( type => type . GetTypeInfo ( ) . GetInterface ( "IDiffResult" ) != null ) ;
410375
411376 var nonBuilderTypes = diffResults . Where ( diffResult => ! changesBuilders . Contains ( diffResult ) ) ;
412377 Assert . False ( nonBuilderTypes . Any ( ) , "Classes which implement IDiffResult but are not registered under ChangesBuilders in Diff:" + Environment . NewLine +
0 commit comments