Ejemplo n.º 1
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());
 }
Ejemplo n.º 2
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());
 }
Ejemplo 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());
 }
Ejemplo n.º 4
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
            });
        }
Ejemplo n.º 5
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());
 }
Ejemplo n.º 6
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());
 }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
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());
        }
Ejemplo n.º 9
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 TestStaticClass()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public static class TestClass",
                "    {",
                "        public static void Method()",
                "        {",
                "        }",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderExtTestUtils.TestStaticClassCompileUnit());
        }
        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());
        }
Ejemplo n.º 12
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());
 }
Ejemplo n.º 13
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());
 }
Ejemplo n.º 14
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());
        }
Ejemplo n.º 15
0
 public void TestIdentifiers()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    public class Class",
         "    {",
         "        private int @value;",
         "",
         "        private void @namespace()",
         "        {",
         "            @namespace();",
         "            this.@namespace();",
         "        }",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestIdentifiersCompileUnit());
 }
Ejemplo n.º 16
0
 public void TestComplexClassAndMethodSignature()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    public abstract class TestClass<T1, T2>",
         "        : BaseClass, IInterface",
         "        where T1 : A, new()",
         "        where T2 : IA, IB",
         "    {",
         "        private void GenericMethod<TA, TB>(TA a, TB b)",
         "            where TA : IEnumerable<TB>",
         "        {",
         "        }",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestComplexClassAndMethodSignatureCompileUnit());
 }
Ejemplo n.º 17
0
 public void TestAttributes()
 {
     string[] expected = new string[]
     {
         "namespace Test.Namespace",
         "{",
         "    [Attribute1]",
         "    [Attribute2(1, Value=2)]",
         "    public class TestClass<[Attribute2(1, Value=2)][Attribute1] T>",
         "    {",
         "        [Attribute1]",
         "        private int a;",
         "",
         "        public void Method([Attribute1] int a, [Attribute1][Attribute2(1, Value=2)] int b)",
         "        {",
         "        }",
         "    }",
         "}"
     };
     ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestAttributesCompileUnit());
 }
Ejemplo n.º 18
0
        public void TestNamespaces()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "  using System;",
                "  using System.CodeDom;",
                "}",
                "",
                "namespace Another",
                "{",
                "  using System;",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderTestUtils.TestNamespacesCompileUnit(),
                                           new GeneratorOptions()
            {
                IndentString = "  ", DoConsistencyChecks = false
            });
        }
        public void TestPropertiesAndMethodSignature()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public class TestClass",
                "    {",
                "        public virtual int Prop",
                "        {",
                "            get;",
                "            private set;",
                "        } = 1;",
                "",
                "        public void Method(int a, int b = 0)",
                "        {",
                "        }",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ProviderExtTestUtils.TestPropertiesAndMethodSignatureCompileUnit());
        }
Ejemplo n.º 20
0
        public void TestElseIfCS()
        {
            string[] expected = new string[]
            {
                "namespace Test.Namespace",
                "{",
                "    public class TestClass",
                "    {",
                "        public void Method()",
                "        {",
                "            if (true)",
                "            {",
                "                return;",
                "            }",
                "            if (1)",
                "            {",
                "                return;",
                "            }",
                "            else if (2)",
                "            {",
                "                return;",
                "            }",
                "            else if (3)",
                "            {",
                "                return;",
                "            }",
                "            else",
                "            {",
                "                return;",
                "            }",
                "        }",
                "    }",
                "}"
            };

            ProviderTestUtils.DoCSharpTest(expected, ReadabilityImprovementsTestUtils.TestElseIfCodeCompileUnit());
        }