1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
20 using Castle
.Core
.Interceptor
;
21 using Castle
.DynamicProxy
.Tests
.Interceptors
;
23 using System
.Collections
.Generic
;
25 using NUnit
.Framework
;
29 public class RhinoMocksTestCase
: BasePEVerifyTestCase
31 private ProxyGenerator generator
;
36 generator
= new ProxyGenerator();
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]);
50 public void GenericClassWithGenericMethodWitoutTarget()
52 BasicInterfaceProxyWithoutTargetTestCase
.ReturnThreeInterceptor interceptor
= new BasicInterfaceProxyWithoutTargetTestCase
.ReturnThreeInterceptor();
53 IDoubleGeneric
<int> proxy
= (IDoubleGeneric
<int>)generator
.CreateInterfaceProxyWithoutTarget(typeof(IDoubleGeneric
<int>),
55 object o
= proxy
.Call
<string>(1, "");
56 Assert
.AreEqual(3,o
);
60 public void UsingEvents_Interface()
62 LogInvocationInterceptor logger
= new LogInvocationInterceptor();
63 IWithEvents proxy
= (IWithEvents
)generator
.CreateInterfaceProxyWithTarget(typeof(IWithEvents
),
67 Assert
.IsNotNull(proxy
);
72 Assert
.AreEqual(2, logger
.Invocations
.Count
);
76 public void UsingEvents_Class()
78 LogInvocationInterceptor logger
= new LogInvocationInterceptor();
79 FakeWithEvents proxy
= (FakeWithEvents
)generator
.CreateClassProxy(
80 typeof(FakeWithEvents
),
81 ProxyGenerationOptions
.Default
,
84 Assert
.IsNotNull(proxy
);
89 Assert
.AreEqual(2, logger
.Invocations
.Count
);
93 public void NeedingToCreateNewMethodTableSlot()
95 generator
.CreateClassProxy(typeof(MultiClass
), new Type
[] { typeof(ISpecialMulti) }
);
99 public void ProxyingInterfaceWithGuid()
101 object o
= generator
.CreateInterfaceProxyWithoutTarget(typeof(IWithGuid
), new StandardInterceptor());
106 public void CanProxyDataSet()
108 generator
.CreateClassProxy(typeof(DataSet
), new Type
[0], new StandardInterceptor());
112 public void ProxyInternalMethod()
114 LogInvocationInterceptor logging
= new LogInvocationInterceptor();
115 WithInternalMethod o
= (WithInternalMethod
)generator
.CreateClassProxy(typeof(WithInternalMethod
),
116 new Type
[0], logging
);
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() { }
146 public virtual void OriginalMethod2() { }
148 public interface ISpecialMulti
: IMulti
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
)