Skip to content

Commit 5109f59

Browse files
shiftkeynulltoken
authored andcommitted
Ensure lack of optional parameters
1 parent 44aa149 commit 5109f59

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

LibGit2Sharp.Tests/MetaFixture.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,59 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
299299
Assert.True(false, Environment.NewLine + sb.ToString());
300300
}
301301
}
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+
}
302356
}
303357
}

0 commit comments

Comments
 (0)