示例#1
0
        private static MethodDeclarationSyntax GenerateCreateSut(
            ClassDeclarationSyntax classDeclaration,
            MethodInspector constructorInspector)
        {
            var methodBuilder = new MethodBuilder(GH.IdentifierToken("CreateSut"))
                                .Modifiers(Modifiers.Private);

            var constructorParameters = constructorInspector
                                        .Parameters
                                        .Select(p => SF.Argument(
                                                    EGH.MemberAccess(
                                                        EGH.ThisMemberAccess(
                                                            GH.Identifier(MockName(p.Name))
                                                            ),
                                                        GH.Identifier("Object")
                                                        )
                                                    )
                                                );

            methodBuilder.ArrowBody(
                EGH.Arrow(
                    EGH.CreateObject(
                        SF.IdentifierName(classDeclaration.Identifier),
                        constructorParameters.ToArray())));

            return(methodBuilder.Build());
        }
示例#2
0
        /// <summary>
        /// Build method generator from given method info.
        /// </summary>
        /// <param name="definition">Type where method is defined.</param>
        /// <param name="method">Method info defining method.</param>
        /// <param name="methodName">Name of defined method.</param>
        /// <param name="forceStatic">if set to <c>true</c> [force static].</param>
        /// <returns>Builder where method is built.</returns>
        private RuntimeMethodGenerator buildMethod(RuntimeTypeDefinition definition, MethodInfo method, string methodName, bool forceStatic = false)
        {
            var builder = new MethodBuilder(definition, methodName, forceStatic);

            builder.ThisObjectExpression = builder.DeclaringDefinitionConstant;
            builder.AdapterFor(method);
            return(builder.Build());
        }
示例#3
0
        public void Build_WhenHavingOperatorOverloading_ShouldGenerateOverloading()
        {
            var builder = new MethodBuilder("MyMethod")
                          .WithModifiers(Modifiers.Public, Modifiers.Static)
                          .WithOperatorOverloading(Operators.Equal)
                          .WithBody(BodyGenerator.Create());

            StringAssert.Contains("publicstaticMyMethodoperator==(){}", builder.Build().ToString());
        }
        public void TestWithParameter()
        {
            var builder = new MethodBuilder();

            builder.WithParameter();

            var result = builder.Build();

            Assert.AreEqual(1, result.Parameters.Length);
        }
        public void TestWithVisibility()
        {
            var builder = new MethodBuilder();

            builder.WithVisibility(AccessType.Internal);

            var result = builder.Build();

            Assert.AreEqual(AccessType.Internal, result.Visibility);
        }
        public void TestWithReturnType()
        {
            var builder = new MethodBuilder();

            builder.WithReturnType("FooBar");

            var result = builder.Build();

            Assert.AreEqual("FooBar", result.ReturnType);
        }
        public void TestIsVirtual()
        {
            var builder = new MethodBuilder();

            builder.IsVirtual(true);

            var result = builder.Build();

            Assert.AreEqual(true, result.IsVirtual);
        }
        public void TestIsStatic()
        {
            var builder = new MethodBuilder();

            builder.IsStatic(true);

            var result = builder.Build <MethodNode>();

            Assert.AreEqual(true, result.IsStatic);
        }
示例#9
0
        private void BuildAppDefault()
        {
            EntryPoint = AppAssembly.EntryPoint;
            if (EntryPoint != null)
            {
                MethodBuilder.Build(EntryPoint);
            }
            else
            {
                BuildLibrary();
            }

            BuildExposedTypes();
        }
示例#10
0
        public void Build_WhenGivingMethodName_CodeShouldContainName()
        {
            var builder = new MethodBuilder("MyMethod");

            Assert.IsTrue(builder.Build().ToString().Contains("MyMethod()"));
        }