Calling generic methods on generics types for interfaces without targets now works.
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / RhinoMocksTestCase.cs
blobbc528ca8ace8971a1e1b2ff2781b4020f8f9c560
1 // Copyright 2004-2007 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 [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
17 namespace Castle.DynamicProxy.Tests
19 using System.Data;
20 using Castle.Core.Interceptor;
21 using Castle.DynamicProxy.Tests.Interceptors;
22 using System;
23 using System.Collections.Generic;
24 using System.Text;
25 using NUnit.Framework;
28 [TestFixture]
29 public class RhinoMocksTestCase : BasePEVerifyTestCase
31 private ProxyGenerator generator;
33 [SetUp]
34 public void Init()
36 generator = new ProxyGenerator();
39 [Test]
40 public void GenericClassWithGenericMethod()
42 LogInvocationInterceptor logger = new LogInvocationInterceptor();
43 IDoubleGeneric<int> proxy = (IDoubleGeneric<int>)generator.CreateInterfaceProxyWithTarget(typeof(IDoubleGeneric<int>),
44 new DoubleGenericImpl<int>(), logger);
45 proxy.Call<string>(1, "");
46 Assert.AreEqual("Call", logger.Invocations[0]);
49 [Test]
50 public void GenericClassWithGenericMethodWitoutTarget()
52 BasicInterfaceProxyWithoutTargetTestCase.ReturnThreeInterceptor interceptor = new BasicInterfaceProxyWithoutTargetTestCase.ReturnThreeInterceptor();
53 IDoubleGeneric<int> proxy = (IDoubleGeneric<int>)generator.CreateInterfaceProxyWithoutTarget(typeof(IDoubleGeneric<int>),
54 interceptor);
55 object o = proxy.Call<string>(1, "");
56 Assert.AreEqual(3,o );
59 [Test]
60 public void UsingEvents_Interface()
62 LogInvocationInterceptor logger = new LogInvocationInterceptor();
63 IWithEvents proxy = (IWithEvents)generator.CreateInterfaceProxyWithTarget(typeof(IWithEvents),
64 new FakeWithEvents(),
65 logger);
67 Assert.IsNotNull(proxy);
69 proxy.Foo += null;
70 proxy.Foo -= null;
72 Assert.AreEqual(2, logger.Invocations.Count);
75 [Test]
76 public void UsingEvents_Class()
78 LogInvocationInterceptor logger = new LogInvocationInterceptor();
79 FakeWithEvents proxy = (FakeWithEvents)generator.CreateClassProxy(
80 typeof(FakeWithEvents),
81 ProxyGenerationOptions.Default,
82 logger);
84 Assert.IsNotNull(proxy);
86 proxy.Foo += null;
87 proxy.Foo -= null;
89 Assert.AreEqual(2, logger.Invocations.Count);
92 [Test]
93 public void NeedingToCreateNewMethodTableSlot()
95 generator.CreateClassProxy(typeof(MultiClass), new Type[] { typeof(ISpecialMulti) });
98 [Test]
99 public void ProxyingInterfaceWithGuid()
101 object o = generator.CreateInterfaceProxyWithoutTarget(typeof(IWithGuid), new StandardInterceptor());
102 Assert.IsNotNull(o);
105 [Test]
106 public void CanProxyDataSet()
108 generator.CreateClassProxy(typeof(DataSet), new Type[0], new StandardInterceptor());
111 [Test]
112 public void ProxyInternalMethod()
114 LogInvocationInterceptor logging = new LogInvocationInterceptor();
115 WithInternalMethod o = (WithInternalMethod)generator.CreateClassProxy(typeof(WithInternalMethod),
116 new Type[0], logging);
117 o.Foo();
118 Assert.AreEqual("Foo ", logging.LogContents);
121 public interface IWithEvents
123 event EventHandler Foo;
126 public class FakeWithEvents : IWithEvents
128 public virtual event EventHandler Foo;
130 public void MethodToGetAroundFooNotUsedError()
132 Foo(this, EventArgs.Empty);
136 public interface IMulti
138 void OriginalMethod1();
139 void OriginalMethod2();
141 public class MultiClass : IMulti
143 // NON-virtual method
144 public void OriginalMethod1() { }
145 // VIRTUAL method
146 public virtual void OriginalMethod2() { }
148 public interface ISpecialMulti : IMulti
150 void ExtraMethod();
153 [System.Runtime.InteropServices.Guid("AFCF8240-61AF-4089-BD98-3CD4D719EDBA")]
154 public interface IWithGuid
159 public class WithInternalMethod
161 internal virtual void Foo()
166 public interface IDoubleGeneric<One>
168 object Call<T>(One one, T two);
171 public class DoubleGenericImpl<One> : IDoubleGeneric<One>
173 public object Call<T>(One one, T two)
175 return two;