public async Task CreateCodeLine()
        {
            // arrange
            var sb     = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await CodeLineBuilder.New()
            .SetLine("abcd;")
            .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot();
        }
        public async Task CreateConstructor()
        {
            // arrange
            var sb     = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await ConstructorBuilder.New()
            .SetTypeName("GetAbc")
            .AddCode(CodeLineBuilder.New().SetLine("return;"))
            .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot();
        }
예제 #3
0
        public async Task CreateMethod_With_ReturnType()
        {
            // arrange
            var sb = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await MethodBuilder.New()
                .SetName("GetAbc")
                .SetReturnType("Int32")
                .AddCode(CodeLineBuilder.New().SetLine("return;"))
                .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot();
        }
예제 #4
0
        public async Task CreateMethod_With_Two_Parameter()
        {
            // arrange
            var sb = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await MethodBuilder.New()
                .SetName("GetAbc")
                .AddCode(CodeLineBuilder.New().SetLine("return;"))
                .AddParameter(ParameterBuilder.New().SetName("abc").SetType("String"))
                .AddParameter(ParameterBuilder.New().SetName("def").SetType("String").SetDefault())
                .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot();
        }
예제 #5
0
        public async Task CreateExtensionMethod()
        {
            // arrange
            var sb = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await MethodBuilder.New()
                .SetName("GetAbc")
                .SetStatic()
                .AddParameter(ParameterBuilder.New().SetName("abc").SetType("this String"))
                .AddCode(CodeLineBuilder.New().SetLine("return;"))
                .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot();
        }
        public async Task CreateConstructor_With_AccessModifier(AccessModifier accessModifier)
        {
            // arrange
            var sb     = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await ConstructorBuilder.New()
            .SetTypeName("GetAbc")
            .SetAccessModifier(accessModifier)
            .AddCode(CodeLineBuilder.New().SetLine("return;"))
            .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot(
                new SnapshotNameExtension(
                    accessModifier.ToString()));
        }
예제 #7
0
        public async Task CreateMethod_With_Inheritance(Inheritance inheritance)
        {
            // arrange
            var sb = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await MethodBuilder.New()
                .SetName("GetAbc")
                .SetInheritance(inheritance)
                .AddCode(CodeLineBuilder.New().SetLine("return;"))
                .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot(
                new SnapshotNameExtension(
                    inheritance.ToString()));
        }
        public async Task CreateProperty_With_Custom_Getter_And_Custom_Setter()
        {
            // arrange
            var sb     = new StringBuilder();
            var writer = new CodeWriter(sb);

            // act
            await PropertyBuilder.New()
            .SetName("Foo")
            .SetType("Bar")
            .SetGetter(CodeLineBuilder.New().SetLine("return _value;"))
            .SetSetterAccessModifier(AccessModifier.Private)
            .SetSetter(CodeLineBuilder.New().SetLine("_value = value;"))
            .MakeSettable()
            .BuildAsync(writer);

            // assert
            sb.ToString().MatchSnapshot();
        }
예제 #9
0
 public CodeBlockBuilder AddEmptyLine()
 {
     _blockParts.Add(CodeLineBuilder.New());
     return(this);
 }
예제 #10
0
 public ConstructorBuilder AddCode(string value)
 {
     _lines.Add(CodeLineBuilder.New().SetLine(value));
     return(this);
 }
예제 #11
0
 public MethodBuilder AddCode(string value)
 {
     _lines.Add(CodeLineBuilder.New().SetLine(value));
     return(this);
 }