Created
July 25, 2016 17:52
-
-
Save soltys/d73b278c29d8f664f4afd1c0ad6e96ac to your computer and use it in GitHub Desktop.
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
[Fact] | |
public void CheckIfAllClassesInNamespaceHavePropertiesWithVirtualKeyword() | |
{ | |
var assembly = Assembly.GetAssembly(typeof(User)); | |
var @namespace = typeof(User).Namespace; | |
var typesInNamespace = GetTypesInNamespace(assembly, @namespace); | |
foreach (var type in typesInNamespace) | |
{ | |
var properties = type.GetProperties(); | |
foreach (var property in properties) | |
{ | |
var userMessage = $"{type.FullName}.{property.Name}"; | |
Assert.True(property.GetGetMethod().IsVirtual, userMessage); | |
} | |
} | |
} | |
private Type[] GetTypesInNamespace(Assembly assembly, string nameSpace) | |
{ | |
return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment