Skip to content

Instantly share code, notes, and snippets.

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