예제 #1
0
        public void Generated_namespace_with_usings_is_correct(bool useVB)
        {
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");
            var expected  = generator switch
            {
                CSharpGenerator => @"using static First = FirstNamespace;
                                     using Second.Namespace;
                                     using Third.Yes.No.Namespace;
                           
                                     namespace CodeNamespace
                                     {
                                     }",
                VBGenerator => @"Imports First = FirstNamespace
                                 Imports Second.Namespace
                                 Imports Third.Yes.No.Namespace
                    
                                 Namespace CodeNamespace
                                 End Namespace",
            };
            var code = Code.Create(CodeNamespace)
                       .Usings(
                new Using(FirstNamespace, FirstNamespaceAlias, true),
                SecondNamespace,
                ThirdNamespace);
            var actual = generator.Generate(code);


            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #2
0
 public void Generated_code_with_member_is_correct(bool useVB)
 {
     var memberName = "AMember";
     var cls        = new Class(ClassName)
                      .Member(new Property(memberName, "string"));
     var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");
     var expected  = generator switch
     {
         CSharpGenerator => @$ "public class {ClassName}
                             {{
예제 #3
0
        public void Generated_field_is_correct(bool useVB)
        {
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @$ "",
                VBGenerator => $@"",
                _ => throw new NotImplementedException()
            };
            //var actual = generator.OutputConstructor(ctor).GetOutput();

            //actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #4
0
        public void Generated_readonly_auto_property_is_correct(bool useVB)
        {
            var property  = new Property(PropertyName, "string", readOnly: true);
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");
            var expected  = generator switch
            {
                CSharpGenerator => @"public string PropertyName { get; }",
                VBGenerator => @"Public ReadOnly Property PropertyName As String",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputProperty(property).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #5
0
        public void Generated_expression_body_property_is_correct(bool useVB)
        {
            var property = new Property(PropertyName, "string", readOnly: true)
                           .GetterReturn(Expression.Value(42));
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @"public string PropertyName
                                        => 42;",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputProperty(property).GetOutput().NormalizeWhitespace();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #6
0
        public void Generated_class_is_correct(bool useVB)
        {
            var cls       = new Class(ClassName);
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");
            var expected  = generator switch
            {
                CSharpGenerator => @$ "public class {ClassName}
                                    {{
                                    }}",
                VBGenerator => $@"Public Class {ClassName}
                                  End Class",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputClass(cls).GetOutput().NormalizeWhitespace();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #7
0
        public void Generated_method_is_correct(bool useVB)
        {
            var method    = new Method(MethodName);
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @$ "public void {MethodName}()
                                    {{
                                    }}",
                VBGenerator => $@"Public Sub {MethodName}()
                                  End Sub",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputMethod(method).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #8
0
        public void Generated_constructor_is_correct(bool useVB)
        {
            var ctor      = new Constructor(new TypeRep("ClassName"));
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @"public ClassName()
                                     {
                                     }",
                VBGenerator => @"Public Sub New()
                                 End Sub",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputConstructor(ctor).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #9
0
        public void Generated_method_is_correct_with_returnType(bool useVB)
        {
            var method = new Method(MethodName)
                         .ReturnType("string");
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @$ "public string {MethodName}()
                                    {{
                                    }}",
                VBGenerator => $@"Public Function {MethodName}() As String
                                  End Function",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputMethod(method).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #10
0
        public void Generated_constructor_with_parameters_is_correct(bool useVB)
        {
            var ctor = new Constructor(new TypeRep("ClassName"))
                       .Parameter("abc", typeof(string))
                       .Parameter("def", typeof(int));
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @$ "public ClassName(string abc, int def)
                                    {{
                                    }}",
                VBGenerator => $@"Public Sub New(abc As String, def As Integer)
                                  End Sub",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputConstructor(ctor).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #11
0
        public void Generated_method_with_modifiers_is_correct(bool useVB)
        {
            var method = new Method(MethodName, modifiers: MemberModifiers.Partial | MemberModifiers.Override)
                         .ReturnType("string")
                         .Parameter("value", typeof(int))
                         .Parameter("s", typeof(string));
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @$ "public partial override string {MethodName}(int value, string s)
                                    {{
                                    }}",
                VBGenerator => $@"Public Partial Overrides Function {MethodName}(value As Integer, s As String) As String
                                  End Function",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputMethod(method).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #12
0
        public void Generated_method_with_parameters_is_correct(bool useVB)
        {
            var method = new Method(MethodName)
                         .Parameter("value", typeof(int))
                         .Parameter("s", typeof(string));
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @$ "public void {MethodName}(int value, string s)
                                    {{
                                    }}",
                VBGenerator => $@"Public Sub {MethodName}(value As Integer, s As String)
                                  End Sub",

                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputMethod(method).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #13
0
        public void Generated_constructor_with_this_and_argument_is_correct(bool useVB)
        {
            var ctor = new Constructor(new TypeRep("Abc"))
                       .ThisCall(Expression.Value(42));
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @"public Abc()
                                     : this(42)
                                     {
                                     }",
                VBGenerator => @"Public Sub New()
                                     Me.New(42)
                                 End Sub",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputConstructor(ctor).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }
예제 #14
0
        public void Generated_full_property_is_correct(bool useVB)
        {
            var property = new Property(PropertyName, "string")
                           .GetterStatements(Expression.AssignVar("y", "int", Expression.Value(11)))
                           .GetterReturn(Expression.Value(5))
                           .SetterStatements(Expression.AssignVar("x", "int", Expression.Value(7)));
            var generator = GeneratorBase.Generator(useVB ? "VisualBasic" : "C#");;
            var expected  = generator switch
            {
                CSharpGenerator => @"public string PropertyName
                                     {
                                        get
                                        {
                                           int y = 11;
                                           return 5;
                                        }
                                        set
                                        {
                                           int x = 7;
                                        }
                                     }",
                VBGenerator => $@"Public Property PropertyName As String
                                      Get
                                          Dim y As Integer = 11
                                          Return 5
                                      End Get
                                  
                                      Set(Value As String)
                                          Dim x As Integer = 7
                                      End Set
                                  End Property",
                _ => throw new NotImplementedException()
            };

            var actual = generator.OutputProperty(property).GetOutput();

            actual.NormalizeWhitespace().Should().Be(expected.NormalizeWhitespace());
        }