public void DotNetMethod_FromAssembly_OptionalParameter() { //arrange XElement xmlTypeElement = XElement.Parse("<member name='T:DataFilesTest.DotNetMethodTests.NormalClass' />", LoadOptions.PreserveWhitespace); XElement xmlMemberElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.NormalClass.MethodOptional(System.Int32,System.String)' />", LoadOptions.PreserveWhitespace); Type type = typeof(NormalClass); DotNetType dotNetType = new DotNetType(new DotNetQualifiedClassName("DataFilesTest.DotNetMethodTests.NormalClass")); dotNetType.AddMember(DotNetMethod.FromVisualStudioXml(xmlMemberElement)); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); DotNetMethod result = dotNetType.Methods[0]; //assert Assert.AreEqual(2, result.MethodName.Parameters.Count); Assert.AreEqual("System.Int32", result.MethodName.Parameters[0].FullTypeName); Assert.AreEqual("a", result.MethodName.Parameters[0].Name); Assert.AreEqual(ParameterCategory.Optional, result.MethodName.Parameters[0].Category); Assert.AreEqual(5, result.MethodName.Parameters[0].DefaultValue); Assert.AreEqual("System.String", result.MethodName.Parameters[1].FullTypeName); Assert.AreEqual("b", result.MethodName.Parameters[1].Name); Assert.AreEqual(ParameterCategory.Optional, result.MethodName.Parameters[1].Category); Assert.IsNull(result.MethodName.Parameters[1].DefaultValue); Assert.AreEqual("System.String b = null", result.MethodName.Parameters[1].SignatureWithName); }
public void DotNetDocumentationFile_InheritComments_OneLevelDeep() { //arrange string xmlDocumentationFilename = Utilities.GetPathTo("data/DotNetDocumentationFile_InheritComments_OneLevelDeep.xml"); //act DotNetDocumentationFile xmlDocumentation = new DotNetDocumentationFile(xmlDocumentationFilename); DotNetType inheritanceTypeA = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceClassA"); inheritanceTypeA.AddAssemblyInfo(typeof(InheritanceClassA), inheritanceTypeA.Name); DotNetType inheritanceTypeB = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceClassB"); inheritanceTypeB.AddAssemblyInfo(typeof(InheritanceClassB), inheritanceTypeB.Name); DotNetType inheritanceTypeC = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceInterfaceC"); inheritanceTypeC.AddAssemblyInfo(typeof(InheritanceInterfaceC), inheritanceTypeC.Name); xmlDocumentation.ResolveInheritedComments(); //assert Assert.AreEqual(inheritanceTypeA.SummaryComments[0], inheritanceTypeB.SummaryComments[0]); Assert.AreEqual(inheritanceTypeA.Fields[0].SummaryComments[0], inheritanceTypeB.Fields[0].SummaryComments[0]); Assert.AreEqual(inheritanceTypeA.Properties[0].SummaryComments[0], inheritanceTypeB.Properties.First(p => p.Name.LocalName == "PropertyA").SummaryComments[0]); Assert.AreEqual(inheritanceTypeA.Events[0].SummaryComments[0], inheritanceTypeB.Events[0].SummaryComments[0]); Assert.AreEqual(inheritanceTypeA.Methods[0].SummaryComments[0], inheritanceTypeB.Methods.First(p => p.Name.LocalName == "MethodA").SummaryComments[0]); Assert.AreEqual(inheritanceTypeC.Properties[0].SummaryComments[0], inheritanceTypeB.Properties.First(p => p.Name.LocalName == "PropertyC").SummaryComments[0]); Assert.AreEqual(inheritanceTypeC.Methods[0].SummaryComments[0], inheritanceTypeB.Methods.First(p => p.Name.LocalName == "MethodC").SummaryComments[0]); }
public void DotNetType_Assembly_Enum() { //arrange Type type = typeof(EnumA); DotNetType dotNetType = new DotNetType(new DotNetQualifiedClassName("DataFilesTest.DotNetTypeTests.EnumA")); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.AreEqual(TypeCategory.Enum, dotNetType.Category); }
public void DotNetType_Assembly_Object() { //arrange Type type = typeof(System.Object); DotNetType dotNetType = new DotNetType(new DotNetQualifiedClassName("System.Object")); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.IsNull(dotNetType.BaseType); }
public void DotNetType_Assembly_ChildOfOneInterface() { //arrange Type type = typeof(ChildOfOneInterface); DotNetType dotNetType = new DotNetType(new DotNetQualifiedClassName("ChildOfOneInterface")); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.AreEqual(1, dotNetType.ImplementedInterfaces.Count); Assert.AreEqual("I1", dotNetType.ImplementedInterfaces[0].Name.LocalName); }
public void DotNetEvent_Assembly_Normal() { //arrange Type type = typeof(A); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:A'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetEvent.FromVisualStudioXml(XElement.Parse("<member name='E:A.EventA'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.AreEqual(1, dotNetType.Events.Count); Assert.AreEqual("System.EventHandler", dotNetType.Events[0].FullTypeName); }
public void DotNetType_Assembly_ChildOfObject() { //arrange Type type = typeof(ChildOfObject); DotNetType dotNetType = new DotNetType(new DotNetQualifiedClassName("ChildOfObject")); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.IsNotNull(dotNetType.BaseType); Assert.AreEqual(1, dotNetType.BaseType.Depth); Assert.AreEqual("System.Object", dotNetType.BaseType.Name.FullName); }
public void DotNetField_Assembly_ArrayTypeField() { //arrange Type type = typeof(C); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:DataFilesTest.DotNetFieldTests.C'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetField.FromVisualStudioXml(XElement.Parse("<member name='F:DataFilesTest.DotNetFieldTests.C.FieldArray'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.IsNotNull(dotNetType.Fields[0].TypeName); Assert.AreEqual("DataFilesTest.DotNetFieldTests.A[]", dotNetType.Fields[0].TypeName.FullName); }
public void DotNetDocumentationFile_InheritComments_NoBaseType() { //arrange string xmlDocumentationFilename = Utilities.GetPathTo("data/DotNetDocumentationFile_InheritComments_NoBaseType.xml"); //act DotNetDocumentationFile xmlDocumentation = new DotNetDocumentationFile(xmlDocumentationFilename); DotNetType inheritanceTypeA = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceClassA"); inheritanceTypeA.AddAssemblyInfo(typeof(InheritanceClassA), inheritanceTypeA.Name); xmlDocumentation.ResolveInheritedComments(); //assert Assert.AreEqual(CommentTag.InheritDoc, inheritanceTypeA.FloatingComments[0].Tag); }
public void DotNetField_Assembly_GetType() { //arrange Type type = typeof(A); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:A'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetField.FromVisualStudioXml(XElement.Parse("<member name='F:A.IntField'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.IsNotNull(dotNetType.Fields[0].TypeName); Assert.AreEqual("System.Int32", dotNetType.Fields[0].TypeName.FullName); }
public void DotNetReferenceClassGeneric_FromAssembly_Property() { //arrange Type type = typeof(ClassGeneric <>); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:DataFilesTest.DotNetReferenceClassGenericTests.ClassGeneric`1'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:DataFilesTest.DotNetReferenceClassGenericTests.ClassGeneric`1.PropertyA'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.IsNotNull(dotNetType.Properties[0].TypeName); Assert.AreEqual("Apple", dotNetType.Properties[0].TypeName.FullName); }
public void DotNetProperty_Assembly_NoSet() { //arrange Type type = typeof(AbstractClass); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:AbstractClass'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:AbstractClass.GetOnlyProperty'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.AreEqual("GetOnlyProperty", dotNetType.Properties[0].Name.LocalName); Assert.IsTrue(dotNetType.Properties[0].HasGetterMethod); Assert.IsFalse(dotNetType.Properties[0].HasSetterMethod); }
public void DotNetDocumentationFile_InheritComments_DifferentGenericAliases() { //arrange string xmlDocumentationFilename = Utilities.GetPathTo("data/DotNetDocumentationFile_InheritComments_DifferentGenericAliases.xml"); //act DotNetDocumentationFile xmlDocumentation = new DotNetDocumentationFile(xmlDocumentationFilename); DotNetType inheritanceTypeI = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceClassI"); inheritanceTypeI.AddAssemblyInfo(typeof(InheritanceClassI), inheritanceTypeI.Name); DotNetType inheritanceTypeJ = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceClassJ"); inheritanceTypeJ.AddAssemblyInfo(typeof(InheritanceClassJ), inheritanceTypeJ.Name); xmlDocumentation.ResolveInheritedComments(); //assert Assert.AreEqual(inheritanceTypeI.Methods[0].SummaryComments[0], inheritanceTypeJ.Methods[0].SummaryComments[0]); }
public void DotNetReferenceClassGeneric_FromAssembly_Indexer() { //arrange Type type = typeof(ClassGeneric <>); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:DataFilesTest.DotNetReferenceClassGenericTests.ClassGeneric`1'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:DataFilesTest.DotNetReferenceClassGenericTests.ClassGeneric`1.Item(`0)'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.IsTrue(dotNetType.Properties[0] is DotNetIndexer); DotNetIndexer indexer = (dotNetType.Properties[0] as DotNetIndexer); Assert.AreEqual(1, indexer.Parameters.Count()); Assert.AreEqual("Apple", indexer.Parameters[0].TypeName); }
public void DotNetReferenceClassGeneric_FromAssembly_ReturnType() { //arrange XElement typeXmlElement = XElement.Parse("<member name='T:DataFilesTest.DotNetReferenceClassGenericTests.ClassGeneric`1' />", LoadOptions.PreserveWhitespace); XElement methodXmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetReferenceClassGenericTests.ClassGeneric`1.MethodA' />", LoadOptions.PreserveWhitespace); Type type = typeof(ClassGeneric <>); //act DotNetType typeResult = DotNetType.FromVisualStudioXml(typeXmlElement); DotNetMethod methodResult = DotNetMethod.FromVisualStudioXml(methodXmlElement); typeResult.AddMember(methodResult); typeResult.AddAssemblyInfo(type, typeResult.Name); //assert Assert.AreEqual(MethodCategory.Normal, methodResult.Category); Assert.AreEqual("Apple", methodResult.MethodName.ReturnTypeName); }
public void DotNetProperty_Assembly_ProtectedGetPublicSet() { //arrange Type type = typeof(AbstractClass); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:AbstractClass'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:AbstractClass.ProtectedGetPublicSet'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.AreEqual("ProtectedGetPublicSet", dotNetType.Properties[0].Name.LocalName); Assert.AreEqual(FieldCategory.Normal, dotNetType.Properties[0].Category); Assert.IsTrue(dotNetType.Properties[0].HasGetterMethod); Assert.IsTrue(dotNetType.Properties[0].HasSetterMethod); Assert.AreEqual(AccessModifier.Protected, dotNetType.Properties[0].GetterMethod.AccessModifier); Assert.AreEqual(AccessModifier.Public, dotNetType.Properties[0].SetterMethod.AccessModifier); }
public void DotNetIndexer_Assembly_MatchesPermission() { //arrange Type type = typeof(A); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:DataFilesTest.DotNetIndexerTests.A'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:DataFilesTest.DotNetIndexerTests.A.Item(System.String)'></member>", LoadOptions.PreserveWhitespace))); dotNetType.AddAssemblyInfo(type, dotNetType.Name); XElement permissionElement = XElement.Parse("<permission cref='P:DataFilesTest.DotNetIndexerTests.A.Item(System.String)'></permission>", LoadOptions.PreserveWhitespace); DotNetCommentQualifiedLinkedGroup permissionComment = DotNetCommentQualifiedLinkedGroup.FromVisualStudioXml(permissionElement); //act DotNetIndexer indexerResult = dotNetType.Properties.OfType <DotNetIndexer>().Cast <DotNetIndexer>().First(); bool matchesResult = indexerResult.Matches(permissionComment); //assert Assert.IsTrue(matchesResult); }
public void DotNetMethod_FromAssembly_MethodOneGeneric_AddedToType() { //arrange XElement typeXmlElement = XElement.Parse("<member name='T:DataFilesTest.DotNetMethodTests.NormalClass' />", LoadOptions.PreserveWhitespace); XElement methodXmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.NormalClass.MethodOneGeneric``1' />", LoadOptions.PreserveWhitespace); string expectedFullName = "DataFilesTest.DotNetMethodTests.NormalClass.MethodOneGeneric<CustomA>"; Type type = typeof(NormalClass); //act DotNetType typeResult = DotNetType.FromVisualStudioXml(typeXmlElement); DotNetMethod methodResult = DotNetMethod.FromVisualStudioXml(methodXmlElement); typeResult.AddMember(methodResult); Assert.IsTrue(methodResult.MatchesSignature(type.GetDeclaredMethods().First(m => m.Name == "MethodOneGeneric"))); typeResult.AddAssemblyInfo(type, typeResult.Name); //assert Assert.AreEqual(expectedFullName, typeResult.Methods[0].Name.FullName); }
public void DotNetDocumentationFile_InheritComments_OrderOfInterfaces() { //arrange string xmlDocumentationFilename = Utilities.GetPathTo("data/DotNetDocumentationFile_InheritComments_OrderOfInterfaces.xml"); //act DotNetDocumentationFile xmlDocumentation = new DotNetDocumentationFile(xmlDocumentationFilename); DotNetType inheritanceTypeF = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceInterfaceF"); inheritanceTypeF.AddAssemblyInfo(typeof(InheritanceInterfaceF), inheritanceTypeF.Name); DotNetType inheritanceTypeG = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceInterfaceG"); inheritanceTypeG.AddAssemblyInfo(typeof(InheritanceInterfaceG), inheritanceTypeG.Name); DotNetType inheritanceTypeH = xmlDocumentation.Types.First(t => t.Name.LocalName == "InheritanceClassH"); inheritanceTypeH.AddAssemblyInfo(typeof(InheritanceClassH), inheritanceTypeH.Name); xmlDocumentation.ResolveInheritedComments(); //assert Assert.AreEqual(inheritanceTypeG.Properties[0].SummaryComments[0], inheritanceTypeH.Properties.First(p => p.Name.LocalName == "PropertyA").SummaryComments[0]); }
public void DotNetMethod_FromAssembly_RefParameter() { //arrange XElement xmlTypeElement = XElement.Parse("<member name='T:DataFilesTest.DotNetMethodTests.NormalClass' />", LoadOptions.PreserveWhitespace); XElement xmlMemberElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.NormalClass.MethodRef(System.Int32@)' />", LoadOptions.PreserveWhitespace); Type type = typeof(NormalClass); DotNetType dotNetType = new DotNetType(new DotNetQualifiedClassName("DataFilesTest.DotNetMethodTests.NormalClass")); dotNetType.AddMember(DotNetMethod.FromVisualStudioXml(xmlMemberElement)); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); DotNetMethod result = dotNetType.Methods[0]; //assert Assert.AreEqual(1, result.MethodName.Parameters.Count); Assert.AreEqual("System.Int32", result.MethodName.Parameters[0].FullTypeName); Assert.AreEqual("a", result.MethodName.Parameters[0].Name); Assert.AreEqual(ParameterCategory.Ref, result.MethodName.Parameters[0].Category); }
public void DotNetIndexer_Assembly_MultipleIndexers() { //arrange Type type = typeof(A); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:A'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:A.Item(System.String)'></member>", LoadOptions.PreserveWhitespace))); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:A.Item(System.Int32)'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.IsTrue(dotNetType.Properties[0] is DotNetIndexer); DotNetIndexer indexer = (dotNetType.Properties[0] as DotNetIndexer); Assert.AreEqual(1, indexer.Parameters.Count()); Assert.AreEqual("key", indexer.Parameters[0].Name); Assert.IsTrue(dotNetType.Properties[1] is DotNetIndexer); indexer = (dotNetType.Properties[1] as DotNetIndexer); Assert.AreEqual(1, indexer.Parameters.Count()); Assert.AreEqual("i", indexer.Parameters[0].Name); }
public void DotNetProperty_Assembly_ExplicitInterfaceImplementation_Properties() { //arrange Type type = typeof(ExplicitInterfaceImplementation); DotNetType dotNetType = DotNetType.FromVisualStudioXml(XElement.Parse("<member name='T:DataFilesTest.DotNetPropertyTests.ExplicitInterfaceImplementation'></member>", LoadOptions.PreserveWhitespace)); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:DataFilesTest.DotNetPropertyTests.ExplicitInterfaceImplementation.DataFilesTest#DotNetPropertyTests#IInterfaceA#SharedProperty'></member>", LoadOptions.PreserveWhitespace))); dotNetType.AddMember(DotNetProperty.FromVisualStudioXml(XElement.Parse("<member name='P:DataFilesTest.DotNetPropertyTests.ExplicitInterfaceImplementation.DataFilesTest#DotNetPropertyTests#IInterfaceB#SharedProperty'></member>", LoadOptions.PreserveWhitespace))); dotNetType.AddMember(DotNetMethod.FromVisualStudioXml(XElement.Parse("<member name='M:DataFilesTest.DotNetPropertyTests.ExplicitInterfaceImplementation.DataFilesTest#DotNetPropertyTests#IInterfaceA#SharedMethod(System.Int32)'></member>", LoadOptions.PreserveWhitespace))); dotNetType.AddMember(DotNetMethod.FromVisualStudioXml(XElement.Parse("<member name='M:DataFilesTest.DotNetPropertyTests.ExplicitInterfaceImplementation.DataFilesTest#DotNetPropertyTests#IInterfaceB#SharedMethod(System.Int32)'></member>", LoadOptions.PreserveWhitespace))); //act dotNetType.AddAssemblyInfo(type, dotNetType.Name); //assert Assert.AreEqual(2, dotNetType.Properties.Count); Assert.AreEqual("DataFilesTest.DotNetPropertyTests.IInterfaceA", dotNetType.Properties[0].Name.ExplicitInterface); Assert.AreEqual("DataFilesTest.DotNetPropertyTests.IInterfaceB", dotNetType.Properties[1].Name.ExplicitInterface); Assert.AreEqual("System.Int32", dotNetType.Properties[0].TypeName); Assert.AreEqual("System.Int32", dotNetType.Properties[1].TypeName); Assert.AreEqual(2, dotNetType.Methods.Count); Assert.AreEqual("DataFilesTest.DotNetPropertyTests.IInterfaceA", dotNetType.Methods[0].Name.ExplicitInterface); Assert.AreEqual("DataFilesTest.DotNetPropertyTests.IInterfaceB", dotNetType.Methods[1].Name.ExplicitInterface); Assert.AreEqual("System.Int32", dotNetType.Methods[0].MethodName.ReturnTypeName); Assert.AreEqual("System.Int32", dotNetType.Methods[1].MethodName.ReturnTypeName); }