Fixed test issue - PEVerify is now called with a quoted assembly path (to allow for...
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / BugsReportedTestCase.cs
blob886bc2e21fd24623129a576426674083ec539fa3
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 namespace Castle.DynamicProxy.Tests
17 using System;
18 using Castle.Core.Interceptor;
19 using Castle.DynamicProxy.Tests.BugsReported;
20 using NUnit.Framework;
22 [TestFixture]
23 public class BugsReportedTestCase : BasePEVerifyTestCase
25 [Test]
26 public void InterfaceInheritance()
28 ICameraService proxy = (ICameraService)
29 generator.CreateInterfaceProxyWithTarget(typeof(ICameraService),
30 new CameraService(),
31 new StandardInterceptor());
33 Assert.IsNotNull(proxy);
35 proxy.Add("", "");
36 proxy.Record(null);
39 [Test]
40 public void ProxyInterfaceWithSetterOnly()
42 IHaveOnlySetter proxy = (IHaveOnlySetter)
43 generator.CreateInterfaceProxyWithTarget(typeof(IHaveOnlySetter),
44 new HaveOnlySetter(),
45 new SkipCallingMethodInterceptor());
47 Assert.IsNotNull(proxy);
49 proxy.Foo = "bar";
52 [Test]
53 [ExpectedException(typeof(NotImplementedException),
54 "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"
56 public void CallingProceedOnAbstractMethodShouldThrowException()
58 AbstractClass proxy = (AbstractClass)
59 generator.CreateClassProxy(typeof(AbstractClass), ProxyGenerationOptions.Default,
60 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 =
81 (WithMixin) generator.CreateClassProxy(typeof(WithMixin), new Type[] {typeof(Marker<int>)}, new IInterceptor[0]);
82 p.Method();
86 public interface IRepository<TEntity, TKey>
88 TEntity GetById(TKey key);
91 public class User
95 public interface IUserRepository : IRepository<User, string>
99 public abstract class AbstractClass
101 public abstract string Foo();
104 public class SkipCallingMethodInterceptor : IInterceptor
106 public void Intercept(IInvocation invocation)
111 public interface IHaveOnlySetter
113 string Foo { set; }
116 public class HaveOnlySetter : IHaveOnlySetter
118 public string Foo
120 set { throw new Exception("The method or operation is not implemented."); }
124 public interface Marker<T>
128 public class WithMixin
130 public virtual void Method()