Skip to content

Commit c81830b

Browse files
committed
Merge branch 'master' of https://github.com/benfulton/fluent-nhibernate into benfulton-master
2 parents 8e7d91b + 87e57e1 commit c81830b

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[core]
2+
autocrlf = false

src/FluentNHibernate.Testing/Cfg/Db/PersistenceConfigurationTester.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ public string ValueOf(string key)
3030
}
3131
#endregion
3232

33+
[Test]
34+
public void ConfigureProperties_should_not_override_values_already_set()
35+
{
36+
_nhibConfig = new Configuration();
37+
_nhibConfig.Properties["proxyfactory.factory_class"] = "foo";
38+
ValueOf("proxyfactory.factory_class").ShouldEqual("foo");
39+
40+
}
41+
42+
[Test]
43+
public void ConfigureProperties_should_override_values_already_set_with_values_set_in_code()
44+
{
45+
_nhibConfig = new Configuration();
46+
_nhibConfig.Properties["proxyfactory.factory_class"] = "foo";
47+
_config.ProxyFactoryFactory("bar").ConfigureProperties(_nhibConfig);
48+
ValueOf("proxyfactory.factory_class").ShouldEqual("bar");
49+
50+
}
51+
3352
[Test]
3453
public void Setting_raw_values_should_populate_dictionary()
3554
{

src/FluentNHibernate/Cfg/Db/PersistenceConfiguration.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Data;
4+
using System.Linq;
45
using NHibernate.Bytecode;
56
using NHibernate.Connection;
67
using NHibernate.Dialect;
@@ -67,12 +68,34 @@ protected virtual IDictionary<string, string> CreateProperties()
6768

6869
return values;
6970
}
71+
72+
static IEnumerable<string> OverridenDefaults(IDictionary<string,string> settings)
73+
{
74+
if (settings[ConnectionProviderKey] != DefaultConnectionProviderClassName)
75+
yield return ConnectionProviderKey;
76+
77+
if (settings[ProxyFactoryFactoryClassKey] != DefaultProxyFactoryFactoryClassName)
78+
yield return ProxyFactoryFactoryClassKey;
79+
}
80+
81+
private static IEnumerable<string> KeysToPreserve(NHibConfiguration nhibernateConfig, IDictionary<string, string> settings)
82+
{
83+
var @default = new NHibConfiguration();
84+
return nhibernateConfig.Properties
85+
.Except(@default.Properties)
86+
.Select(k => k.Key)
87+
.Except(OverridenDefaults(settings));
88+
}
7089

7190
public NHibConfiguration ConfigureProperties(NHibConfiguration nhibernateConfig)
7291
{
7392
var settings = CreateProperties();
93+
var keepers = KeysToPreserve(nhibernateConfig, settings);
7494

75-
nhibernateConfig.SetProperties(settings);
95+
foreach (var kv in settings.Where(s => !keepers.Contains(s.Key)))
96+
{
97+
nhibernateConfig.SetProperty(kv.Key, kv.Value);
98+
}
7699

77100
return nhibernateConfig;
78101
}

0 commit comments

Comments
 (0)