Beispiel #1
0
        public void FieldTestConstantStringRep()
        {
            var          fieldSymbol = (IFieldSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "publicString");
            FieldApiView field       = new FieldApiView(fieldSymbol);

            Assert.Equal("public static const string publicString = \"constant string\";", field.ToString());
        }
Beispiel #2
0
        public void MethodTestMultipleAttributesMultipleTypeParamsNoParams()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1", "AttributesTypeParamsMethod");
            MethodApiView method       = new MethodApiView(methodSymbol);

            Assert.True(method.IsInterfaceMethod);
            Assert.False(method.IsStatic);
            Assert.False(method.IsVirtual);
            Assert.False(method.IsSealed);
            Assert.False(method.IsOverride);
            Assert.True(method.IsAbstract);
            Assert.False(method.IsExtern);
            Assert.Equal("int", method.ReturnType.Tokens[0].DisplayString);

            Assert.Equal(2, method.Attributes.Length);
            Assert.Equal("TestLibrary", method.Attributes[0].Type.Tokens[0].DisplayString);
            Assert.Equal(".", method.Attributes[0].Type.Tokens[1].DisplayString);
            Assert.Equal("CustomAttribute", method.Attributes[0].Type.Tokens[2].DisplayString);

            Assert.Equal(2, method.Attributes[0].ConstructorArgs.Length);
            Assert.Equal("\"Test\"", method.Attributes[0].ConstructorArgs[0].Value);
            Assert.Equal("Named", method.Attributes[0].ConstructorArgs[1].Name);
            Assert.Equal("\"Param\"", method.Attributes[0].ConstructorArgs[1].Value);

            Assert.Equal("TestLibrary", method.Attributes[1].Type.Tokens[0].DisplayString);
            Assert.Equal(".", method.Attributes[1].Type.Tokens[1].DisplayString);
            Assert.Equal("NewAttribute", method.Attributes[1].Type.Tokens[2].DisplayString);
            Assert.Empty(method.Attributes[1].ConstructorArgs);

            Assert.Empty(method.Parameters);
            Assert.Equal(2, method.TypeParameters.Length);
        }
Beispiel #3
0
        public void FieldTestReadOnlyStringRep()
        {
            var          fieldSymbol = (IFieldSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "publicField");
            FieldApiView field       = new FieldApiView(fieldSymbol);

            Assert.Equal("public readonly int publicField;", field.ToString());
        }
Beispiel #4
0
        public void MethodTestNoAttributesOneTypeParamMultipleParamsStringRep()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1", "TypeParamParamsMethod");
            MethodApiView method       = new MethodApiView(methodSymbol);

            Assert.Equal("int TypeParamParamsMethod<T>(T param, string str = \"hello\");", method.ToString().Replace(Environment.NewLine, ""));
        }
Beispiel #5
0
        public void FieldTestProtectedStringRep()
        {
            var          fieldSymbol = (IFieldSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "protectedField");
            FieldApiView field       = new FieldApiView(fieldSymbol);

            Assert.Equal("protected int protectedField;", field.ToString());
        }
Beispiel #6
0
        public void MethodTestOneAttributeNoTypeParamsOneParam()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "StaticVoid");
            MethodApiView method       = new MethodApiView(methodSymbol);

            Assert.False(method.IsInterfaceMethod);
            Assert.True(method.IsStatic);
            Assert.False(method.IsVirtual);
            Assert.False(method.IsSealed);
            Assert.False(method.IsOverride);
            Assert.False(method.IsAbstract);
            Assert.False(method.IsExtern);
            Assert.Equal("void", method.ReturnType.Tokens[0].DisplayString);

            Assert.Single(method.Attributes);
            Assert.Equal("System", method.Attributes[0].Type.Tokens[0].DisplayString);
            Assert.Equal(".", method.Attributes[0].Type.Tokens[1].DisplayString);
            Assert.Equal("Diagnostics", method.Attributes[0].Type.Tokens[2].DisplayString);
            Assert.Equal(".", method.Attributes[0].Type.Tokens[3].DisplayString);
            Assert.Equal("ConditionalAttribute", method.Attributes[0].Type.Tokens[4].DisplayString);
            Assert.Single(method.Attributes[0].ConstructorArgs);
            Assert.Equal("\"DEBUG\"", method.Attributes[0].ConstructorArgs[0].Value);

            Assert.Single(method.Parameters);
            Assert.Empty(method.TypeParameters);
        }
Beispiel #7
0
        public void NamedTypeTestImplementsInterfaceStringRep()
        {
            var namedTypeSymbol          = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.ImplementingClass");
            NamedTypeApiView implementer = new NamedTypeApiView(namedTypeSymbol);

            Assert.Contains("public class ImplementingClass : TestLibrary.PublicInterface<int> {", implementer.ToString());
        }
        public void ParameterTestNoRefKindStringDefaultValue()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1", "TypeParamParamsMethod");
            MethodApiView method       = new MethodApiView(methodSymbol);

            Assert.Equal(2, method.Parameters.Length);

            ParameterApiView param = null;
            ParameterApiView num   = null;

            foreach (ParameterApiView p in method.Parameters)
            {
                if (p.Name.Equals("param"))
                {
                    param = p;
                }
                else
                {
                    num = p;
                }
            }

            Assert.False(param == null || num == null);
            Assert.Single(param.Type.Tokens);
            Assert.Equal("T", param.Type.Tokens[0].DisplayString);
            Assert.Equal(TypeReferenceApiView.TokenType.TypeArgument, param.Type.Tokens[0].Type);
            Assert.Equal("param", param.Name);
            Assert.Null(param.ExplicitDefaultValue);

            Assert.Equal("str", num.Name);
            Assert.Equal("hello", num.ExplicitDefaultValue);
        }
Beispiel #9
0
        public void NamedTypeTestInterfaceNoEventsNoFieldsSomeMethodsNoNamedTypesStringRep()
        {
            var namedTypeSymbol = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1");
            NamedTypeApiView publicInterface = new NamedTypeApiView(namedTypeSymbol);

            Assert.Contains("public interface PublicInterface<T> {", publicInterface.ToString());
        }
Beispiel #10
0
        public void NamedTypeTestClassSomeEventsSomeFieldsNoMethodsSomeNamedTypesStringRep()
        {
            var namedTypeSymbol          = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.SomeEventsSomeFieldsNoMethodsSomeNamedTypes");
            NamedTypeApiView publicClass = new NamedTypeApiView(namedTypeSymbol);

            Assert.Contains("public class SomeEventsSomeFieldsNoMethodsSomeNamedTypes {", publicClass.ToString());
        }
Beispiel #11
0
        public void PropertyTestHasSetterStringRep()
        {
            var             propertySymbol = (IPropertySymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "propertyBoth");
            PropertyApiView property       = new PropertyApiView(propertySymbol);

            Assert.Equal("public int propertyBoth { get; set; }", property.ToString());
        }
Beispiel #12
0
        public void EventTestCreation()
        {
            var eventSymbol = (IEventSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "PublicEvent");
            var e           = new EventApiView(eventSymbol);

            Assert.Equal("PublicEvent", e.Name);
        }
Beispiel #13
0
        public void NamedTypeTestDelegateStringRep()
        {
            var namedTypeSymbol             = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.publicDelegate");
            NamedTypeApiView publicDelegate = new NamedTypeApiView(namedTypeSymbol);

            Assert.Equal("public delegate int publicDelegate(int num = 10) { }", publicDelegate.ToString().Replace(Environment.NewLine, ""));
        }
Beispiel #14
0
        public void EventTestStringRep()
        {
            var eventSymbol = (IEventSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "PublicEvent");
            var e           = new EventApiView(eventSymbol);

            Assert.Equal("public event System.EventHandler PublicEvent;", e.ToString());
        }
Beispiel #15
0
        public void NamedTypeTestDelegate()
        {
            var namedTypeSymbol             = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.publicDelegate");
            NamedTypeApiView publicDelegate = new NamedTypeApiView(namedTypeSymbol);

            Assert.Equal("publicDelegate", publicDelegate.Name);
            Assert.Equal("delegate", publicDelegate.TypeKind);
        }
Beispiel #16
0
        public void TypeParameterTestCreation()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1", "TypeParamParamsMethod");
            MethodApiView method       = new MethodApiView(methodSymbol);

            Assert.Single(method.TypeParameters);
            Assert.Equal("T", method.TypeParameters[0].Name);
        }
Beispiel #17
0
        public void PropertyTestNoSetter()
        {
            var             propertySymbol = (IPropertySymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "propertyGet");
            PropertyApiView property       = new PropertyApiView(propertySymbol);

            Assert.Equal("propertyGet", property.Name);
            Assert.Equal("uint", property.Type.Tokens[0].DisplayString);
            Assert.False(property.HasSetMethod);
        }
Beispiel #18
0
        public void NamedTypeTestEnumDefaultUnderlyingTypeStringRep()
        {
            var namedTypeSymbol         = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "PublicEnum");
            NamedTypeApiView publicEnum = new NamedTypeApiView(namedTypeSymbol);

            string stringRep = publicEnum.ToString().Replace(Environment.NewLine, "");

            Assert.Equal("public enum PublicEnum {    One = 0,    Two = 1,    Three = 2,}", stringRep);
        }
Beispiel #19
0
        public void MethodTestOneAttributeNoTypeParamsOneParamStringRep()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "StaticVoid");
            MethodApiView method       = new MethodApiView(methodSymbol);

            string stringRep = method.ToString().Replace(Environment.NewLine, "");

            Assert.Equal("[System.Diagnostics.ConditionalAttribute(\"DEBUG\")]public static void StaticVoid(string[] args) { }", stringRep);
        }
Beispiel #20
0
        public void NamedTypeTestEnumDefaultUnderlyingType()
        {
            var namedTypeSymbol         = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "PublicEnum");
            NamedTypeApiView publicEnum = new NamedTypeApiView(namedTypeSymbol);

            Assert.Equal("PublicEnum", publicEnum.Name);
            Assert.Equal("enum", publicEnum.TypeKind);
            Assert.Equal("int", publicEnum.EnumUnderlyingType.Tokens[0].DisplayString);
        }
Beispiel #21
0
        public void MethodTestMultipleAttributesMultipleTypeParamsNoParamsStringRep()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1", "AttributesTypeParamsMethod");
            MethodApiView method       = new MethodApiView(methodSymbol);

            string stringRep = method.ToString().Replace(Environment.NewLine, "");

            Assert.Equal("[TestLibrary.CustomAttribute(\"Test\", Named = \"Param\")][TestLibrary.NewAttribute]int AttributesTypeParamsMethod<T, R>();", stringRep);
        }
Beispiel #22
0
        public void NamedTypeTestAutomaticConstructor()
        {
            var namedTypeSymbol          = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.SomeEventsSomeFieldsNoMethodsSomeNamedTypes");
            NamedTypeApiView publicClass = new NamedTypeApiView(namedTypeSymbol);

            foreach (MethodApiView method in publicClass.Methods)
            {
                Assert.NotEqual("SomeEventsSomeFieldsNoMethodsSomeNamedTypes", method.Name);
                Assert.NotEqual(".ctor", method.Name);
            }
        }
Beispiel #23
0
        public void NamedTypeTestInterfaceNoEventsNoFieldsSomeMethodsNoNamedTypes()
        {
            var namedTypeSymbol = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1");
            NamedTypeApiView publicInterface = new NamedTypeApiView(namedTypeSymbol);

            Assert.Equal("PublicInterface", publicInterface.Name);
            Assert.Equal("interface", publicInterface.TypeKind);
            Assert.Empty(publicInterface.Events);
            Assert.Empty(publicInterface.Fields);
            Assert.Equal(3, publicInterface.Methods.Length);
            Assert.Empty(publicInterface.NamedTypes);
        }
Beispiel #24
0
        public void NamedTypeTestClassSomeEventsSomeFieldsNoMethodsSomeNamedTypes()
        {
            var namedTypeSymbol          = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.SomeEventsSomeFieldsNoMethodsSomeNamedTypes");
            NamedTypeApiView publicClass = new NamedTypeApiView(namedTypeSymbol);

            Assert.Equal("SomeEventsSomeFieldsNoMethodsSomeNamedTypes", publicClass.Name);
            Assert.Equal("class", publicClass.TypeKind);
            Assert.Equal(2, publicClass.Events.Length);
            Assert.Equal(2, publicClass.Fields.Length);
            Assert.Empty(publicClass.Methods);
            Assert.Equal(2, publicClass.NamedTypes.Length);
        }
Beispiel #25
0
        public void FieldTestProtected()
        {
            var          fieldSymbol = (IFieldSymbol)TestResource.GetTestMember("TestLibrary.PublicClass", "protectedField");
            FieldApiView field       = new FieldApiView(fieldSymbol);

            Assert.Equal("protectedField", field.Name);
            Assert.Equal("int", field.Type.Tokens[0].DisplayString);
            Assert.Equal("protected", field.Accessibility);
            Assert.False(field.IsConstant);
            Assert.False(field.IsReadOnly);
            Assert.False(field.IsStatic);
            Assert.False(field.IsVolatile);
            Assert.Null(field.Value);
        }
Beispiel #26
0
        public void NamedTypeTestImplementsInterface()
        {
            var namedTypeSymbol          = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.ImplementingClass");
            NamedTypeApiView implementer = new NamedTypeApiView(namedTypeSymbol);

            Assert.Equal("ImplementingClass", implementer.Name);
            Assert.Equal("class", implementer.TypeKind);
            Assert.Single(implementer.Implementations);
            Assert.Equal("TestLibrary", implementer.Implementations[0].Tokens[0].DisplayString);
            Assert.Equal(".", implementer.Implementations[0].Tokens[1].DisplayString);
            Assert.Equal("PublicInterface", implementer.Implementations[0].Tokens[2].DisplayString);
            Assert.Equal("<", implementer.Implementations[0].Tokens[3].DisplayString);
            Assert.Equal("int", implementer.Implementations[0].Tokens[4].DisplayString);
            Assert.Equal(">", implementer.Implementations[0].Tokens[5].DisplayString);
        }
        public void ParameterTestSomeRefKindNoDefaultValue()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1", "RefKindParamMethod");
            MethodApiView method       = new MethodApiView(methodSymbol);

            Assert.Single(method.Parameters);

            var typeParts = method.Parameters[0].Type.Tokens;

            Assert.Equal(RefKind.Ref, method.Parameters[0].RefKind);
            Assert.Single(typeParts);
            Assert.Equal("string", typeParts[0].DisplayString);
            Assert.Equal(TypeReferenceApiView.TokenType.BuiltInType, typeParts[0].Type);
            Assert.Equal("str", method.Parameters[0].Name);
            Assert.Null(method.Parameters[0].ExplicitDefaultValue);
        }
Beispiel #28
0
        public void NamedTypeTestExplicitConstructor()
        {
            var namedTypeSymbol          = (INamedTypeSymbol)TestResource.GetTestMember("TestLibrary.PublicClass");
            NamedTypeApiView publicClass = new NamedTypeApiView(namedTypeSymbol);

            bool constructorFound = false;

            foreach (MethodApiView method in publicClass.Methods)
            {
                if (method.Name.Equals("PublicClass"))
                {
                    constructorFound = true;
                }
            }

            Assert.True(constructorFound);
        }
Beispiel #29
0
        public void MethodTestNoAttributesOneTypeParamMultipleParams()
        {
            var           methodSymbol = (IMethodSymbol)TestResource.GetTestMember("TestLibrary.PublicInterface`1", "TypeParamParamsMethod");
            MethodApiView method       = new MethodApiView(methodSymbol);

            Assert.True(method.IsInterfaceMethod);
            Assert.False(method.IsStatic);
            Assert.False(method.IsVirtual);
            Assert.False(method.IsSealed);
            Assert.False(method.IsOverride);
            Assert.True(method.IsAbstract);
            Assert.False(method.IsExtern);
            Assert.Equal("int", method.ReturnType.Tokens[0].DisplayString);

            Assert.Empty(method.Attributes);
            Assert.Equal(2, method.Parameters.Length);
            Assert.Single(method.TypeParameters);
        }