示例#1
0
        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);
        }
示例#2
0
        public void Perform()
        {
            var contractFile = new CodeFile("test.cs");
            var contractType = new DotNetType();

            contractFile.TypeList.Add(contractType);
            contractType.InheritAndImpls = new List <string> {
                "ICodeGenInterface"
            };

            var type = typeof(TestDb);

            contractType.AddMember(new GrpcOperation(type.GetMethod("Set")));
            contractType.AddMember(new GrpcOperation(type.GetMethod("Get")));
            contractType.AddMember(new GrpcOperation(type.GetMethod("DoWork")));
            contractType.AddMember(new GrpcOperation(type.GetMethod("Update")));

            var paras = new Dictionary <string, object>
            {
                ["config"] = new GrpcBuildConfig {
                    OutNamespace = "OutNamespace", OutServiceName = "RpcSrv"
                },
                ["file"] = contractFile
            };

            var tmpl = new TmplServiceContract {
                Session = paras
            };
            var t2 = new TmplServiceImplement {
                Session = paras
            };
            var t3 = new TmplServiceProxy()
            {
                Session = paras
            };

            tmpl.Initialize();
            t2.Initialize();
            t3.Initialize();

            tmpl.TransformText();
            t2.TransformText();
            Console.WriteLine(t3.TransformText());
        }
        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 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);
        }
示例#5
0
        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 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);
        }
示例#7
0
        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);
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }
示例#11
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);
        }
示例#12
0
        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);
        }
示例#14
0
        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);
        }
示例#15
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);
        }