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
27 public void InterfaceInheritance()
29 ProxyGenerator generator
= new ProxyGenerator();
31 ICameraService proxy
= (ICameraService
)
32 generator
.CreateInterfaceProxyWithTarget(typeof(ICameraService
),
34 new StandardInterceptor());
36 Assert
.IsNotNull(proxy
);
43 public void ProxyInterfaceWithSetterOnly()
45 ProxyGenerator generator
= new ProxyGenerator();
47 IHaveOnlySetter proxy
= (IHaveOnlySetter
)
48 generator
.CreateInterfaceProxyWithTarget(typeof(IHaveOnlySetter
),
50 new SkipCallingMethodInterceptor());
52 Assert
.IsNotNull(proxy
);
58 [ExpectedException(typeof(NotImplementedException
),
59 "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"
61 public void CallingProceedOnAbstractMethodShouldThrowException()
63 ProxyGenerator generator
= new ProxyGenerator();
65 AbstractClass proxy
= (AbstractClass
)
66 generator
.CreateClassProxy(typeof(AbstractClass
), ProxyGenerationOptions
.Default
, new StandardInterceptor());
68 Assert
.IsNotNull(proxy
);
74 public void ProxyTypeThatInheritFromGenericType()
76 ProxyGenerator generator
= new ProxyGenerator();
78 IUserRepository proxy
= (IUserRepository
)
79 generator
.CreateInterfaceProxyWithoutTarget(typeof(IUserRepository
),
80 new SkipCallingMethodInterceptor());
82 Assert
.IsNotNull(proxy
);
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]);
94 public void ProxyingInterfaceWithComImport()
96 ProxyGenerator generator
= new ProxyGenerator();
98 IHTMLEventObj2 proxy
= (IHTMLEventObj2
)
99 generator
.CreateInterfaceProxyWithoutTarget(typeof(IHTMLEventObj2
),
100 new SkipCallingMethodInterceptor());
102 Assert
.IsNotNull(proxy
);
108 [ComImport
, Guid("3050F48B-98B5-11CF-BB82-00AA00BDCE0B")]
109 public interface IHTMLEventObj2
115 public interface IRepository
<TEntity
, TKey
>
117 TEntity
GetById(TKey key
);
124 public interface IUserRepository
: IRepository
<User
, string>
128 public abstract class AbstractClass
130 public abstract string Foo();
133 public class SkipCallingMethodInterceptor
: IInterceptor
135 public void Intercept(IInvocation invocation
)
140 public interface IHaveOnlySetter
145 public class HaveOnlySetter
: IHaveOnlySetter
149 set { throw new Exception("The method or operation is not implemented."); }
153 public interface Marker
<T
>
157 public class WithMixin
159 public virtual void Method()