Added RedirectUsingNamedRoute
[castle.git] / ActiveRecord / Castle.ActiveRecord.Tests / Config / ConfigurationSource.cs
blob7490df15069833820ad3323f2edb50c9844fd006
1 // Copyright 2004-2008 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.ActiveRecord.Tests.Config
17 using System;
18 using System.IO;
19 using Castle.ActiveRecord.Framework;
20 using Castle.ActiveRecord.Framework.Config;
21 using Castle.ActiveRecord.Framework.Scopes;
22 using NUnit.Framework;
24 [TestFixture]
25 public class ConfigurationSource
27 [Test]
28 public void TestLoadDefaultThreadScopeConfig()
30 String xmlConfig = @"<activerecord>" + GetDefaultHibernateConfigAndCloseActiveRecordSection();
32 //null == use default. == typeof(ThreadScopeInfo);
33 Type expectedType = null;
35 AssertConfig(xmlConfig, expectedType, null);
39 [Test]
40 public void TestLoadWebThreadScopeInfo()
42 String xmlConfig = @"<activerecord isWeb=""true"">" + GetDefaultHibernateConfigAndCloseActiveRecordSection();
44 Type expectedType = typeof(WebThreadScopeInfo);
46 AssertConfig(xmlConfig, expectedType, null);
50 [Test]
51 public void TestDefaultSessionFactoryHolder()
53 String xmlConfig = @"<activerecord isWeb=""true"">" + GetDefaultHibernateConfigAndCloseActiveRecordSection();
55 Type sfh = typeof(SessionFactoryHolder);
57 AssertConfig(xmlConfig, null, sfh);
61 [Test]
62 public void TestCustomSessionFactoryholder()
64 String xmlConfig =
65 @"<activerecord isWeb=""true"" sessionfactoryholdertype=""Castle.ActiveRecord.Tests.Config.MySessionFactoryHolder, Castle.ActiveRecord.Tests"">"
66 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
68 Type sfh = typeof(MySessionFactoryHolder);
70 AssertConfig(xmlConfig, null, sfh);
74 [Test]
75 public void TestDebug()
77 String xmlConfig =
78 @"<activerecord isDebug=""true"" isWeb=""true"" sessionfactoryholdertype=""Castle.ActiveRecord.Tests.Config.MySessionFactoryHolder, Castle.ActiveRecord.Tests"">"
79 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
81 AssertConfig(xmlConfig, null, null, true, false, false);
84 [Test]
85 public void TestPluralizeTableNames()
87 String xmlConfig1 =
88 @"<activerecord pluralizeTableNames=""true"">"
89 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
91 AssertConfig(xmlConfig1, null, null, false, true, false);
93 String xmlConfig2 =
94 @"<activerecord pluralizeTableNames=""false"">"
95 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
97 AssertConfig(xmlConfig2, null, null, false, false, false);
99 String xmlConfig3 =
100 @"<activerecord>"
101 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
103 AssertConfig(xmlConfig3, null, null, false, false, false);
106 [Test]
107 public void TestVerifyModelsAgainstDBSchema()
109 String xmlConfig1 =
110 @"<activerecord verifyModelsAgainstDBSchema=""true"">"
111 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
113 AssertConfig(xmlConfig1, null, null, false, false, true);
115 String xmlConfig2 =
116 @"<activerecord verifyModelsAgainstDBSchema=""false"">"
117 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
119 AssertConfig(xmlConfig2, null, null, false, false, false);
121 String xmlConfig3 =
122 @"<activerecord>"
123 + GetDefaultHibernateConfigAndCloseActiveRecordSection();
125 AssertConfig(xmlConfig3, null, null, false, false, false);
129 private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType)
131 AssertConfig(xmlConfig, webinfotype, sessionFactoryHolderType, false, false, false);
134 private static void AssertConfig(string xmlConfig, Type webinfotype, Type sessionFactoryHolderType, bool isDebug,
135 bool pluralize, bool verifyModelsAgainstDBSchema)
137 StringReader sr = new StringReader(xmlConfig);
139 XmlConfigurationSource c = new XmlConfigurationSource(sr);
141 if (null != webinfotype)
143 Assert.IsTrue(c.ThreadScopeInfoImplementation == webinfotype,
144 "Expected {0}, Got {1}", webinfotype, c.ThreadScopeInfoImplementation);
147 if (null != sessionFactoryHolderType)
149 Assert.IsTrue(c.SessionFactoryHolderImplementation == sessionFactoryHolderType,
150 "Expected {0}, Got {1}", sessionFactoryHolderType, c.SessionFactoryHolderImplementation);
153 Assert.IsTrue(c.Debug == isDebug);
154 Assert.IsTrue(c.PluralizeTableNames == pluralize);
155 Assert.IsTrue(c.VerifyModelsAgainstDBSchema == verifyModelsAgainstDBSchema);
158 private static string GetDefaultHibernateConfigAndCloseActiveRecordSection()
160 return @" <config>
161 <add key=""connection.driver_class"" value=""NHibernate.Driver.SqlClientDriver"" />
162 <add key=""dialect"" value=""NHibernate.Dialect.MsSql2000Dialect"" />
163 <add key=""connection.provider"" value=""NHibernate.Connection.DriverConnectionProvider"" />
164 <add key=""connection.connection_string"" value=""Data Source=.;Initial Catalog=test;Integrated Security=True;Pooling=False"" />
165 </config>
166 </activerecord>";
171 public class MySessionFactoryHolder : SessionFactoryHolder