2 // MethodRentalTest.cs - NUnit Test Cases for the MethodRental class
4 // Zoltan Varga (vargaz@freemail.hu)
6 // (C) Ximian, Inc. http://www.ximian.com
9 using System.Threading;
10 using System.Reflection;
11 using System.Reflection.Emit;
13 using NUnit.Framework;
15 namespace MonoTests.System.Reflection.Emit
18 public class MethodRentalTest : Assertion
20 private TypeBuilder genClass;
21 private ModuleBuilder module;
22 private static int methodIndexer = 0;
23 private static int typeIndexer = 0;
26 protected void SetUp ()
28 AssemblyName assemblyName = new AssemblyName();
29 assemblyName.Name = "MonoTests.System.Reflection.Emit.MethodRentalTest";
31 AssemblyBuilder assembly = Thread.GetDomain().DefineDynamicAssembly(
32 assemblyName, AssemblyBuilderAccess.Run);
34 module = assembly.DefineDynamicModule("module1");
36 genClass = module.DefineType(genTypeName (),
37 TypeAttributes.Public);
41 [ExpectedException (typeof (ArgumentException))]
42 public void SwapMethodBodyInvalidMethodSize ()
44 MethodRental.SwapMethodBody (null, 0, IntPtr.Zero, 0, 0);
48 [ExpectedException (typeof (ArgumentNullException))]
49 public void SwapMethodBodyNullType ()
51 MethodRental.SwapMethodBody (null, 0, IntPtr.Zero, 1, 0);
55 [ExpectedException (typeof (NotSupportedException))]
56 public void SwapMethodBodyUnfinishedType ()
58 MethodRental.SwapMethodBody (genClass, 0, IntPtr.Zero, 1, 0);
61 // Return a unique method name
62 private string genMethodName ()
64 return "m" + (methodIndexer++);
67 // Return a unique type name
68 private string genTypeName ()
70 return "class" + (typeIndexer++);