1 // Copyright 2004-2007 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
.Properties
19 using Castle
.Core
.Configuration
;
20 using Castle
.MicroKernel
;
21 using Castle
.Windsor
.Configuration
.Interpreters
.XmlProcessor
;
22 using NUnit
.Framework
;
25 public class PropertiesTestCase
27 private String dir
= ConfigHelper
.ResolveConfigPath("Configuration2/Properties/");
29 private IWindsorContainer container
;
32 public void CorrectEval()
34 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
35 "config_with_properties.xml");
37 container
= new WindsorContainer(file
);
39 AssertConfiguration();
43 public void SilentProperties()
45 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
46 "config_with_silent_properties.xml");
48 container
= new WindsorContainer(file
);
50 IConfigurationStore store
= container
.Kernel
.ConfigurationStore
;
52 Assert
.AreEqual(1, store
.GetFacilities().Length
, "Diff num of facilities");
53 Assert
.AreEqual(1, store
.GetComponents().Length
, "Diff num of components");
55 IConfiguration config
= store
.GetFacilityConfiguration("facility1");
56 IConfiguration childItem
= config
.Children
["param1"];
57 Assert
.IsNotNull(childItem
);
58 Assert
.AreEqual("prop1 value", childItem
.Value
);
59 Assert
.AreEqual("", childItem
.Attributes
["attr"]);
61 config
= store
.GetComponentConfiguration("component1");
62 childItem
= config
.Children
["param1"];
63 Assert
.IsNotNull(childItem
);
64 Assert
.AreEqual(null, childItem
.Value
);
65 Assert
.AreEqual("prop1 value", childItem
.Attributes
["attr"]);
68 [Test
, ExpectedException(typeof(ConfigurationProcessingException
))]
69 public void MissingProperties()
71 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
72 "config_with_missing_properties.xml");
74 container
= new WindsorContainer(file
);
78 public void PropertiesWithinProperties()
80 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
81 "properties_using_properties.xml");
83 container
= new WindsorContainer(file
);
85 AssertConfiguration();
89 public void PropertiesAndIncludes()
91 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
92 "config_with_properties_and_includes.xml");
94 container
= new WindsorContainer(file
);
96 AssertConfiguration();
100 public void PropertiesAndDefines()
102 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
103 "config_with_properties_and_defines.xml");
105 container
= new WindsorContainer(file
);
107 AssertConfiguration();
111 public void PropertiesAndDefines2()
113 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
114 "config_with_properties_and_defines2.xml");
116 container
= new WindsorContainer(file
);
118 AssertConfiguration();
121 private void AssertConfiguration()
123 IConfigurationStore store
= container
.Kernel
.ConfigurationStore
;
125 Assert
.AreEqual(3, store
.GetFacilities().Length
, "Diff num of facilities");
126 Assert
.AreEqual(2, store
.GetComponents().Length
, "Diff num of components");
128 IConfiguration config
= store
.GetFacilityConfiguration("facility1");
129 IConfiguration childItem
= config
.Children
["item"];
130 Assert
.IsNotNull(childItem
);
131 Assert
.AreEqual("prop1 value", childItem
.Value
);
133 config
= store
.GetFacilityConfiguration("facility2");
134 Assert
.IsNotNull(config
);
135 childItem
= config
.Children
["item"];
136 Assert
.IsNotNull(childItem
);
137 Assert
.AreEqual("prop2 value", childItem
.Attributes
["value"]);
138 Assert
.IsNull(childItem
.Value
);
140 config
= store
.GetFacilityConfiguration("facility3");
141 Assert
.IsNotNull(config
);
142 Assert
.AreEqual(3, config
.Children
.Count
, "facility3 should have 3 children");
144 childItem
= config
.Children
["param1"];
145 Assert
.IsNotNull(childItem
);
146 Assert
.AreEqual("prop2 value", childItem
.Value
);
147 Assert
.AreEqual("prop1 value", childItem
.Attributes
["attr"]);
149 childItem
= config
.Children
["param2"];
150 Assert
.IsNotNull(childItem
);
151 Assert
.AreEqual("prop1 value", childItem
.Value
);
152 Assert
.AreEqual("prop2 value", childItem
.Attributes
["attr"]);
154 childItem
= config
.Children
["param3"];
155 Assert
.IsNotNull(childItem
);
156 Assert
.AreEqual("param3 attr", childItem
.Attributes
["attr"]);
158 childItem
= childItem
.Children
["value"];
159 Assert
.IsNotNull(childItem
);
160 Assert
.AreEqual("param3 value", childItem
.Value
);
161 Assert
.AreEqual("param3 value attr", childItem
.Attributes
["attr"]);
163 config
= store
.GetComponentConfiguration("component1");
164 childItem
= config
.Children
["item"];
165 Assert
.IsNotNull(childItem
);
166 Assert
.AreEqual("prop1 value", childItem
.Value
);
168 config
= store
.GetComponentConfiguration("component2");
169 childItem
= config
.Children
["item"];
170 Assert
.IsNotNull(childItem
);
171 Assert
.AreEqual("prop2 value", childItem
.Attributes
["value"]);