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 DotNetMethod_FromXml_GenericParameter() { //arrange XElement xmlElement = XElement.Parse("<member name='M:Demo.DoubleGenericClass`2.op_Addition(`0,Demo.DoubleGenericClass{`0,`1})' />", LoadOptions.PreserveWhitespace); string expectedFullName = "Demo.DoubleGenericClass<T,U>.op_Addition"; //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); //assert Assert.AreEqual(expectedFullName, result.Name.FullName); }
public void DotNetMethod_FromAssembly_AbstractClassProtectedMethod() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.AbstractClass.MethodProtected()'></member>", LoadOptions.PreserveWhitespace); Type type = typeof(AbstractClass); MethodInfo methodInfo = type.GetDeclaredMethods().First(m => m.Name == "MethodProtected"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert Assert.AreEqual(MethodCategory.Protected, result.Category); }
public void DotNetMethodOperator_Equals_True() { //arrange string xml = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass,System.Int32)' />"; XElement element = XElement.Parse(xml, LoadOptions.PreserveWhitespace); DotNetMethodOperator a = (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(element); DotNetMethodOperator b = (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(element); //act bool result = (a == b); //assert Assert.IsTrue(result); }
public void DotNetMethod_FromAssembly_MethodOneGeneric_AddedToMethod() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.NormalClass.MethodOneGeneric``1' />", LoadOptions.PreserveWhitespace); string expectedFullName = "DataFilesTest.DotNetMethodTests.NormalClass.MethodOneGeneric<CustomA>"; Type type = typeof(NormalClass); MethodInfo methodInfo = type.GetMethods().First(m => m.Name == "MethodOneGeneric"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert Assert.AreEqual(expectedFullName, result.Name.FullName); }
public void DotNetMethodOperator_FromAssembly_ExplicitOperator() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodOperatorTests.ClassA.op_Explicit(DataFilesTest.DotNetMethodOperatorTests.ClassA)~System.Int64' />", LoadOptions.PreserveWhitespace); Type type = typeof(ClassA); MethodInfo methodInfo = type.GetMethods().First(m => m.Name == "op_Explicit"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert Assert.AreEqual("System.Single", result.MethodName.ReturnTypeName); Assert.AreEqual("DataFilesTest.DotNetMethodOperatorTests.ClassA", result.MethodName.Parameters[0].TypeName); }
public void DotNetMethod_FromAssembly_ParamComment() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.ParameterClass.MethodOneNormalParameter(System.Int32)'><param name='a'>Comments</param></member>", LoadOptions.PreserveWhitespace); Type type = typeof(ParameterClass); MethodInfo methodInfo = type.GetMethods().First(m => m.Name == "MethodOneNormalParameter"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert Assert.AreEqual(1, result.ParameterComments.Count); Assert.IsNotNull(result.ParameterComments[0]); }
public void DotNetMethodConstructor_FromAssembly_StaticConstructor() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodConstructorTests.ClassA.#cctor' />", LoadOptions.PreserveWhitespace); Type type = typeof(ClassA); ConstructorInfo constructorInfo = type.GetDeclaredConstructors().First(m => m.Name == ".cctor"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); DotNetMethodConstructor constructorResult = (result as DotNetMethodConstructor); constructorResult.AddAssemblyInfo(constructorInfo); //assert Assert.AreEqual(MethodCategory.Static, constructorResult.Category); }
public void DotNetMethodOperator_Equals_DifferentParameterCounts_False() { //arrange string xmlA = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass,System.Int32)' />"; string xmlB = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass)' />"; XElement elementA = XElement.Parse(xmlA, LoadOptions.PreserveWhitespace); XElement elementB = XElement.Parse(xmlB, LoadOptions.PreserveWhitespace); DotNetMethodOperator a = (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(elementA); DotNetMethodOperator b = (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(elementB); //act bool result = (a == b); //assert Assert.IsFalse(result); }
public void DotNetMethod_FromAssembly_ZeroParameters() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.ParameterClass.MethodZeroParameters' />", LoadOptions.PreserveWhitespace); string expectedFullName = "DataFilesTest.DotNetMethodTests.ParameterClass.MethodZeroParameters"; Type type = typeof(ParameterClass); MethodInfo methodInfo = type.GetMethods().First(m => m.Name == "MethodZeroParameters"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert Assert.AreEqual(expectedFullName, result.Name.FullName); Assert.AreEqual(0, result.MethodName.Parameters.Count); }
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 DotNetMethod_FromAssembly_ReturnNestedGeneric() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.NormalClass.MethodReturnNestedGeneric' />", LoadOptions.PreserveWhitespace); string expectedFullName = "DataFilesTest.DotNetMethodTests.NormalClass.MethodReturnNestedGeneric"; string expectedReturnFullName = "DataFilesTest.DotNetMethodTests.GenericOne<System.String>.NestedGeneric<System.Int32>"; Type type = typeof(NormalClass); MethodInfo methodInfo = type.GetMethods().First(m => m.Name == "MethodReturnNestedGeneric"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert Assert.AreEqual(expectedFullName, result.Name.FullName); Assert.AreEqual(expectedReturnFullName, result.MethodName.ReturnTypeName.FullName); }
public void DotNetMethod_FromAssembly_GenericClassGenericMethodOneParameterFromMethod() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.DotNetMethodTests.GenericOne`1.MethodMethodGeneric``1(``0)' />", LoadOptions.PreserveWhitespace); string expectedFullName = "DataFilesTest.DotNetMethodTests.GenericOne<T>.MethodMethodGeneric<A>"; Type type = typeof(GenericOne <>); MethodInfo methodInfo = type.GetMethods().First(m => m.Name == "MethodMethodGeneric"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert Assert.AreEqual(expectedFullName, result.Name.FullName); Assert.AreEqual(1, result.MethodName.Parameters.Count); Assert.AreEqual("A", result.MethodName.Parameters[0].FullTypeName); Assert.AreEqual("a", result.MethodName.Parameters[0].Name); }
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 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 DotNetMethod_FromAssembly_ExtensionMethodParameters() { //arrange XElement xmlElement = XElement.Parse("<member name='M:DataFilesTest.StaticTestClass.MethodExtension(System.String,System.String)'></member>", LoadOptions.PreserveWhitespace); Type type = typeof(StaticTestClass); MethodInfo methodInfo = type.GetDeclaredMethods().First(m => m.Name == "MethodExtension"); //act DotNetMethod result = DotNetMethod.FromVisualStudioXml(xmlElement); result.AddAssemblyInfo(methodInfo); //assert #if DATAFILES_TARGET_20 || DATAFILES_TARGET_30 Assert.AreEqual(MethodCategory.Static, result.Category); Assert.AreEqual(ParameterCategory.Normal, result.MethodName.Parameters[0].Category); #else Assert.AreEqual(MethodCategory.Extension, result.Category); Assert.AreEqual(ParameterCategory.Extension, result.MethodName.Parameters[0].Category); #endif Assert.AreEqual(ParameterCategory.Normal, result.MethodName.Parameters[1].Category); }
public void DotNetMethodOperator_Sort_OperatorOrder_RegardlessOfParameters() { //arrange string xmlA = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass,System.Int32)' />"; string xmlB = "<member name='M:MyNamespace.MyClass.op_Subtraction(MyNamespace.MyClass,System.Byte)' />"; string xmlC = "<member name='M:MyNamespace.MyClass.op_Multiply(MyNamespace.MyClass,System.Int64)' />"; string xmlD = "<member name='M:MyNamespace.MyClass.op_Division(MyNamespace.MyClass,System.Decimal)' />"; List <DotNetMethodOperator> list = new List <DotNetMethodOperator>() { (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlC, LoadOptions.PreserveWhitespace)), (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlA, LoadOptions.PreserveWhitespace)), (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlD, LoadOptions.PreserveWhitespace)), (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlB, LoadOptions.PreserveWhitespace)), }; //act list.Sort(); //assert Assert.AreEqual("op_Addition", list[0].Name.LocalName); Assert.AreEqual("op_Subtraction", list[1].Name.LocalName); Assert.AreEqual("op_Multiply", list[2].Name.LocalName); Assert.AreEqual("op_Division", list[3].Name.LocalName); }
public void DotNetMethodOperator_SortLINQ_OperatorOrder_ByParameters() { //arrange string xmlA = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass,System.Byte)' />"; string xmlB = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass,System.Decimal)' />"; string xmlC = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass,System.Int32)' />"; string xmlD = "<member name='M:MyNamespace.MyClass.op_Addition(MyNamespace.MyClass,System.Int64)' />"; List <DotNetMethodOperator> list = new List <DotNetMethodOperator>() { (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlC, LoadOptions.PreserveWhitespace)), (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlA, LoadOptions.PreserveWhitespace)), (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlD, LoadOptions.PreserveWhitespace)), (DotNetMethodOperator)DotNetMethod.FromVisualStudioXml(XElement.Parse(xmlB, LoadOptions.PreserveWhitespace)), }; //act list = list.OrderBy(x => x).ToList(); //assert Assert.AreEqual("System.Byte", list[0].MethodName.Parameters[1].TypeName); Assert.AreEqual("System.Decimal", list[1].MethodName.Parameters[1].TypeName); Assert.AreEqual("System.Int32", list[2].MethodName.Parameters[1].TypeName); Assert.AreEqual("System.Int64", list[3].MethodName.Parameters[1].TypeName); }
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); }