|
13 | 13 |
|
14 | 14 | namespace LibGit2Sharp.Tests
|
15 | 15 | {
|
16 |
| - public partial class MetaFixture |
| 16 | + public class MetaFixture |
17 | 17 | {
|
18 | 18 | private static readonly HashSet<Type> explicitOnlyInterfaces = new HashSet<Type>
|
19 | 19 | {
|
20 | 20 | typeof(IBelongToARepository), typeof(IDiffResult),
|
21 | 21 | };
|
22 | 22 |
|
| 23 | + [Fact] |
| 24 | + public void LibGit2SharpPublicInterfacesCoverAllPublicMembers() |
| 25 | + { |
| 26 | + var methodsMissingFromInterfaces = |
| 27 | + from t in typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes() |
| 28 | + where !t.GetTypeInfo().IsInterface |
| 29 | + where t.GetTypeInfo().GetInterfaces().Any(i => i.GetTypeInfo().IsPublic && i.Namespace == typeof(IRepository).Namespace && !explicitOnlyInterfaces.Contains(i)) |
| 30 | + let interfaceTargetMethods = from i in t.GetTypeInfo().GetInterfaces() |
| 31 | + from im in t.GetInterfaceMap(i).TargetMethods |
| 32 | + select im |
| 33 | + from tm in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance) |
| 34 | + where !interfaceTargetMethods.Contains(tm) |
| 35 | + select t.Name + " has extra method " + tm.Name; |
| 36 | + |
| 37 | + Assert.Equal("", string.Join(Environment.NewLine, |
| 38 | + methodsMissingFromInterfaces.ToArray())); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void LibGit2SharpExplicitOnlyInterfacesAreIndeedExplicitOnly() |
| 43 | + { |
| 44 | + var methodsMissingFromInterfaces = |
| 45 | + from t in typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes() |
| 46 | + where t.GetInterfaces().Any(explicitOnlyInterfaces.Contains) |
| 47 | + let interfaceTargetMethods = from i in t.GetInterfaces() |
| 48 | + where explicitOnlyInterfaces.Contains(i) |
| 49 | + from im in t.GetTypeInfo().GetInterfaceMap(i).TargetMethods |
| 50 | + select im |
| 51 | + from tm in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance) |
| 52 | + where interfaceTargetMethods.Contains(tm) |
| 53 | + select t.Name + " has public method " + tm.Name + " which should be explicitly implemented."; |
| 54 | + |
| 55 | + Assert.Equal("", string.Join(Environment.NewLine, |
| 56 | + methodsMissingFromInterfaces.ToArray())); |
| 57 | + } |
| 58 | + |
23 | 59 | [Fact]
|
24 | 60 | public void PublicTestMethodsAreFactsOrTheories()
|
25 | 61 | {
|
|
0 commit comments