Fixing spelling mistake
[castle.git] / InversionOfControl / Castle.Windsor.Tests / CircularDependencyTests.cs
blob9f3186a9f6e3a8a770e8cee52e41316ee26f1375
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 ThrowsACircularDependencyException()
29 IWindsorContainer container = new WindsorContainer();
30 container.AddComponent("controller", typeof(IController), typeof(Controller));
31 container.AddComponent("view", typeof(IView), typeof(View));
32 try
34 container.Resolve("controller");
36 throw new Exception(
37 @"A cycle was detected when trying to resolve a dependency. The dependency graph that resulted in a cycle is:
38 - Service dependency 'view' type 'Castle.Windsor.Tests.Components.IView' for Void .ctor(Castle.Windsor.Tests.Components.IView) in type Castle.Windsor.Tests.Components.Controller
39 - Service dependency 'Controller' type 'Castle.Windsor.Tests.Components.IController' for Castle.Windsor.Tests.Components.IController Controller in type Castle.Windsor.Tests.Components.View
40 + Service dependency 'view' type 'Castle.Windsor.Tests.Components.IView' for Void .ctor(Castle.Windsor.Tests.Components.IView) in Castle.Windsor.Tests.Components.Controller
44 catch(CircularDependencyException)
49 [Test]
51 ExpectedException(typeof(HandlerException),
52 @"Can't create component 'compA' as it has dependencies to be satisfied.
53 compA is waiting for the following dependencies:
55 Services:
56 - Castle.Windsor.Tests.Components.CompB which was registered but is also waiting for dependencies.
58 compB is waiting for the following dependencies:
60 Services:
61 - Castle.Windsor.Tests.Components.CompC which was registered but is also waiting for dependencies.
63 compC is waiting for the following dependencies:
65 Services:
66 - Castle.Windsor.Tests.Components.CompD which was registered but is also waiting for dependencies.
68 compD is waiting for the following dependencies:
70 Services:
71 - Castle.Windsor.Tests.Components.CompA which was registered but is also waiting for dependencies.
74 public void ThrowsACircularDependencyException2()
76 IWindsorContainer container = new WindsorContainer();
77 container.AddComponent("compA", typeof(CompA));
78 container.AddComponent("compB", typeof(CompB));
79 container.AddComponent("compC", typeof(CompC));
80 container.AddComponent("compD", typeof(CompD));
82 container.Resolve("compA");
85 [Test]
86 public void ShouldNotGetCircularDepencyExceptionWhenResolvingTypeOnItselfWithDifferentModels()
88 WindsorContainer container = new WindsorContainer(ConfigHelper.ResolveConfigPath("IOC-51.xml"));
89 object o = container["path.fileFinder"];
90 Assert.IsNotNull(o);
94 namespace IOC51
96 using System.Reflection;
98 public interface IPathProvider
100 string Path { get; }
103 public class AssemblyPath : IPathProvider
105 public string Path
109 Uri uriPath = new Uri(Assembly.GetExecutingAssembly().GetName(false).CodeBase);
110 return uriPath.LocalPath;
115 public class RelativeFilePath : IPathProvider
117 public RelativeFilePath(IPathProvider basePathProvider, string extensionsPath)
119 _path = System.IO.Path.Combine(basePathProvider.Path + "\\", extensionsPath);
122 public string Path
124 get { return _path; }
127 private string _path;