Skip to content

Commit f2cf9a5

Browse files
committed
Fluent configuration implemented
SVN: trunk@4551
1 parent 3b5ec8f commit f2cf9a5

File tree

6 files changed

+562
-23
lines changed

6 files changed

+562
-23
lines changed

Diff for: src/NHibernate.Test/CfgTest/Loquacious/ConfigurationFixture.cs

+55-5
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
using NHibernate.Exceptions;
1111
using NHibernate.Hql.Classic;
1212
using NHibernate.Type;
13+
using NUnit.Framework;
1314

1415
namespace NHibernate.Test.CfgTest.Loquacious
1516
{
17+
[TestFixture]
1618
public class ConfigurationFixture
1719
{
18-
public void ProofOfConcept()
20+
[Test]
21+
public void CompleteConfiguration()
1922
{
2023
// Here I'm configuring near all properties outside the scope of Configuration class
2124
// Using the Configuration class the user can add mappings and configure listeners
@@ -42,27 +45,67 @@ public void ProofOfConcept()
4245
.AutoQuoteKeywords()
4346
.BatchingQueries
4447
.Through<SqlClientBatchingBatcherFactory>()
45-
.Each(10)
48+
.Each(15)
4649
.Connected
4750
.Through<DebugConnectionProvider>()
4851
.By<SqlClientDriver>()
4952
.Releasing(ConnectionReleaseMode.AfterTransaction)
5053
.With(IsolationLevel.ReadCommitted)
51-
.Using("The connection string but it has some overload")
54+
.Using("The connection string")
5255
.CreateCommands
5356
.AutoCommentingSql()
5457
.ConvertingExceptionsThrough<SQLStateConverter>()
5558
.Preparing()
5659
.WithTimeout(10)
57-
.WithMaximumDepthOfOuterJoinFetching(10)
60+
.WithMaximumDepthOfOuterJoinFetching(11)
5861
.WithHqlToSqlSubstitutions("true 1, false 0, yes 'Y', no 'N'")
5962
.Schema
6063
.Validating()
6164
;
6265

66+
Assert.That(cfg.Properties[Environment.SessionFactoryName], Is.EqualTo("SomeName"));
67+
Assert.That(cfg.Properties[Environment.CacheProvider],
68+
Is.EqualTo(typeof(HashtableCacheProvider).AssemblyQualifiedName));
69+
Assert.That(cfg.Properties[Environment.CacheRegionPrefix], Is.EqualTo("xyz"));
70+
Assert.That(cfg.Properties[Environment.QueryCacheFactory],
71+
Is.EqualTo(typeof(StandardQueryCache).AssemblyQualifiedName));
72+
Assert.That(cfg.Properties[Environment.UseMinimalPuts], Is.EqualTo("true"));
73+
Assert.That(cfg.Properties[Environment.CacheDefaultExpiration], Is.EqualTo("15"));
74+
Assert.That(cfg.Properties[Environment.CollectionTypeFactoryClass],
75+
Is.EqualTo(typeof(DefaultCollectionTypeFactory).AssemblyQualifiedName));
76+
Assert.That(cfg.Properties[Environment.UseProxyValidator], Is.EqualTo("false"));
77+
Assert.That(cfg.Properties[Environment.ProxyFactoryFactoryClass],
78+
Is.EqualTo(typeof(ProxyFactoryFactory).AssemblyQualifiedName));
79+
Assert.That(cfg.Properties[Environment.QueryTranslator],
80+
Is.EqualTo(typeof(ClassicQueryTranslatorFactory).AssemblyQualifiedName));
81+
Assert.That(cfg.Properties[Environment.DefaultCatalog], Is.EqualTo("MyCatalog"));
82+
Assert.That(cfg.Properties[Environment.DefaultSchema], Is.EqualTo("MySche"));
83+
Assert.That(cfg.Properties[Environment.Dialect],
84+
Is.EqualTo(typeof(MsSql2000Dialect).AssemblyQualifiedName));
85+
Assert.That(cfg.Properties[Environment.Hbm2ddlKeyWords], Is.EqualTo("auto-quote"));
86+
Assert.That(cfg.Properties[Environment.BatchStrategy],
87+
Is.EqualTo(typeof(SqlClientBatchingBatcherFactory).AssemblyQualifiedName));
88+
Assert.That(cfg.Properties[Environment.BatchSize], Is.EqualTo("15"));
89+
Assert.That(cfg.Properties[Environment.ConnectionProvider],
90+
Is.EqualTo(typeof(DebugConnectionProvider).AssemblyQualifiedName));
91+
Assert.That(cfg.Properties[Environment.ConnectionDriver],
92+
Is.EqualTo(typeof(SqlClientDriver).AssemblyQualifiedName));
93+
Assert.That(cfg.Properties[Environment.ReleaseConnections],
94+
Is.EqualTo(ConnectionReleaseModeParser.ToString(ConnectionReleaseMode.AfterTransaction)));
95+
Assert.That(cfg.Properties[Environment.Isolation], Is.EqualTo("ReadCommitted"));
96+
Assert.That(cfg.Properties[Environment.ConnectionString], Is.EqualTo("The connection string"));
97+
Assert.That(cfg.Properties[Environment.UseSqlComments], Is.EqualTo("true"));
98+
Assert.That(cfg.Properties[Environment.SqlExceptionConverter],
99+
Is.EqualTo(typeof(SQLStateConverter).AssemblyQualifiedName));
100+
Assert.That(cfg.Properties[Environment.PrepareSql], Is.EqualTo("true"));
101+
Assert.That(cfg.Properties[Environment.CommandTimeout], Is.EqualTo("10"));
102+
Assert.That(cfg.Properties[Environment.MaxFetchDepth], Is.EqualTo("11"));
103+
Assert.That(cfg.Properties[Environment.QuerySubstitutions], Is.EqualTo("true 1, false 0, yes 'Y', no 'N'"));
104+
Assert.That(cfg.Properties[Environment.Hbm2ddlAuto], Is.EqualTo("validate"));
63105
}
64106

65-
public void ProofOfConceptMinimalConfiguration()
107+
[Test]
108+
public void UseDbConfigurationStringBuilder()
66109
{
67110
// This is a possible minimal configuration
68111
// in this case we must define best default properties for each dialect
@@ -79,6 +122,13 @@ public void ProofOfConceptMinimalConfiguration()
79122
InitialCatalog = "nhibernate",
80123
IntegratedSecurity = true
81124
});
125+
126+
Assert.That(cfg.Properties[Environment.ProxyFactoryFactoryClass],
127+
Is.EqualTo(typeof (ProxyFactoryFactory).AssemblyQualifiedName));
128+
Assert.That(cfg.Properties[Environment.Dialect],
129+
Is.EqualTo(typeof(MsSql2005Dialect).AssemblyQualifiedName));
130+
Assert.That(cfg.Properties[Environment.ConnectionString],
131+
Is.EqualTo("Data Source=(local);Initial Catalog=nhibernate;Integrated Security=True"));
82132
}
83133
}
84134
}

Diff for: src/NHibernate/Cfg/Loquacious/ConfigurationExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static class ConfigurationExtensions
44
{
55
public static IFluentSessionFactoryConfiguration SessionFactory(this Configuration configuration)
66
{
7-
return null;
7+
return new FluentSessionFactoryConfiguration(configuration);
88
}
99
}
1010
}

0 commit comments

Comments
 (0)