Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
XUnit test for interface implementation
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