Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / ClassEmitterTestCase.cs
blob08528e3fc0e8fb1d95b9bcc52afa5f9fd225d63c
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.DynamicProxy.Tests
17 using System;
18 using System.Collections.Generic;
19 using System.Reflection;
20 using Castle.DynamicProxy.Generators.Emitters;
21 using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
22 using NUnit.Framework;
24 [TestFixture]
25 public class ClassEmitterTestCase : BasePEVerifyTestCase
27 [Test]
28 public void AutomaticDefaultConstructorGeneration ()
30 ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes);
31 Type t = emitter.BuildType();
32 Activator.CreateInstance (t);
35 [Test]
36 public void AutomaticDefaultConstructorGenerationWithClosedGenericType ()
38 ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (List<object>), Type.EmptyTypes);
39 Type t = emitter.BuildType ();
40 Activator.CreateInstance (t);
43 [Test]
44 public void StaticMethodArguments ()
46 ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (List<object>), Type.EmptyTypes);
47 MethodEmitter methodEmitter = emitter.CreateMethod ("StaticMethod", MethodAttributes.Public | MethodAttributes.Static,
48 typeof (string), typeof (string));
49 methodEmitter.CodeBuilder.AddStatement (new ReturnStatement (methodEmitter.Arguments[0]));
50 Type t = emitter.BuildType ();
51 Assert.AreEqual ("five", t.GetMethod ("StaticMethod").Invoke (null, new object[] { "five" }));
54 [Test]
55 public void InstanceMethodArguments ()
57 ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (List<object>), Type.EmptyTypes);
58 MethodEmitter methodEmitter = emitter.CreateMethod ("InstanceMethod", MethodAttributes.Public,
59 typeof (string), typeof (string));
60 methodEmitter.CodeBuilder.AddStatement (new ReturnStatement (methodEmitter.Arguments[0]));
61 Type t = emitter.BuildType ();
62 object instance = Activator.CreateInstance (t);
63 Assert.AreEqual ("six", t.GetMethod ("InstanceMethod").Invoke (instance, new object[] { "six" }));
66 [Test]
67 public void ForceUnsignedFalseWithSignedTypes ()
69 ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes, TypeAttributes.Public, false);
70 Type t = emitter.BuildType ();
71 Assert.IsTrue (StrongNameUtil.IsAssemblySigned (t.Assembly));
74 [Test]
75 public void ForceUnsignedTrueWithSignedTypes ()
77 ClassEmitter emitter = new ClassEmitter (generator.ProxyBuilder.ModuleScope, "Foo", typeof (object), Type.EmptyTypes, TypeAttributes.Public, true);
78 Type t = emitter.BuildType ();
79 Assert.IsFalse (StrongNameUtil.IsAssemblySigned (t.Assembly));