Fixing previous commit, using correct case for CaptureFor and removing the component...
[castle.git] / InversionOfControl / Castle.Windsor.Tests / CircularDependencyTests.cs
blob20cfb8562b8ad58b40a0aaa4dd8469050f8b480f
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.Windsor.Tests
17 using System;
18 using Castle.MicroKernel.Exceptions;
19 using Castle.MicroKernel.Handlers;
20 using Castle.Windsor.Tests.Components;
21 using NUnit.Framework;
23 [TestFixture]
24 public class CircularDependencyTests
26 [Test]
27 public void ShouldNotSetTheViewControllerProperty()
29 IWindsorContainer container = new WindsorContainer();
30 container.AddComponent("controller", typeof(IController), typeof(Controller));
31 container.AddComponent("view", typeof(IView), typeof(View));
32 Controller controller = (Controller)container.Resolve("controller");
33 Assert.IsNotNull(controller.View);
34 Assert.IsNull(controller.View.Controller);
37 [Test]
39 ExpectedException(typeof(HandlerException),
40 @"Can't create component 'compA' as it has dependencies to be satisfied.
41 compA is waiting for the following dependencies:
43 Services:
44 - Castle.Windsor.Tests.Components.CompB which was registered but is also waiting for dependencies.
46 compB is waiting for the following dependencies:
48 Services:
49 - Castle.Windsor.Tests.Components.CompC which was registered but is also waiting for dependencies.
51 compC is waiting for the following dependencies:
53 Services:
54 - Castle.Windsor.Tests.Components.CompD which was registered but is also waiting for dependencies.
56 compD is waiting for the following dependencies:
58 Services:
59 - Castle.Windsor.Tests.Components.CompA which was registered but is also waiting for dependencies.
62 public void ThrowsACircularDependencyException2()
64 IWindsorContainer container = new WindsorContainer();
65 container.AddComponent("compA", typeof(CompA));
66 container.AddComponent("compB", typeof(CompB));
67 container.AddComponent("compC", typeof(CompC));
68 container.AddComponent("compD", typeof(CompD));
70 container.Resolve("compA");
73 [Test]
74 public void ShouldNotGetCircularDepencyExceptionWhenResolvingTypeOnItselfWithDifferentModels()
76 WindsorContainer container = new WindsorContainer(ConfigHelper.ResolveConfigPath("IOC-51.xml"));
77 object o = container["path.fileFinder"];
78 Assert.IsNotNull(o);
82 namespace IOC51
84 using System.Reflection;
86 public interface IPathProvider
88 string Path { get; }
91 public class AssemblyPath : IPathProvider
93 public string Path
95 get
97 Uri uriPath = new Uri(Assembly.GetExecutingAssembly().GetName(false).CodeBase);
98 return uriPath.LocalPath;
103 public class RelativeFilePath : IPathProvider
105 public RelativeFilePath(IPathProvider basePathProvider, string extensionsPath)
107 _path = System.IO.Path.Combine(basePathProvider.Path + "\\", extensionsPath);
110 public string Path
112 get { return _path; }
115 private string _path;