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
.Configuration2
19 using Castle
.Core
.Configuration
;
20 using Castle
.Core
.Resource
;
21 using Castle
.MicroKernel
;
22 using Castle
.Windsor
.Configuration
.Interpreters
;
23 using NUnit
.Framework
;
26 public class IncludesTestCase
28 private String dir
= ConfigHelper
.ResolveConfigPath("Configuration2/");
30 private IWindsorContainer container
;
33 public void FileResourceAndIncludes()
35 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
36 "config_with_include.xml");
38 container
= new WindsorContainer(file
);
40 AssertConfiguration();
44 public void FileResourceAndRelativeIncludes()
46 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
47 "config_with_include_relative.xml");
49 container
= new WindsorContainer(file
);
51 AssertConfiguration();
55 public void FileResourceAndRelativeIncludes2()
57 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
58 "config_with_include_relative2.xml");
60 container
= new WindsorContainer(file
);
62 AssertConfiguration();
66 public void AssemblyResourceAndIncludes()
69 new AssemblyResource("assembly://Castle.Windsor.Tests/Configuration2/resource_config_with_include.xml");
71 container
= new WindsorContainer(new XmlInterpreter(resource
));
73 AssertConfiguration();
76 private void AssertConfiguration()
78 IConfigurationStore store
= container
.Kernel
.ConfigurationStore
;
80 Assert
.AreEqual(2, store
.GetFacilities().Length
);
81 Assert
.AreEqual(2, store
.GetComponents().Length
);
83 IConfiguration config
= store
.GetFacilityConfiguration("testidengine");
84 IConfiguration childItem
= config
.Children
["item"];
85 Assert
.IsNotNull(childItem
);
86 Assert
.AreEqual("value", childItem
.Value
);
88 config
= store
.GetFacilityConfiguration("testidengine2");
89 Assert
.IsNotNull(config
);
90 Assert
.AreEqual("value within CDATA section", config
.Value
);
92 config
= store
.GetComponentConfiguration("testidcomponent1");
93 childItem
= config
.Children
["item"];
94 Assert
.IsNotNull(childItem
);
95 Assert
.AreEqual("value1", childItem
.Value
);
97 config
= store
.GetComponentConfiguration("testidcomponent2");
98 childItem
= config
.Children
["item"];
99 Assert
.IsNotNull(childItem
);
100 Assert
.AreEqual("value2", childItem
.Value
);