@@ -299,5 +299,59 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
299
299
Assert . True ( false , Environment . NewLine + sb . ToString ( ) ) ;
300
300
}
301
301
}
302
+
303
+ [ Fact ]
304
+ public void NoOptionalParametersinMethods ( )
305
+ {
306
+ IEnumerable < string > mis =
307
+ from t in Assembly . GetAssembly ( typeof ( IRepository ) )
308
+ . GetExportedTypes ( )
309
+ from m in t . GetMethods ( )
310
+ where ! m . IsObsolete ( )
311
+ from p in m . GetParameters ( )
312
+ where p . IsOptional
313
+ select m . DeclaringType + "." + m . Name ;
314
+
315
+ var sb = new StringBuilder ( ) ;
316
+
317
+ foreach ( var method in mis . Distinct ( ) )
318
+ {
319
+ sb . AppendFormat ( "At least one overload of method '{0}' accepts an optional parameter.{1}" ,
320
+ method , Environment . NewLine ) ;
321
+ }
322
+
323
+ Assert . Equal ( "" , sb . ToString ( ) ) ;
324
+ }
325
+
326
+ [ Fact ]
327
+ public void NoOptionalParametersinConstructors ( )
328
+ {
329
+ IEnumerable < string > mis =
330
+ from t in Assembly . GetAssembly ( typeof ( IRepository ) )
331
+ . GetExportedTypes ( )
332
+ from c in t . GetConstructors ( )
333
+ from p in c . GetParameters ( )
334
+ where p . IsOptional
335
+ select c . DeclaringType . Name ;
336
+
337
+ var sb = new StringBuilder ( ) ;
338
+
339
+ foreach ( var method in mis . Distinct ( ) )
340
+ {
341
+ sb . AppendFormat ( "At least one constructor of type '{0}' accepts an optional parameter.{1}" ,
342
+ method , Environment . NewLine ) ;
343
+ }
344
+
345
+ Assert . Equal ( "" , sb . ToString ( ) ) ;
346
+ }
347
+ }
348
+
349
+ internal static class TypeExtensions
350
+ {
351
+ internal static bool IsObsolete ( this MethodInfo methodInfo )
352
+ {
353
+ var attributes = methodInfo . GetCustomAttributes ( false ) ;
354
+ return attributes . Any ( a => a is ObsoleteAttribute ) ;
355
+ }
302
356
}
303
357
}
0 commit comments