public void From_ClassWithNoGenericArguments_TreeShouldNotHaveAny() { // Act var tree = TypeTree.From(typeof(NonGenericNoInterfacesClass)); // Assert Assert.Null(tree.GenericArguments); }
public void From_ClassWithNoImplementedInterfaces_TreeShouldNotHaveAny() { // Act var tree = TypeTree.From(typeof(NonGenericNoInterfacesClass)); // Assert Assert.Null(tree.DirectlyImplementedInterfaces); }
public void From_BuiltInType_TreeShouldNotHaveGenericArguments(Type simpleType) { // Act var tree = TypeTree.From(simpleType); // Assert Assert.Null(tree.GenericArguments); }
public void From_AnyType_RootTreeTypeShouldMatch(Type type) { // Act var tree = TypeTree.From(type); // Assert Assert.Equal(type, tree.Type); }
public static string Visualize(this Type type) { var typeTree = TypeTree.From(type); var visualizationRoot = new TreeNode(); Traverse(visualizationRoot, typeTree); return(new TreeVisualization(visualizationRoot).ToString()); }
public void From_TypeWithDirectInterfaces_TreeShouldContainThem() { // Arrange var expectedInterfaces = new[] { typeof(IFoo), typeof(IBar) }; // Act var tree = TypeTree.From(typeof(ClassWithInterfaces)); // Assert Assert.NotNull(tree.DirectlyImplementedInterfaces); Assert.NotEmpty(tree.DirectlyImplementedInterfaces); Assert.Equal(expectedInterfaces, tree.DirectlyImplementedInterfaces.Select(t => t.Type)); }
public void From_TypeWithSingleGenericArgument_TreeShouldContainIt() { // Arrange var argumentType = typeof(int); var genericClass = CreateGeneric <OneGenericArgumentClass <int> >(typeof(OneGenericArgumentClass <>), typeof(int)); // Act var tree = TypeTree.From(genericClass.GetType()); // Assert Assert.NotNull(tree.GenericArguments); Assert.Single(tree.GenericArguments); Assert.Equal(argumentType, tree.GenericArguments.First().Type); }
public void From_TypeWithInterfaceInheritance_TreeShouldReflectIt() { // Arrange var expectedNestedTreeInterfaces = new[] { typeof(IFoo), typeof(IBar) }; // Act var tree = TypeTree.From(typeof(ClassWithInheritedInterfaces)); // Assert Assert.Single(tree.DirectlyImplementedInterfaces); var nestedTree = tree.DirectlyImplementedInterfaces.First(); Assert.Equal(typeof(IFooBar), nestedTree.Type); Assert.NotNull(nestedTree.DirectlyImplementedInterfaces); Assert.Equal(expectedNestedTreeInterfaces, nestedTree.DirectlyImplementedInterfaces.Select(t => t.Type)); }
public void From_TypeWithNestedGenericArguments_TreeShouldReflectIt() { // Arrange var nestedArgumentType = typeof(int); var genericClass = CreateGeneric <OneGenericArgumentClass <List <int> > >(typeof(OneGenericArgumentClass <>), typeof(List <int>)); // Act var tree = TypeTree.From(genericClass.GetType()); // Assert Assert.NotNull(tree.GenericArguments); Assert.Single(tree.GenericArguments); var genericArgument = tree.GenericArguments.First(); Assert.NotNull(genericArgument.GenericArguments); Assert.Single(genericArgument.GenericArguments); var nestedGenericArgument = genericArgument.GenericArguments.First(); Assert.Equal(nestedArgumentType, nestedGenericArgument.Type); Assert.Null(nestedGenericArgument.GenericArguments); }