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 Castle
.Core
.Interceptor
;
19 using Castle
.DynamicProxy
.Tests
.BugsReported
;
20 using NUnit
.Framework
;
23 public class BugsReportedTestCase
: BasePEVerifyTestCase
26 public void InterfaceInheritance()
28 ICameraService proxy
= (ICameraService
)
29 generator
.CreateInterfaceProxyWithTarget(typeof(ICameraService
),
31 new StandardInterceptor());
33 Assert
.IsNotNull(proxy
);
40 public void ProxyInterfaceWithSetterOnly()
42 IHaveOnlySetter proxy
= (IHaveOnlySetter
)
43 generator
.CreateInterfaceProxyWithTarget(typeof(IHaveOnlySetter
),
45 new SkipCallingMethodInterceptor());
47 Assert
.IsNotNull(proxy
);
53 [ExpectedException(typeof(NotImplementedException
),
54 "This is a DynamicProxy2 error: the interceptor attempted to 'Proceed' for a method without a target, for example, an interface method or an abstract method"
56 public void CallingProceedOnAbstractMethodShouldThrowException()
58 AbstractClass proxy
= (AbstractClass
)
59 generator
.CreateClassProxy(typeof(AbstractClass
), ProxyGenerationOptions
.Default
,
60 new StandardInterceptor());
62 Assert
.IsNotNull(proxy
);
68 public void ProxyTypeThatInheritFromGenericType()
70 IUserRepository proxy
= (IUserRepository
)
71 generator
.CreateInterfaceProxyWithoutTarget(typeof(IUserRepository
),
72 new SkipCallingMethodInterceptor());
74 Assert
.IsNotNull(proxy
);
78 public void DYNPROXY_51_GenericMarkerInterface()
81 (WithMixin
) generator
.CreateClassProxy(typeof(WithMixin
), new Type
[] {typeof(Marker<int>)}
, new IInterceptor
[0]);
86 public interface IRepository
<TEntity
, TKey
>
88 TEntity
GetById(TKey key
);
95 public interface IUserRepository
: IRepository
<User
, string>
99 public abstract class AbstractClass
101 public abstract string Foo();
104 public class SkipCallingMethodInterceptor
: IInterceptor
106 public void Intercept(IInvocation invocation
)
111 public interface IHaveOnlySetter
116 public class HaveOnlySetter
: IHaveOnlySetter
120 set { throw new Exception("The method or operation is not implemented."); }
124 public interface Marker
<T
>
128 public class WithMixin
130 public virtual void Method()