Beispiel #1
0
        public void From_ClassWithNoGenericArguments_TreeShouldNotHaveAny()
        {
            // Act
            var tree = TypeTree.From(typeof(NonGenericNoInterfacesClass));

            // Assert
            Assert.Null(tree.GenericArguments);
        }
Beispiel #2
0
        public void From_ClassWithNoImplementedInterfaces_TreeShouldNotHaveAny()
        {
            // Act
            var tree = TypeTree.From(typeof(NonGenericNoInterfacesClass));

            // Assert
            Assert.Null(tree.DirectlyImplementedInterfaces);
        }
Beispiel #3
0
        public void From_BuiltInType_TreeShouldNotHaveGenericArguments(Type simpleType)
        {
            // Act
            var tree = TypeTree.From(simpleType);

            // Assert
            Assert.Null(tree.GenericArguments);
        }
Beispiel #4
0
        public void From_AnyType_RootTreeTypeShouldMatch(Type type)
        {
            // Act
            var tree = TypeTree.From(type);

            // Assert
            Assert.Equal(type, tree.Type);
        }
Beispiel #5
0
        public static string Visualize(this Type type)
        {
            var typeTree = TypeTree.From(type);

            var visualizationRoot = new TreeNode();

            Traverse(visualizationRoot, typeTree);

            return(new TreeVisualization(visualizationRoot).ToString());
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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));
        }
Beispiel #9
0
        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);
        }