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
.MicroKernel
.Tests
18 using NUnit
.Framework
;
21 public class SubResolverTestCase
24 public void WillAskResolverWhenTryingToResolveDependencyAfterAnotherHandlerWasRegistered()
26 FooBarResolver resolver
= new FooBarResolver();
28 IKernel kernel
= new DefaultKernel();
29 kernel
.Resolver
.AddSubResolver(resolver
);
31 kernel
.AddComponent("foo", typeof(Foo
));
32 IHandler handler
= kernel
.GetHandler("foo");
33 Assert
.AreEqual(HandlerState
.WaitingDependency
, handler
.CurrentState
);
37 kernel
.RaiseHandlerRegistered(null);//should force reevaluation of state
39 Assert
.AreEqual(HandlerState
.Valid
, handler
.CurrentState
);
53 public class FooBarResolver
: ISubDependencyResolver
57 public object Resolve(CreationContext context
, ISubDependencyResolver parentResolver
, ComponentModel model
,
58 DependencyModel dependency
)
63 public bool CanResolve(CreationContext context
, ISubDependencyResolver parentResolver
, ComponentModel model
,
64 DependencyModel dependency
)
66 return Result
!= null;