Exemplo n.º 1
0
        public void TestNamespaceImportsVB()
        {
            string[] expected =
            {
                "Imports N1.N2",
                "Imports N1.N2.N3.N4",
                "Imports System",
                "",
                "Namespace N1",
                "    Public Class TestClass",
                "        Public Sub Method()",
                "            New A()",
                "            New N2.N3.B()",
                "            New C()",
                "            Console.WriteLine()",
                "            New CodeDomExtTests.TestClasses.BaseClass()",
                "            New [namespace].object.class()",
                "        End Sub",
                "    End Class",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ReadabilityImprovementsTestUtils.TestTypeWithImport(),
                                                new GeneratorOptions()
            {
                DoConsistencyChecks = false, AlwaysUseFullyQualifiedName = false
            });
        }
Exemplo n.º 2
0
        public void TestElseIfVB()
        {
            string[] expected =
            {
                "Namespace Test.Namespace",
                "    Public Class TestClass",
                "        Public Sub Method()",
                "            If True Then",
                "                Return",
                "            End If",
                "            If 1 Then",
                "                Return",
                "            ElseIf 2 Then",
                "                Return",
                "            ElseIf 3 Then",
                "                Return",
                "            Else",
                "                Return",
                "            End If",
                "        End Sub",
                "    End Class",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ReadabilityImprovementsTestUtils.TestElseIfCodeCompileUnit());
        }
Exemplo n.º 3
0
 public void TestDirective()
 {
     string[] expected =
     {
         "#region Compile unit region",
         "namespace Test.Namespace",
         "{",
         "    #region Class region",
         "    public class TestClass",
         "    {",
         "        #region Fields region",
         "        private int a;",
         "",
         "        private int b;",
         "        #endregion",
         "",
         "        public void Method()",
         "        {",
         "            #region region a",
         "            #region region b",
         "            a = b;",
         "            return a;",
         "            #endregion",
         "            #endregion",
         "        }",
         "    }",
         "    #endregion",
         "}",
         "#endregion"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestDirectiveCompileUnit());
 }
Exemplo n.º 4
0
 public void TestSnippet()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    public class TestClass",
         "    {",
         "        public void SnippetMember()",
         "        {",
         "        ",
         "        }",
         "",
         "        public void Method()",
         "        {",
         "            SnippetStatement",
         "                on multiple lines",
         "            i = snippet expression;",
         "            i2 = multiline",
         "                snippet expression;",
         "        }",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestSnippetCompileUnit());
 }
Exemplo n.º 5
0
 public void TestStatementsAndExpressions()
 {
     string[] expected =
     {
         "Namespace Test.Namespace",
         "    Public Class TestClass",
         "        Public Sub Method()",
         "            New [Class]() {New A(), New A(Me.field, arg)}",
         "            New Double((arg * avar) - 1) {}",
         "            avar(CType(5.5F, Integer), Math.Abs(-2))",
         "            CType(Nothing, UInteger)",
         "            GetType(Integer)",
         "            Dim i As Integer = 0",
         "            While i < 10",
         "                Try",
         "                    AddHandler MyBase.EventsHolder.AnEvent, AddressOf Me.Method",
         "                Catch e As Exception",
         "                Catch e As AnotherException",
         "                End Try",
         "                i = i + 1",
         "            End While",
         "        End Sub",
         "    End Class",
         "End Namespace"
     };
     ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestStatementsAndExpressionsCompileUnit());
 }
Exemplo n.º 6
0
 public void TestStatementsAndExpressions()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    public class TestClass",
         "    {",
         "        public void Method()",
         "        {",
         "            new Class[] {new A(), new A(this.field, arg)};",
         "            new double[arg * avar];",
         "            avar[(int) 5.5f, Math.Abs(-2)];",
         "            default(uint);",
         "            typeof(int);",
         "            for (int i = 0; i < 10; i = i + 1)",
         "            {",
         "                try",
         "                {",
         "                    base.EventsHolder.AnEvent += new Action(this.Method);",
         "                }",
         "                catch (Exception e)",
         "                {",
         "                }",
         "                catch (AnotherException e)",
         "                {",
         "                }",
         "            }",
         "        }",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestStatementsAndExpressionsCompileUnit());
 }
Exemplo n.º 7
0
 public void TestSimpleStruct()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    internal struct TestClass",
         "    {",
         "        private int count;",
         "",
         "        private int increment;",
         "",
         "        public TestClass(int count, int increment)",
         "        {",
         "            this.count = count;",
         "            this.increment = increment;",
         "        }",
         "",
         "        internal int IncrementAndGet()",
         "        {",
         "            count = count + increment;",
         "            return count;",
         "        }",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestSimpleStructCompileUnit());
 }
Exemplo n.º 8
0
        public void TestDirective()
        {
            string[] expected =
            {
                "#Region \"Compile unit region\"",
                "Option Strict Off",
                "Option Explicit On",
                "Option Infer On",
                "",
                "Namespace Test.Namespace",
                "    #Region \"Class region\"",
                "    Public Class TestClass",
                "        #Region \"Fields region\"",
                "        Private a As Integer",
                "",
                "        Private b As Integer",
                "        #End Region",
                "",
                "        Public Sub Method()",
                "            #Region \"region a\"",
                "            #Region \"region b\"",
                "            a = b",
                "            Return a",
                "            #End Region",
                "            #End Region",
                "        End Sub",
                "    End Class",
                "    #End Region",
                "End Namespace",
                "#End Region"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestDirectiveCompileUnit(), addOptions: false);
        }
Exemplo n.º 9
0
        public void TestNamespaceImportsCS()
        {
            string[] expected =
            {
                "namespace N1",
                "{",
                "    using N1.N2;",
                "    using N1.N2.N3.N4;",
                "    using System;",
                "",
                "    public class TestClass",
                "    {",
                "        public void Method()",
                "        {",
                "            new A();",
                "            new N2.N3.B();",
                "            new C();",
                "            Console.WriteLine();",
                "            new CodeDomExtTests.TestClasses.BaseClass();",
                "            new @namespace.@object.@class();", //N1.namespace.object.class
                "        }",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ReadabilityImprovementsTestUtils.TestTypeWithImport(),
                                           new GeneratorOptions()
            {
                DoConsistencyChecks = false, AlwaysUseFullyQualifiedName = false
            });
        }
Exemplo n.º 10
0
 public void TestSimpleClass()
 {
     string[] expected = new string[]
     {
         "//this is a comment",
         "/// this is a doc comment",
         "namespace Test.Namespace",
         "{",
         "    /// this is a doc comment",
         "    /// this is a doc comment",
         "    internal class TestClass",
         "    {",
         "        private int count;",
         "",
         "        private protected int increment;",
         "",
         "        public int Prop",
         "        {",
         "            get",
         "            {",
         "                return increment;",
         "            }",
         "            set",
         "            {",
         "                increment = value;",
         "            }",
         "        }",
         "",
         "        public virtual int Prop2",
         "        {",
         "            set",
         "            {",
         "                throw new Exception();",
         "            }",
         "        }",
         "",
         "        protected TestClass(int count, int increment)",
         "        {",
         "            this.count = count;",
         "            this.increment = increment;",
         "        }",
         "",
         "        //this is a comment",
         "        protected internal int IncrementAndGet()",
         "        {",
         "            //this is a comment",
         "            count = count + increment;",
         "            return count;",
         "        }",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestSimpleClassCompileUnit());
 }
Exemplo n.º 11
0
        public void TestTypesAndFieldMemberAttributes()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public class TestClass",
                "    {",
                "        private int i;",
                "",
                "        public uint ui;",
                "",
                "        protected short s;",
                "",
                "        internal ushort us;",
                "",
                "        protected internal long l;",
                "",
                "        private protected ulong ul;",
                "",
                "        private static bool bo;",
                "",
                "        private const byte b = 123;",
                "",
                "        private sbyte sb;",
                "",
                "        private char c;",
                "",
                "        private new decimal dec;",
                "",
                "        private float f;",
                "",
                "        private double d = 0;",
                "",
                "        private object obj = new object();",
                "",
                "        private string str;",
                "",
                "        private int? nullableInt;",
                "",
                "        private System.Console console;",
                "",
                "        private System.Collections.Generic.IDictionary<int, System.Collections.Generic.IList<double>> dictionary;",
                "",
                "        private double[,] array;",
                "",
                "        private System.DateTime someDate;",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestTypesAndFieldMemberAttributesCompileUnit());
        }
Exemplo n.º 12
0
        public void TestMethodSignature()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public class TestClass",
                "    {",
                "        static TestClass()",
                "        {",
                "        }",
                "",
                "        public TestClass()",
                "            : this(0)",
                "        {",
                "        }",
                "",
                "        private TestClass(int i)",
                "        {",
                "        }",
                "",
                "        private protected TestClass(int a, double b)",
                "            : base(a, b)",
                "        {",
                "        }",
                "",
                "        public static int Main(string[] args)",
                "        {",
                "        }",
                "",
                "        protected abstract void Method();",
                "",
                "        public virtual void Method()",
                "        {",
                "        }",
                "",
                "        public override void Method()",
                "        {",
                "        }",
                "",
                "        public void Method(int a, int b)",
                "        {",
                "        }",
                "",
                "        public static void Method()",
                "        {",
                "        }",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestMethodSignatureCompileUnit());
        }
Exemplo n.º 13
0
        public void TestTypesAndFieldMemberAttributes()
        {
            string[] expected =
            {
                "Namespace Test.Namespace",
                "    Public Class TestClass",
                "        Private i As Integer",
                "",
                "        Public ui As UInteger",
                "",
                "        Protected s As Short",
                "",
                "        Friend us As UShort",
                "",
                "        Protected Friend l As Long",
                "",
                "        Private Protected ul As ULong",
                "",
                "        Private Shared bo As Boolean",
                "",
                "        Private Const b As Byte = 123",
                "",
                "        Private sb As SByte",
                "",
                "        Private c As Char",
                "",
                "        Private Shadows dec As Decimal",
                "",
                "        Private f As Single",
                "",
                "        Private d As Double = 0",
                "",
                "        Private obj As Object = New Object()",
                "",
                "        Private str As String",
                "",
                "        Private nullableInt As Integer?",
                "",
                "        Private console As System.Console",
                "",
                "        Private dictionary As System.Collections.Generic.IDictionary(Of Integer, System.Collections.Generic.IList(Of Double))",
                "",
                "        Private array As Double(,)",
                "",
                "        Private someDate As Date",
                "    End Class",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestTypesAndFieldMemberAttributesCompileUnit());
        }
        public void TestModule()
        {
            string[] expected =
            {
                "Namespace Test.Namespace",
                "    Public Module TestClass",
                "        Public Sub Method()",
                "        End Sub",
                "    End Module",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ProviderExtTestUtils.TestStaticClassCompileUnit());
        }
Exemplo n.º 15
0
 public void TestPrimitives()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    public class TestClass",
         "    {",
         "        private short s = (short) 2;",
         "",
         "        private uint ui = 2U;",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestPrimitivesCompileUnit());
 }
        public void TestPropertiesAndMethodSignature()
        {
            string[] expected =
            {
                "Namespace Test.Namespace",
                "    Public Class TestClass",
                "        Public Overridable Property Prop As Integer = 1",
                "",
                "        Public Sub Method(ByVal a As Integer, Optional ByVal b As Integer = 0)",
                "        End Sub",
                "    End Class",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ProviderExtTestUtils.TestPropertiesAndMethodSignatureCompileUnit());
        }
Exemplo n.º 17
0
 public void TestDelegateAndEvent()
 {
     string[] expected =
     {
         "Namespace Test.Namespace",
         "    Partial Public Class TestClass",
         "        Protected Delegate Function TestDelegate(ByVal a As Integer, ByVal b As Integer) As Integer",
         "",
         "        Protected Delegate Sub TestDelegate2()",
         "",
         "        Protected Shared Event TestEvent As TestDelegate2",
         "    End Class",
         "End Namespace"
     };
     ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestDelegateAndEventCompileUnit());
 }
Exemplo n.º 18
0
 public void TestInterface()
 {
     string[] expected =
     {
         "Namespace Test.Namespace",
         "    Public Interface IInterface",
         "        Inherits IAnotherInterface",
         "",
         "        Function GenericMethod(Of TA As IEnumerable(Of TB), TB)(ByVal a As TA, ByVal b As TB) As Integer",
         "",
         "        Sub AnotherMethod()",
         "    End Interface",
         "End Namespace"
     };
     ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestInterfaceCompileUnit());
 }
Exemplo n.º 19
0
 public void TestComplexClassAndMethodSignature()
 {
     string[] expected =
     {
         "Namespace Test.Namespace",
         "    Public MustInherit Class TestClass(Of T1 As {A, New}, T2 As {IA, IB})",
         "        Inherits BaseClass",
         "        Implements IInterface",
         "",
         "        Private Sub GenericMethod(Of TA As IEnumerable(Of TB), TB)(ByVal a As TA, ByVal b As TB)",
         "        End Sub",
         "    End Class",
         "End Namespace"
     };
     ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestComplexClassAndMethodSignatureCompileUnit());
 }
Exemplo n.º 20
0
 public void TestIdentifiers()
 {
     string[] expected = new string[]
     {
         "Namespace Test.Namespace",
         "    Public Class [Class]",
         "        Private value As Integer",
         "",
         "        Private Sub [namespace]()",
         "            [namespace]()",
         "            Me.namespace()",
         "        End Sub",
         "    End Class",
         "End Namespace"
     };
     ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestIdentifiersCompileUnit());
 }
Exemplo n.º 21
0
        public void TestEnum()
        {
            string[] expected =
            {
                "Namespace Test.Namespace",
                "    Public Enum TestEnum",
                "        A",
                "        B",
                "        C = 5",
                "        <System.SerializableAttribute>",
                "        D",
                "    End Enum",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestEnumCompileUnit());
        }
        public void TestStaticClass()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public static class TestClass",
                "    {",
                "        public static void Method()",
                "        {",
                "        }",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderExtTestUtils.TestStaticClassCompileUnit());
        }
Exemplo n.º 23
0
 public void TestSimpleClass()
 {
     string[] expected =
     {
         "'this is a comment",
         "''' this is a doc comment",
         "Namespace Test.Namespace",
         "    ''' this is a doc comment",
         "    ''' this is a doc comment",
         "    Friend Class TestClass",
         "        Private count As Integer",
         "",
         "        Private Protected increment As Integer",
         "",
         "        Public Property Prop As Integer",
         "            Get",
         "                Return increment",
         "            End Get",
         "            Set",
         "                increment = Value",
         "            End Set",
         "        End Property",
         "",
         "        Public Overridable WriteOnly Property Prop2 As Integer",
         "            Set",
         "                Throw New Exception()",
         "            End Set",
         "        End Property",
         "",
         "        Protected Sub New(ByVal count As Integer, ByVal increment As Integer)",
         "            Me.count = count",
         "            Me.increment = increment",
         "        End Sub",
         "",
         "        'this is a comment",
         "        Protected Friend Function IncrementAndGet() As Integer",
         "            'this is a comment",
         "            count = count + increment",
         "            Return count",
         "        End Function",
         "    End Class",
         "End Namespace"
     };
     ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestSimpleClassCompileUnit());
 }
        public void TestExpressionsAndStatements()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public class TestClass",
                "    {",
                "        public void Method()",
                "        {",
                "            (i > 0) ? i : null;",
                "            do",
                "            {",
                "                a <<= 2;",
                "            } while (!true);",
                "            lambda = (int i, int j) =>",
                "            {",
                "                b ?? 0;",
                "                new A()",
                "                {",
                "                    Prop = 0,",
                "                    Prop2 = 2",
                "                };",
                "            };",
                "            while (false)",
                "            {",
                "                i++;",
                "                break;",
                "            }",
                "            using (var stream = new Stream())",
                "            {",
                "                var matrix = new int[,] {{1, 1}, {1, 1}};",
                "            }",
                "            foreach (int i in collection)",
                "            {",
                "                new int[1, 1] {{1}};",
                "                new int[1, 1];",
                "            }",
                "        }",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderExtTestUtils.TestExpressionsAndStatementsCompileUnit());
        }
Exemplo n.º 25
0
 public void TestInterface()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    public interface IInterface",
         "        : IAnotherInterface",
         "    {",
         "        int GenericMethod<TA, TB>(TA a, TB b)",
         "            where TA : IEnumerable<TB>;",
         "",
         "        void AnotherMethod();",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestInterfaceCompileUnit());
 }
Exemplo n.º 26
0
 public void TestDelegateAndEvent()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    public partial class TestClass",
         "    {",
         "        protected delegate int TestDelegate(int a, int b);",
         "",
         "        protected delegate void TestDelegate2();",
         "",
         "        protected static event TestDelegate2 TestEvent;",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestDelegateAndEventCompileUnit());
 }
Exemplo n.º 27
0
 public void TestAttributes()
 {
     string[] expected =
     {
         "Namespace Test.Namespace",
         "    <Attribute1> _",
         "    <Attribute2(1, Value:=2)> _",
         "    Public Class TestClass(Of T)",
         "        <Attribute1>",
         "        Private a As Integer",
         "",
         "        Public Sub Method(<Attribute1> ByVal a As Integer, <Attribute1><Attribute2(1, Value:=2)> ByVal b As Integer)",
         "        End Sub",
         "    End Class",
         "End Namespace"
     };
     ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestAttributesCompileUnit());
 }
Exemplo n.º 28
0
        public void TestEnum()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public enum TestEnum",
                "    {",
                "        A,",
                "        B,",
                "        C = 5,",
                "        [System.SerializableAttribute]",
                "        D",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestEnumCompileUnit());
        }
Exemplo n.º 29
0
        public void TestMethodSignature()
        {
            string[] expected =
            {
                "Namespace Test.Namespace",
                "    Public Class TestClass",
                "        Shared Sub New()",
                "        End Sub",
                "",
                "        Public Sub New()",
                "            Me.New(0)",
                "        End Sub",
                "",
                "        Private Sub New(ByVal i As Integer)",
                "        End Sub",
                "",
                "        Private Protected Sub New(ByVal a As Integer, ByVal b As Double)",
                "            MyBase.New(a, b)",
                "        End Sub",
                "",
                "        Public Shared Function Main(ByVal cmdArgs() As String) As Integer",
                "        End Function",
                "",
                "        Protected MustOverride Sub Method()",
                "",
                "        Public Overridable Sub Method()",
                "        End Sub",
                "",
                "        Public Overrides Sub Method()",
                "        End Sub",
                "",
                "        Public Sub Method(ByVal a As Integer, ByVal b As Integer)",
                "        End Sub",
                "",
                "        Public Shared Sub Method()",
                "        End Sub",
                "    End Class",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestMethodSignatureCompileUnit());
        }
Exemplo n.º 30
0
        public void TestNamespaces()
        {
            string[] expected = new string[]
            {
                "Option Strict Off",
                "Option Explicit On",
                "Option Infer On",
                "",
                "Imports System",
                "Imports System.CodeDom",
                "",
                "Namespace Test.Namespace",
                "End Namespace",
                "",
                "Namespace Another",
                "End Namespace"
            };

            ProviderTestUtils.DoVisualBasicTest(expected, ProviderTestUtils.TestNamespacesCompileUnit(), addOptions: false);
        }