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 }); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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); }
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 }); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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()); }
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); }