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
18 using Castle
.MicroKernel
.Handlers
;
19 using NUnit
.Framework
;
22 public class MultiResolveTests
25 public void CanResolveMoreThanSingleComponentForService()
27 IWindsorContainer container
= new WindsorContainer()
28 .AddComponent
<IClock
, IsraelClock
>()
29 .AddComponent
<IClock
, WorldClock
>();
31 IClock
[] clocks
= container
.ResolveAll
<IClock
>();
33 Assert
.AreEqual(2, clocks
.Length
);
37 public void MultiResolveWillResolveInRegistrationOrder()
39 IWindsorContainer container
= new WindsorContainer()
40 .AddComponent
<IClock
, IsraelClock
>()
41 .AddComponent
<IClock
, WorldClock
>();
43 IClock
[] clocks
= container
.ResolveAll
<IClock
>();
45 Assert
.AreEqual(typeof(IsraelClock
), clocks
[0].GetType());
46 Assert
.AreEqual(typeof(WorldClock
), clocks
[1].GetType());
49 container
= new WindsorContainer()
50 .AddComponent
<IClock
, WorldClock
>()
51 .AddComponent
<IClock
, IsraelClock
>();
53 clocks
= container
.ResolveAll
<IClock
>();
55 Assert
.AreEqual(typeof(WorldClock
), clocks
[0].GetType());
56 Assert
.AreEqual(typeof(IsraelClock
), clocks
[1].GetType());
60 public void CanUseMutliResolveWithGenericSpecialization()
62 IWindsorContainer container
= new WindsorContainer()
63 .AddComponent("demo", typeof (IRepository
<>), typeof (DemoRepository
<>))
64 .AddComponent("trans", typeof(IRepository
<>), typeof(TransientRepository
<>));
66 IRepository
<IClock
> resolve
= container
.Resolve
<IRepository
<IClock
>>();
67 Assert
.IsNotNull(resolve
);
69 IRepository
<IsraelClock
>[] repositories
= container
.ResolveAll
<IRepository
<IsraelClock
>>();
70 Assert
.AreEqual(2, repositories
.Length
);
74 [ExpectedException(typeof(HandlerException
))]
75 public void WillThrowIfOneOfTheComponentsIsNotValid()
77 IWindsorContainer container
= new WindsorContainer()
78 .AddComponent
<IClock
, IsraelClock
>()
79 .AddComponent
<IClock
, WorldClock
>()
80 .AddComponent
<IClock
, DependantClock
>();
82 container
.ResolveAll
<IClock
>();
86 public interface IClock
{}
87 public class IsraelClock
: IClock
{}
88 public class WorldClock
: IClock
{}
89 public class DependantClock
: IClock
91 private IDisposable disposable
;
93 public DependantClock(IDisposable disposable
)
95 this.disposable
= disposable
;