1 // Copyright 2004-2008 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.
15 namespace Castle
.Windsor
.Tests
.Proxy
18 using Castle
.Core
.Interceptor
;
19 using Castle
.Windsor
.Tests
.Components
;
20 using NUnit
.Framework
;
23 public class ProxyBehaviorTestCase
26 public void DefaultProxyBehaviorFromConfiguration()
28 IWindsorContainer container
;
30 container
= new WindsorContainer(ConfigHelper
.ResolveConfigPath("Proxy/proxyBehavior.xml"));
32 ICalcService calcService
= (ICalcService
) container
["default"];
33 Assert
.IsNotNull(calcService
);
34 Assert
.IsTrue(calcService
is IDisposable
, "Service proxy should expose the IDisposable interface");
38 public void NoSingleInterfaceProxyBehaviorFromConfiguration()
40 IWindsorContainer container
;
42 container
= new WindsorContainer(ConfigHelper
.ResolveConfigPath("Proxy/proxyBehavior.xml"));
44 ICalcService calcService
= (ICalcService
) container
["noSingle"];
45 Assert
.IsNotNull(calcService
);
46 Assert
.IsTrue(calcService
is IDisposable
, "Service proxy should expose the IDisposable interface");
50 public void UseSingleInterfaceProxyBehaviorFromConfiguration()
52 IWindsorContainer container
;
54 container
= new WindsorContainer(ConfigHelper
.ResolveConfigPath("Proxy/proxyBehavior.xml"));
56 ICalcService calcService
= (ICalcService
) container
["useSingle"];
57 Assert
.IsNotNull(calcService
);
58 Assert
.IsFalse(calcService
is IDisposable
, "Service proxy should not expose the IDisposable interface");
62 public void UseSingleInterfaceProxyBehaviorFromAttribute()
64 IWindsorContainer container
;
66 container
= new WindsorContainer(ConfigHelper
.ResolveConfigPath("Proxy/proxyBehavior.xml"));
68 ICalcService calcService
= (ICalcService
) container
["useSingleAttribute"];
69 Assert
.IsFalse(calcService
is IDisposable
, "Service proxy should not expose the IDisposable interface");
73 public void RequestSingleInterfaceProxyWithAttribute()
75 IWindsorContainer container
= new WindsorContainer();
77 container
.AddComponent("standard.interceptor", typeof(StandardInterceptor
));
78 container
.AddComponent("useSingle", typeof(ICalcService
), typeof(CalculatorServiceWithSingleProxyBehavior
));
80 ICalcService calcService
= (ICalcService
) container
["useSingle"];
81 Assert
.IsNotNull(calcService
);
82 Assert
.IsFalse(calcService
is IDisposable
, "Service proxy should not expose the IDisposable interface");
86 public void NoSingleInterfaceProxyWithAttribute()
88 IWindsorContainer container
= new WindsorContainer();
90 container
.AddComponent("standard.interceptor", typeof(StandardInterceptor
));
91 container
.AddComponent("noSingle", typeof(ICalcService
), typeof(CalculatorServiceWithoutSingleProxyBehavior
));
93 ICalcService calcService
= (ICalcService
) container
["noSingle"];
94 Assert
.IsNotNull(calcService
);
95 Assert
.IsTrue(calcService
is IDisposable
, "Service proxy should expose the IDisposable interface");
99 public void RequestMarshalByRefProxyWithAttribute()
101 IWindsorContainer container
= new WindsorContainer();
103 container
.AddComponent("standard.interceptor", typeof(StandardInterceptor
));
104 container
.AddComponent("useMarshal", typeof(ICalcService
), typeof(CalculatorServiceWithMarshalByRefProxyBehavior
));
106 ICalcService calcService
= (ICalcService
)container
["useMarshal"];
107 Assert
.IsNotNull(calcService
);
108 Assert
.IsFalse(calcService
is CalculatorServiceWithMarshalByRefProxyBehavior
, "Service proxy should not expose CalculatorServiceWithMarshalByRefProxyBehavior");
109 Assert
.IsTrue(calcService
is MarshalByRefObject
, "Service proxy should expose MarshalByRefObject");
110 Assert
.IsTrue(calcService
is IDisposable
, "Service proxy should expose the IDisposable interface");