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 namespace Castle
.DynamicProxy
.Tests
18 using System
.Collections
;
19 using Castle
.Core
.Interceptor
;
20 using Castle
.DynamicProxy
.Tests
.Classes
;
21 using Castle
.DynamicProxy
.Tests
.Interceptors
;
22 using NUnit
.Framework
;
25 public class AccessLevelTestCase
: BasePEVerifyTestCase
28 public void ProtectedConstructor()
30 NonPublicConstructorClass proxy
=
31 generator
.CreateClassProxy(
32 typeof(NonPublicConstructorClass
), new StandardInterceptor())
33 as NonPublicConstructorClass
;
35 Assert
.IsNotNull(proxy
);
41 public void ProtectedInternalConstructor ()
43 ProtectedInternalConstructorClass proxy
=
44 generator
.CreateClassProxy (
45 typeof (ProtectedInternalConstructorClass
), new StandardInterceptor())
46 as ProtectedInternalConstructorClass
;
48 Assert
.IsNotNull (proxy
);
54 public void ProtectedMethods()
56 LogInvocationInterceptor logger
= new LogInvocationInterceptor();
58 NonPublicMethodsClass proxy
= (NonPublicMethodsClass
)
59 generator
.CreateClassProxy(typeof(NonPublicMethodsClass
), logger
);
63 Assert
.AreEqual(2, logger
.Invocations
.Count
);
64 Assert
.AreEqual("DoSomething", logger
.Invocations
[0]);
65 Assert
.AreEqual("DoOtherThing", logger
.Invocations
[1]);
69 public void InternalConstructorIsNotReplicated()
71 object proxy
= generator
.CreateClassProxy(typeof(Hashtable
), new StandardInterceptor());
72 Assert
.IsNull(proxy
.GetType().GetConstructor(new Type
[] {typeof(IInterceptor[]), typeof(bool)}
));
75 internal class InternalClass
77 internal InternalClass()
85 public void InternalConstructorIsReplicatedWhenInternalsVisibleTo()
87 object proxy
= generator
.CreateClassProxy(typeof(InternalClass
), new StandardInterceptor());
88 Assert
.IsNotNull(proxy
.GetType().GetConstructor(new Type
[] {typeof(IInterceptor[])}
));