using System.CodeDom;
using System.CodeDom.Compiler;
using System.Globalization;
+using System.IO;
using Microsoft.CSharp;
{
string code = GenerateDerivedType (Options);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-#if NET_2_0
"internal abstract class Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#else
- "abstract class Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#endif
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal event int Click;{0}" +
-#else
- " /*FamANDAssem*/ internal event int Click;{0}" +
-#endif
"}}{0}", NewLine), code);
}
"}}{0}", NewLine), code);
}
+ [Test]
+ public void AbstractPropertyTest ()
+ {
+ string code = GenerateAbstractProperty (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public abstract class Test1 {{{0}" +
+ " {0}" +
+ " public abstract string Name {{{0}" +
+ " get;{0}" +
+ " set;{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), code);
+ }
+
+ [Test]
+ public void StaticPropertyTest ()
+ {
+ string code = GenerateStaticProperty (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public class Test1 {{{0}" +
+ " {0}" +
+ " public static string Name {{{0}" +
+ " set {{{0}" +
+ " }}{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), code);
+ }
+
[Test]
public override void PropertyMembersTypeTest1 ()
{
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Name {{{0}" +
-#else
- " internal int Name {{{0}" +
-#endif
" set {{{0}" +
" }}{0}" +
" }}{0}" +
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Name {{{0}" +
-#else
- " internal int Name {{{0}" +
-#endif
" }}{0}" +
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
- " public virtual int Something([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int index) {{{0}" +
+ " public virtual int Something([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int ) {{{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Execute() {{{0}" +
-#else
- " internal int Execute() {{{0}" +
-#endif
" }}{0}" +
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Execute() {{{0}" +
-#else
- " internal int Execute() {{{0}" +
-#endif
" }}{0}" +
"}}{0}", NewLine), code);
}
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void MethodParamArrayAttribute ()
+ {
+ string code = GenerateMethodParamArrayAttribute (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public class Test1 {{{0}" +
+ " {0}" +
+ " public virtual int Something([A()] [B()] params out object value, [C()] ref int ) {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), code);
+ }
+
[Test]
public override void MethodReturnTypeAttributes ()
{
" {0}" +
" [A()]{0}" +
" [B()]{0}" +
+ " params{0}" +
" [return: C(A1=false, A2=true)]{0}" +
" [return: D()]{0}" +
+ " return: params{0}" +
" public virtual int Execute() {{{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" [B()]{0}" +
-#endif
" static Test1() {{{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
"public class Test1{0}" +
"{{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" [B()]{0}" +
-#endif
" static Test1(){0}" +
" {{{0}" +
" }}{0}" +
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public class Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" public static int Main() {{{0}" +
-#else
- " public static void Main() {{{0}" +
-#endif
" Test.InnerType x;{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
}
#endregion Override implementation of CodeGeneratorFromTypeTestBase
+
+ [Test]
+ public void EscapePropertyName ()
+ {
+ CodeNamespace cns = new CodeNamespace ();
+ CodeTypeDeclaration ctd = new CodeTypeDeclaration ("TestType");
+ CodeMemberProperty f = new CodeMemberProperty ();
+ f.Type = new CodeTypeReference (typeof (string));
+ f.Name = "default";
+ f.GetStatements.Add (new CodeMethodReturnStatement (
+ new CodePrimitiveExpression (null)));
+ ctd.Members.Add (f);
+ cns.Types.Add (ctd);
+ CSharpCodeProvider p = new CSharpCodeProvider ();
+ StringWriter sw = new StringWriter ();
+ p.CreateGenerator ().GenerateCodeFromNamespace (cns, sw, null);
+ Assert.IsTrue (sw.ToString ().IndexOf ("@default") > 0);
+ }
+
+ [Test]
+ public void GenericCodeTypeReferencesTest ()
+ {
+ string code = GenerateGenericCodeTypeReferences (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public class Test {{{0}" +
+ " {0}" +
+ " private System.Nullable<int> Foo;{0}" +
+ " {0}" +
+ " private System.Nullable<> Bar;{0}" +
+ "}}{0}", NewLine), code);
+ }
+
+ [Test]
+ public override void PartialTypeTest ()
+ {
+ string code = GeneratePartialType (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public partial class Test1 {{{0}" +
+ "}}{0}", NewLine), code);
+ }
}
[TestFixture]
"public delegate void Test1();{0}{0}", NewLine), code);
}
+ [Test]
+ public override void MethodParamArrayAttribute ()
+ {
+ string code = GenerateMethodParamArrayAttribute (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public delegate void Test1();{0}{0}", NewLine), code);
+ }
+
[Test]
public override void MethodReturnTypeAttributes ()
{
string code = GenerateEntryPointMethod (Options);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public delegate void Test1();{0}{0}" +
-#if NET_2_0
"[A()]{0}" +
"public static int Main() {{{0}" +
-#else
- "public static void Main() {{{0}" +
-#endif
" Test.InnerType x;{0}" +
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void PartialTypeTest ()
+ {
+ string code = GeneratePartialType (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public delegate void Test1();{0}"
+ , NewLine), code);
+ }
+
#endregion Override implementation of CodeGeneratorFromTypeTestBase
}
{
string code = GenerateDerivedType (Options);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-#if NET_2_0
"internal interface Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#else
- "interface Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#endif
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public interface Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal event int Click;{0}" +
-#else
- " /*FamANDAssem*/ internal event int Click;{0}" +
-#endif
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public interface Test1 {{{0}" +
" {0}" +
- " int Something([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int index);{0}" +
+ " int Something([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int );{0}" +
"}}{0}", NewLine), code);
}
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void MethodParamArrayAttribute ()
+ {
+ string code = GenerateMethodParamArrayAttribute (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public interface Test1 {{{0}" +
+ " {0}" +
+ " int Something([A()] [B()] params out object value, [C()] ref int );{0}" +
+ "}}{0}", NewLine), code);
+ }
+
[Test]
public override void MethodReturnTypeAttributes ()
{
" {0}" +
" [A()]{0}" +
" [B()]{0}" +
+ " params{0}" +
" [return: C(A1=false, A2=true)]{0}" +
" [return: D()]{0}" +
+ " return: params{0}" +
" int Execute();{0}" +
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public interface Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" public static int Main() {{{0}" +
-#else
- " public static void Main() {{{0}" +
-#endif
" Test.InnerType x;{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void PartialTypeTest ()
+ {
+ string code = GeneratePartialType (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public partial interface Test1 {{{0}" +
+ "}}{0}", NewLine), code);
+ }
#endregion Override implementation of CodeGeneratorFromTypeTestBase
}
{
string code = GenerateDerivedType (Options);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-#if NET_2_0
"internal struct Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#else
- "struct Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#endif
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal event int Click;{0}" +
-#else
- " /*FamANDAssem*/ internal event int Click;{0}" +
-#endif
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Name {{{0}" +
-#else
- " internal int Name {{{0}" +
-#endif
" set {{{0}" +
" }}{0}" +
" }}{0}" +
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Name {{{0}" +
-#else
- " internal int Name {{{0}" +
-#endif
" }}{0}" +
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
- " public virtual int Something([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int index) {{{0}" +
+ " public virtual int Something([A()] [B()] object value, [C(A1=false, A2=true)] [D()] out int ) {{{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Execute() {{{0}" +
-#else
- " internal int Execute() {{{0}" +
-#endif
" }}{0}" +
"}}{0}", NewLine), code);
}
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" internal virtual int Execute() {{{0}" +
-#else
- " internal int Execute() {{{0}" +
-#endif
" }}{0}" +
"}}{0}", NewLine), code);
}
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void MethodParamArrayAttribute ()
+ {
+ string code = GenerateMethodParamArrayAttribute (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public struct Test1 {{{0}" +
+ " {0}" +
+ " public virtual int Something([A()] [B()] params out object value, [C()] ref int ) {{{0}" +
+ " }}{0}" +
+ "}}{0}", NewLine), code);
+ }
+
[Test]
public override void MethodReturnTypeAttributes ()
{
" {0}" +
" [A()]{0}" +
" [B()]{0}" +
+ " params{0}" +
" [return: C(A1=false, A2=true)]{0}" +
" [return: D()]{0}" +
+ " return: params{0}" +
" public virtual int Execute() {{{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" [B()]{0}" +
-#endif
" static Test1() {{{0}" +
" }}{0}" +
"}}{0}", NewLine), code, "#1");
"public struct Test1{0}" +
"{{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" [B()]{0}" +
-#endif
" static Test1(){0}" +
" {{{0}" +
" }}{0}" +
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public struct Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" public static int Main() {{{0}" +
-#else
- " public static void Main() {{{0}" +
-#endif
" Test.InnerType x;{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void PartialTypeTest ()
+ {
+ string code = GeneratePartialType (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public partial struct Test1 {{{0}" +
+ "}}{0}", NewLine), code);
+ }
#endregion Override implementation of CodeGeneratorFromTypeTestBase
}
{
string code = GenerateDerivedType (Options);
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
-#if NET_2_0
"internal enum Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#else
- "enum Test1 : int, System.Security.Principal.IIdentity, string, System.Security.IPermission {{{0}" +
-#endif
"}}{0}", NewLine), code);
}
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void MethodParamArrayAttribute ()
+ {
+ string code = GenerateMethodParamArrayAttribute (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public enum Test1 {{{0}" +
+ " {0}" +
+ "}}{0}", NewLine), code);
+ }
+
[Test]
public override void MethodReturnTypeAttributes ()
{
Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
"public enum Test1 {{{0}" +
" {0}" +
-#if NET_2_0
" [A()]{0}" +
" public static int Main() {{{0}" +
-#else
- " public static void Main() {{{0}" +
-#endif
" Test.InnerType x;{0}" +
" }}{0}" +
"}}{0}", NewLine), code);
}
+ [Test]
+ public override void PartialTypeTest ()
+ {
+ string code = GeneratePartialType (Options);
+ Assert.AreEqual (string.Format (CultureInfo.InvariantCulture,
+ "public enum Test1 {{{0}" +
+ "}}{0}", NewLine), code);
+ }
+
#endregion Override implementation of CodeGeneratorFromTypeTestBase
}
}