Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Forster <brendan@github.com>2015-05-10 14:04:55 +0300
committernulltoken <emeric.fermas@gmail.com>2015-05-15 20:31:47 +0300
commit5109f5979d92f92c74144a4595e35d8094dc9a53 (patch)
treec742aed8f67c48693798b3b20dd8f077257f217f
parent44aa1498f8159b169af93895c60a7a68c6c1ca2b (diff)
Ensure lack of optional parameters
-rw-r--r--LibGit2Sharp.Tests/MetaFixture.cs54
1 files changed, 54 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/MetaFixture.cs b/LibGit2Sharp.Tests/MetaFixture.cs
index df0a1d96..685ff5f4 100644
--- a/LibGit2Sharp.Tests/MetaFixture.cs
+++ b/LibGit2Sharp.Tests/MetaFixture.cs
@@ -299,5 +299,59 @@ namespace LibGit2Sharp.Tests
Assert.True(false, Environment.NewLine + sb.ToString());
}
}
+
+ [Fact]
+ public void NoOptionalParametersinMethods()
+ {
+ IEnumerable<string> mis =
+ from t in Assembly.GetAssembly(typeof(IRepository))
+ .GetExportedTypes()
+ from m in t.GetMethods()
+ where !m.IsObsolete()
+ from p in m.GetParameters()
+ where p.IsOptional
+ select m.DeclaringType + "." + m.Name;
+
+ var sb = new StringBuilder();
+
+ foreach (var method in mis.Distinct())
+ {
+ sb.AppendFormat("At least one overload of method '{0}' accepts an optional parameter.{1}",
+ method, Environment.NewLine);
+ }
+
+ Assert.Equal("", sb.ToString());
+ }
+
+ [Fact]
+ public void NoOptionalParametersinConstructors()
+ {
+ IEnumerable<string> mis =
+ from t in Assembly.GetAssembly(typeof(IRepository))
+ .GetExportedTypes()
+ from c in t.GetConstructors()
+ from p in c.GetParameters()
+ where p.IsOptional
+ select c.DeclaringType.Name;
+
+ var sb = new StringBuilder();
+
+ foreach (var method in mis.Distinct())
+ {
+ sb.AppendFormat("At least one constructor of type '{0}' accepts an optional parameter.{1}",
+ method, Environment.NewLine);
+ }
+
+ Assert.Equal("", sb.ToString());
+ }
+ }
+
+ internal static class TypeExtensions
+ {
+ internal static bool IsObsolete(this MethodInfo methodInfo)
+ {
+ var attributes = methodInfo.GetCustomAttributes(false);
+ return attributes.Any(a => a is ObsoleteAttribute);
+ }
}
}