Created
February 24, 2015 16:20
-
-
Save scottlaw1/ded746b8057fb297c5f0 to your computer and use it in GitHub Desktop.
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