XUnit test for interface implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ValueObjectTest | |
{ | |
[Fact] | |
public void AllValueObjectsImplementIEquatable() | |
{ | |
var typeToFind = typeof (IValueObject); | |
var typesFound = AppDomain.CurrentDomain.GetAssemblies().ToList() | |
.SelectMany(s => s.GetTypes()) | |
.Where(typeToFind.IsAssignableFrom); | |
foreach ( var type in typesFound) | |
{ | |
if (type.IsInterface) continue; | |
bool typeIsIEquatable = type.GetInterfaces().Any( | |
i => i.IsGenericType && i.GetGenericTypeDefinition() == typeof (IEquatable <>)); | |
Assert.True(typeIsIEquatable, string.Format( "{0} does not implement IEquatable<>",type)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment