DYNPROXY-58 - Inherited interfaces - FIXED.
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / BugsReportedTestCase.cs
blob752c0d20ae17bb1f3bb3e64b3abcf3127738ac3f
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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 using System;
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
23 [TestFixture]
24 public class BugsReportedTestCase : BasePEVerifyTestCase
26 [Test]
27 public void InterfaceInheritance()
29 ICameraService proxy = (ICameraService)
30 generator.CreateInterfaceProxyWithTarget(typeof (ICameraService),
31 new CameraService(),
32 new StandardInterceptor());
34 Assert.IsNotNull(proxy);
36 proxy.Add("", "");
37 proxy.Record(null);
40 [Test]
41 public void ProxyInterfaceWithSetterOnly()
43 IHaveOnlySetter proxy = (IHaveOnlySetter)
44 generator.CreateInterfaceProxyWithTarget(typeof (IHaveOnlySetter),
45 new HaveOnlySetter(),
46 new SkipCallingMethodInterceptor());
48 Assert.IsNotNull(proxy);
50 proxy.Foo = "bar";
53 [Test]
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);
64 proxy.Foo();
67 [Test]
68 public void ProxyTypeThatInheritFromGenericType()
70 IUserRepository proxy = (IUserRepository)
71 generator.CreateInterfaceProxyWithoutTarget(typeof (IUserRepository),
72 new SkipCallingMethodInterceptor());
74 Assert.IsNotNull(proxy);
77 [Test]
78 public void DYNPROXY_51_GenericMarkerInterface()
80 WithMixin p = (WithMixin) generator.CreateClassProxy(typeof (WithMixin), new Type[] {typeof (Marker<int>)}, new IInterceptor[0]);
82 p.Method();
85 [Test]
86 public void ProxyingInterfaceWithComImport()
88 IHTMLEventObj2 proxy = (IHTMLEventObj2)
89 generator.CreateInterfaceProxyWithoutTarget(typeof (IHTMLEventObj2),
90 new SkipCallingMethodInterceptor());
92 Assert.IsNotNull(proxy);
95 [Test]
96 public void InheritedInterfaces()
98 IFooExtended proxiedFoo =
99 (IFooExtended) generator.CreateInterfaceProxyWithTargetInterface(typeof (IFooExtended), new ImplementedFoo(), new StandardInterceptor());
100 proxiedFoo.FooExtended();
104 public interface IFoo
106 void Foo();
109 public interface IFooExtended : IFoo
111 void FooExtended();
114 public class ImplementedFoo : IFooExtended
116 public void FooExtended()
120 public void Foo()
125 [ComImport, Guid("3050F48B-98B5-11CF-BB82-00AA00BDCE0B")]
126 public interface IHTMLEventObj2
130 public interface IRepository<TEntity, TKey>
132 TEntity GetById(TKey key);
135 public class User
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
157 string Foo { set; }
160 public class HaveOnlySetter : IHaveOnlySetter
162 public string Foo
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()