Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 4
0
        public void TestWithParameter()
        {
            var builder = new MethodBuilder();

            builder.WithParameter();

            var result = builder.Build();

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

            builder.WithVisibility(AccessType.Internal);

            var result = builder.Build();

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

            builder.WithReturnType("FooBar");

            var result = builder.Build();

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

            builder.IsVirtual(true);

            var result = builder.Build();

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

            builder.IsStatic(true);

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

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

            BuildExposedTypes();
        }
Ejemplo n.º 10
0
        public void Build_WhenGivingMethodName_CodeShouldContainName()
        {
            var builder = new MethodBuilder("MyMethod");

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