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 using Castle
.Core
.Interceptor
;
17 using Castle
.DynamicProxy
.Tests
.BugsReported
;
18 using NUnit
.Framework
;
20 namespace Castle
.DynamicProxy
.Tests
23 public class BugsReportedTestCase
26 public void InterfaceInheritance()
28 ProxyGenerator generator
= new ProxyGenerator();
30 ICameraService proxy
= (ICameraService
)
31 generator
.CreateInterfaceProxyWithTarget(typeof(ICameraService
),
33 new StandardInterceptor());
35 Assert
.IsNotNull(proxy
);
42 public void ProxyInterfaceWithSetterOnly()
44 ProxyGenerator generator
= new ProxyGenerator();
46 IHaveOnlySetter proxy
= (IHaveOnlySetter
)
47 generator
.CreateInterfaceProxyWithTarget(typeof(IHaveOnlySetter
),
49 new SkipCallingMethodInterceptor());
51 Assert
.IsNotNull(proxy
);
57 [ExpectedException(typeof(NotImplementedException
),
58 "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"
60 public void CallingProceedOnAbstractMethodShouldThrowException()
62 ProxyGenerator generator
= new ProxyGenerator();
64 AbstractClass proxy
= (AbstractClass
)
65 generator
.CreateClassProxy(typeof(AbstractClass
), ProxyGenerationOptions
.Default
, new StandardInterceptor());
67 Assert
.IsNotNull(proxy
);
73 public void ProxyTypeThatInheritFromGenericType()
75 ProxyGenerator generator
= new ProxyGenerator();
77 IUserRepository proxy
= (IUserRepository
)
78 generator
.CreateInterfaceProxyWithoutTarget(typeof(IUserRepository
),
79 new SkipCallingMethodInterceptor());
81 Assert
.IsNotNull(proxy
);
85 [Ignore("Need to discuss why we are calling interf.GetGenericArguments() in class emitter")]
86 public void DYNPROXY_51_GenericMarkerInterface()
88 ProxyGenerator gen
= new ProxyGenerator();
89 WithMixin p
= (WithMixin
)gen
.CreateClassProxy(typeof(WithMixin
), new Type
[] { typeof(Marker<int>) }
, new IInterceptor
[0]);
95 public interface IRepository
<TEntity
, TKey
>
97 TEntity
GetById(TKey key
);
104 public interface IUserRepository
: IRepository
<User
, string>
108 public abstract class AbstractClass
110 public abstract string Foo();
113 public class SkipCallingMethodInterceptor
: IInterceptor
115 public void Intercept(IInvocation invocation
)
120 public interface IHaveOnlySetter
125 public class HaveOnlySetter
: IHaveOnlySetter
129 set { throw new Exception("The method or operation is not implemented."); }
133 public interface Marker
<T
>
137 public class WithMixin
139 public virtual void Method()