Exemplo n.º 1
0
        public void CanEmitMethodBody()
        {
            //-- arrange

            var method = new MethodMember(
                MemberVisibility.Public,
                "TestMethod",
                new MethodSignature {
                ReturnValue = new MethodParameter {
                    Type = typeof(string)
                }
            });

            method.Body = new BlockStatement(
                new ReturnStatement {
                Expression = new ConstantExpression {
                    Value = "ABC"
                }
            }
                );

            var emitterUnderTest = new MethodSyntaxEmitter(method);

            //-- act

            var actualSyntax = emitterUnderTest.EmitSyntax();

            //-- assert

            var expectedCode = "public string TestMethod() { return \"ABC\"; }";

            actualSyntax.Should().BeEquivalentToCode(expectedCode);
        }
Exemplo n.º 2
0
        public void CanEmitMethodDeclaration(
            string expectedCode,
            MemberVisibility visibility,
            MemberModifier modifier,
            Delegate signaturePrototype)
        {
            //-- arrange

            var method = new MethodMember(signaturePrototype.GetMethodInfo());

            method.Name       = "TestMethod";
            method.Visibility = visibility;
            method.Modifier   = modifier;

            var emitterUnderTest = new MethodSyntaxEmitter(method);

            //-- act

            var actualSyntax = emitterUnderTest.EmitSyntax();

            //-- assert

            actualSyntax.Should().BeEquivalentToCode(expectedCode);
        }