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.
16 namespace Castle
.DynamicProxy
.Test
19 using System
.Collections
.Generic
;
21 using NUnit
.Framework
;
22 using System
.Runtime
.CompilerServices
;
25 public class DotNet2Tests
28 public void ProxyGenericClass()
30 ProxyGenerator pg
= new ProxyGenerator();
31 GenericClass
<int> x
= (GenericClass
<int>)pg
.CreateClassProxy(typeof(GenericClass
<int>),
32 new StandardInterceptor());
34 Assert
.IsFalse(x
.SomeMethod());
36 GenericClass
<string> y
= (GenericClass
<string>)pg
.CreateClassProxy(typeof(GenericClass
<string>),
37 new StandardInterceptor());
39 Assert
.IsFalse(y
.SomeMethod());
43 public void ProxyGenericInterface()
45 ProxyGenerator pg
= new ProxyGenerator();
46 IList
<int> x
= (IList
<int>)pg
.CreateProxy(typeof(IList
<int>),
47 new StandardInterceptor(), new List
<int>());
49 Assert
.AreEqual(0, x
.Count
);
51 IList
<string> y
= (IList
<string>)pg
.CreateProxy(typeof(IList
<string>),
52 new StandardInterceptor(), new List
<string>());
54 Assert
.AreEqual(0, y
.Count
);
58 public void ProxyGenericInterfaceWithTwoGenericParameters()
60 IDictionary
<int, float> ints
= new Dictionary
<int, float>();
61 ProxyGenerator pg
= new ProxyGenerator();
62 IDictionary
<int, float> x
= (IDictionary
<int, float>)pg
.CreateProxy(typeof(IDictionary
<int, float>),
63 new StandardInterceptor(), ints
);
65 Assert
.AreEqual(0, x
.Count
);
69 public void ProxyInternalClass()
71 ProxyGenerator pg
= new ProxyGenerator();
72 LogInvocationInterceptor logger
= new LogInvocationInterceptor();
73 InternalClass x
= (InternalClass
)pg
.CreateClassProxy(typeof(InternalClass
),
76 Assert
.AreEqual("ayende", x
.Name
);
77 Assert
.AreEqual("set_Name", logger
.Invocations
[0]);
78 Assert
.AreEqual("get_Name", logger
.Invocations
[1]);
82 public class GenericClass
<T
>
84 public virtual bool SomeMethod() { return false; }
87 internal class InternalClass
91 internal virtual String Name
94 set { _name = value; }