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 System
.Runtime
.InteropServices
;
17 using Castle
.Core
.Interceptor
;
18 using Castle
.DynamicProxy
.Tests
.BugsReported
;
19 using NUnit
.Framework
;
21 namespace Castle
.DynamicProxy
.Tests
24 public class BugsReportedTestCase
: BasePEVerifyTestCase
27 public void InterfaceInheritance()
29 ICameraService proxy
= (ICameraService
)
30 generator
.CreateInterfaceProxyWithTarget(typeof (ICameraService
),
32 new StandardInterceptor());
34 Assert
.IsNotNull(proxy
);
41 public void ProxyInterfaceWithSetterOnly()
43 IHaveOnlySetter proxy
= (IHaveOnlySetter
)
44 generator
.CreateInterfaceProxyWithTarget(typeof (IHaveOnlySetter
),
46 new SkipCallingMethodInterceptor());
48 Assert
.IsNotNull(proxy
);
54 [ExpectedException(typeof (NotImplementedException
),
55 "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"
57 public void CallingProceedOnAbstractMethodShouldThrowException()
59 AbstractClass proxy
= (AbstractClass
)
60 generator
.CreateClassProxy(typeof (AbstractClass
), ProxyGenerationOptions
.Default
, 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()
80 WithMixin p
= (WithMixin
) generator
.CreateClassProxy(typeof (WithMixin
), new Type
[] {typeof (Marker<int>)}
, new IInterceptor
[0]);
86 public void ProxyingInterfaceWithComImport()
88 IHTMLEventObj2 proxy
= (IHTMLEventObj2
)
89 generator
.CreateInterfaceProxyWithoutTarget(typeof (IHTMLEventObj2
),
90 new SkipCallingMethodInterceptor());
92 Assert
.IsNotNull(proxy
);
96 public void InheritedInterfaces()
98 IFooExtended proxiedFoo
=
99 (IFooExtended
) generator
.CreateInterfaceProxyWithTargetInterface(typeof (IFooExtended
), new ImplementedFoo(), new StandardInterceptor());
100 proxiedFoo
.FooExtended();
104 public interface IFoo
109 public interface IFooExtended
: IFoo
114 public class ImplementedFoo
: IFooExtended
116 public void FooExtended()
125 [ComImport
, Guid("3050F48B-98B5-11CF-BB82-00AA00BDCE0B")]
126 public interface IHTMLEventObj2
130 public interface IRepository
<TEntity
, TKey
>
132 TEntity
GetById(TKey key
);
139 public interface IUserRepository
: IRepository
<User
, string>
143 public abstract class AbstractClass
145 public abstract string Foo();
148 public class SkipCallingMethodInterceptor
: IInterceptor
150 public void Intercept(IInvocation invocation
)
155 public interface IHaveOnlySetter
160 public class HaveOnlySetter
: IHaveOnlySetter
164 set { throw new Exception("The method or operation is not implemented."); }
168 public interface Marker
<T
>
172 public class WithMixin
174 public virtual void Method()