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
17 using Castle
.Core
.Configuration
;
18 using Castle
.Core
.Resource
;
19 using Castle
.MicroKernel
;
20 using Castle
.MicroKernel
.SubSystems
.Configuration
;
21 using Castle
.Windsor
.Configuration
.Interpreters
;
22 using Castle
.Windsor
.Configuration
.Interpreters
.XmlProcessor
;
23 using NUnit
.Framework
;
26 public class ConfigXmlInterpreterTestCase
29 public void ProperDeserialization()
31 DefaultConfigurationStore store
= new DefaultConfigurationStore();
33 XmlInterpreter interpreter
= new XmlInterpreter(ConfigHelper
.ResolveConfigPath("sample_config.xml"));
34 interpreter
.ProcessResource(interpreter
.Source
, store
);
36 Assert
.AreEqual(2, store
.GetFacilities().Length
);
37 Assert
.AreEqual(2, store
.GetComponents().Length
);
38 Assert
.AreEqual(2, store
.GetConfigurationForChildContainers().Length
);
40 IConfiguration config
= store
.GetFacilityConfiguration("testidengine");
41 IConfiguration childItem
= config
.Children
["item"];
42 Assert
.IsNotNull(childItem
);
43 Assert
.AreEqual("value", childItem
.Value
);
45 config
= store
.GetFacilityConfiguration("testidengine2");
46 Assert
.IsNotNull(config
);
47 Assert
.AreEqual("value within CDATA section", config
.Value
);
49 config
= store
.GetComponentConfiguration("testidcomponent1");
50 childItem
= config
.Children
["item"];
51 Assert
.IsNotNull(childItem
);
52 Assert
.AreEqual("value1", childItem
.Value
);
54 config
= store
.GetComponentConfiguration("testidcomponent2");
55 childItem
= config
.Children
["item"];
56 Assert
.IsNotNull(childItem
);
57 Assert
.AreEqual("value2", childItem
.Value
);
59 config
= store
.GetChildContainerConfiguration("child1");
60 Assert
.IsNotNull(config
);
61 Assert
.AreEqual(config
.Attributes
["name"], "child1");
62 Assert
.AreEqual("<configuration />", config
.Value
);
64 config
= store
.GetChildContainerConfiguration("child2");
65 Assert
.IsNotNull(config
);
66 Assert
.AreEqual(config
.Attributes
["name"], "child2");
67 Assert
.AreEqual("<configuration />", config
.Value
);
71 public void CorrectConfigurationMapping()
73 DefaultConfigurationStore store
= new DefaultConfigurationStore();
74 XmlInterpreter interpreter
= new XmlInterpreter(ConfigHelper
.ResolveConfigPath("sample_config.xml"));
75 interpreter
.ProcessResource(interpreter
.Source
, store
);
77 WindsorContainer container
= new WindsorContainer(store
);
79 container
.AddFacility("testidengine", new DummyFacility());
83 public void ProperManifestDeserialization()
85 DefaultConfigurationStore store
= new DefaultConfigurationStore();
86 XmlInterpreter interpreter
= new XmlInterpreter(
87 new AssemblyResource("assembly://Castle.Windsor.Tests/Configuration/sample_config.xml"));
88 interpreter
.ProcessResource(interpreter
.Source
, store
);
90 Assert
.AreEqual(2, store
.GetFacilities().Length
);
91 Assert
.AreEqual(2, store
.GetComponents().Length
);
92 Assert
.AreEqual(2, store
.GetConfigurationForChildContainers().Length
);
94 IConfiguration config
= store
.GetFacilityConfiguration("testidengine");
95 IConfiguration childItem
= config
.Children
["item"];
96 Assert
.IsNotNull(childItem
);
97 Assert
.AreEqual("value", childItem
.Value
);
99 config
= store
.GetFacilityConfiguration("testidengine2");
100 Assert
.IsNotNull(config
);
101 Assert
.AreEqual("value within CDATA section", config
.Value
);
103 config
= store
.GetComponentConfiguration("testidcomponent1");
104 childItem
= config
.Children
["item"];
105 Assert
.IsNotNull(childItem
);
106 Assert
.AreEqual("value1", childItem
.Value
);
108 config
= store
.GetComponentConfiguration("testidcomponent2");
109 childItem
= config
.Children
["item"];
110 Assert
.IsNotNull(childItem
);
111 Assert
.AreEqual("value2", childItem
.Value
);
113 config
= store
.GetChildContainerConfiguration("child1");
114 Assert
.IsNotNull(config
);
115 Assert
.AreEqual(config
.Attributes
["name"], "child1");
116 Assert
.AreEqual("<configuration />", config
.Value
);
118 config
= store
.GetChildContainerConfiguration("child2");
119 Assert
.IsNotNull(config
);
120 Assert
.AreEqual(config
.Attributes
["name"], "child2");
121 Assert
.AreEqual("<configuration />", config
.Value
);
125 [ExpectedException(typeof(ConfigurationProcessingException
))]
126 public void MissingManifestResourceConfiguration()
128 DefaultConfigurationStore store
= new DefaultConfigurationStore();
129 AssemblyResource source
= new AssemblyResource("assembly://Castle.Windsor.Tests/missing_config.xml");
130 new XmlInterpreter(source
).ProcessResource(source
, store
);
134 public class DummyFacility
: IFacility
136 public void Init(IKernel kernel
, IConfiguration facilityConfig
)
138 Assert
.IsNotNull(facilityConfig
);
139 IConfiguration childItem
= facilityConfig
.Children
["item"];
140 Assert
.IsNotNull(childItem
);
141 Assert
.AreEqual("value", childItem
.Value
);
144 public void Terminate()