Skipping [ComImport] attribute when replicating attributes.
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / BugsReportedTestCase.cs
blobeed85746118952e140bfca793b93527f783912df
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
26 [Test]
27 public void InterfaceInheritance()
29 ProxyGenerator generator = new ProxyGenerator();
31 ICameraService proxy = (ICameraService)
32 generator.CreateInterfaceProxyWithTarget(typeof(ICameraService),
33 new CameraService(),
34 new StandardInterceptor());
36 Assert.IsNotNull(proxy);
38 proxy.Add("", "");
39 proxy.Record(null);
42 [Test]
43 public void ProxyInterfaceWithSetterOnly()
45 ProxyGenerator generator = new ProxyGenerator();
47 IHaveOnlySetter proxy = (IHaveOnlySetter)
48 generator.CreateInterfaceProxyWithTarget(typeof(IHaveOnlySetter),
49 new HaveOnlySetter(),
50 new SkipCallingMethodInterceptor());
52 Assert.IsNotNull(proxy);
54 proxy.Foo = "bar";
57 [Test]
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);
70 proxy.Foo();
73 [Test]
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);
85 [Test]
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]);
90 p.Method();
93 [Test]
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);
120 public class User
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
142 string Foo { set; }
145 public class HaveOnlySetter : IHaveOnlySetter
147 public string Foo
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()