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 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 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 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 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 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 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 DotNetDelegate_ConvertFromType_Global() { //arrange XElement xmlElement = XElement.Parse("<member name='T:DataFileTest.DotNetDelegateTests.GlobalDelegate' />", LoadOptions.PreserveWhitespace); Type type = typeof(GlobalDelegate); //act DotNetType typeResult = DotNetType.FromVisualStudioXml(xmlElement); DotNetDelegate delegateResult = typeResult.ToDelegate(typeResult.Name); delegateResult.AddAssemblyInfo(type); //assert Assert.AreEqual(2, delegateResult.MethodName.Parameters.Count); Assert.AreEqual("a", delegateResult.MethodName.Parameters[0].Name); Assert.AreEqual("b", delegateResult.MethodName.Parameters[1].Name); Assert.AreEqual("System.Int32", delegateResult.MethodName.Parameters[0].FullTypeName); Assert.AreEqual("System.String", delegateResult.MethodName.Parameters[1].FullTypeName); Assert.AreEqual("System.EventHandler", delegateResult.MethodName.ReturnTypeName.FullName); }
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); }