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
.Facilities
.Remoting
.Tests
18 using System
.Globalization
;
20 using System
.Reflection
;
21 using System
.Runtime
.Remoting
;
25 using NUnit
.Framework
;
28 public abstract class AbstractRemoteTestCase
30 protected IWindsorContainer serverContainer
;
32 protected AppDomain serverDomain
;
34 protected AppDomain clientDomain
;
37 public virtual void Init()
39 serverDomain
= AppDomainFactory
.Create("server");
40 clientDomain
= AppDomainFactory
.Create("client");
42 serverContainer
= CreateRemoteContainer(serverDomain
, GetServerConfigFile());
46 public virtual void Terminate()
48 serverContainer
.Dispose();
50 AppDomain
.Unload(clientDomain
);
51 AppDomain
.Unload(serverDomain
);
54 protected abstract String
GetServerConfigFile();
56 protected IWindsorContainer
CreateRemoteContainer(AppDomain domain
, String configFile
)
58 ObjectHandle handle
= domain
.CreateInstance(
59 typeof(WindsorContainer
).Assembly
.FullName
,
60 typeof(WindsorContainer
).FullName
, false, BindingFlags
.Instance
|BindingFlags
.Public
, null,
61 new object[] { configFile }
,
62 CultureInfo
.InvariantCulture
, null, null );
64 return (IWindsorContainer
) handle
.Unwrap();
67 protected IWindsorContainer
GetRemoteContainer(AppDomain domain
, String configFile
)
69 ObjectHandle handle
= domain
.CreateInstance(
70 typeof(ContainerPlaceHolder
).Assembly
.FullName
,
71 typeof(ContainerPlaceHolder
).FullName
, false, BindingFlags
.Instance
|BindingFlags
.Public
, null,
72 new object[] { configFile }
,
73 CultureInfo
.InvariantCulture
, null, null );
75 ContainerPlaceHolder holder
= handle
.Unwrap() as ContainerPlaceHolder
;
77 return holder
.Container
;
80 protected string BuildConfigPath(string configFile
)
82 string baseDir
= System
.Configuration
.ConfigurationManager
.AppSettings
["configPath"];
84 return ConfigHelper
.ResolveConfigPath(Path
.Combine(baseDir
, configFile
));
88 public class ContainerPlaceHolder
: MarshalByRefObject
90 private static IWindsorContainer _container
;
92 public ContainerPlaceHolder(string configFile
)
94 if (_container
== null)
96 _container
= new WindsorContainer(configFile
);
100 public IWindsorContainer Container