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
.MicroKernel
;
21 using NUnit
.Framework
;
24 public class ConfigWithStatementsTestCase
26 private String dir
= ConfigHelper
.ResolveConfigPath("Configuration2/");
28 private IWindsorContainer container
;
31 public void SimpleIf()
33 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
34 "config_with_if_stmt.xml");
36 container
= new WindsorContainer(file
);
38 IConfigurationStore store
= container
.Kernel
.ConfigurationStore
;
40 Assert
.AreEqual(4, store
.GetComponents().Length
);
42 IConfiguration config
= store
.GetComponentConfiguration("debug");
43 Assert
.IsNotNull(config
);
45 IConfiguration childItem
= config
.Children
["item"];
46 Assert
.IsNotNull(childItem
);
47 Assert
.AreEqual("some value", childItem
.Value
);
49 childItem
= config
.Children
["item2"];
50 Assert
.IsNotNull(childItem
);
51 Assert
.AreEqual("some <&> value2", childItem
.Value
);
53 config
= store
.GetComponentConfiguration("qa");
54 Assert
.IsNotNull(config
);
56 config
= store
.GetComponentConfiguration("default");
57 Assert
.IsNotNull(config
);
59 config
= store
.GetComponentConfiguration("notprod");
60 Assert
.IsNotNull(config
);
64 public void SimpleChoose()
66 foreach(string flag
in new string[] {"debug", "prod", "qa", "default"}
)
68 String file
= Path
.Combine(AppDomain
.CurrentDomain
.BaseDirectory
, dir
+
69 "config_with_define_" + flag
+ ".xml");
71 container
= new WindsorContainer(file
);
73 IConfigurationStore store
= container
.Kernel
.ConfigurationStore
;
75 Assert
.AreEqual(1, store
.GetComponents().Length
);
77 IConfiguration config
= store
.GetComponentConfiguration(flag
);
79 Assert
.IsNotNull(config
);