1
+ using System ;
1
2
using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using NHibernate . Cfg ;
4
5
using NHibernate . Engine ;
5
6
using NHibernate . Mapping ;
6
7
using NHibernate . Tool . hbm2ddl ;
7
8
using NUnit . Framework ;
9
+ using Environment = NHibernate . Cfg . Environment ;
8
10
9
11
namespace NHibernate . Test . Tools . hbm2ddl . SchemaMetadataUpdaterTest
10
12
{
@@ -23,8 +25,8 @@ public void CanRetrieveReservedWords()
23
25
var metaData = dialect . GetDataBaseSchema ( connectionHelper . Connection ) ;
24
26
var reserved = metaData . GetReservedWords ( ) ;
25
27
Assert . That ( reserved , Is . Not . Empty ) ;
26
- Assert . That ( reserved , Has . Member ( "SELECT" ) ) ;
27
- Assert . That ( reserved , Has . Member ( "FROM" ) ) ;
28
+ Assert . That ( reserved , Has . Member ( "SELECT" ) . IgnoreCase ) ;
29
+ Assert . That ( reserved , Has . Member ( "FROM" ) . IgnoreCase ) ;
28
30
}
29
31
finally
30
32
{
@@ -35,7 +37,7 @@ public void CanRetrieveReservedWords()
35
37
[ Test ]
36
38
public void UpdateReservedWordsInDialect ( )
37
39
{
38
- var reservedDb = new HashSet < string > ( ) ;
40
+ var reservedDb = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
39
41
var configuration = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
40
42
var dialect = Dialect . Dialect . GetDialect ( configuration . Properties ) ;
41
43
var connectionHelper = new ManagedProviderConnectionHelper ( configuration . Properties ) ;
@@ -55,7 +57,7 @@ public void UpdateReservedWordsInDialect()
55
57
56
58
var sf = ( ISessionFactoryImplementor ) configuration . BuildSessionFactory ( ) ;
57
59
SchemaMetadataUpdater . Update ( sf ) ;
58
- var match = reservedDb . Intersect ( sf . Dialect . Keywords ) ;
60
+ var match = reservedDb . Intersect ( sf . Dialect . Keywords , StringComparer . OrdinalIgnoreCase ) ;
59
61
Assert . That ( match , Is . EquivalentTo ( reservedDb ) ) ;
60
62
}
61
63
@@ -66,14 +68,19 @@ public void ExplicitAutoQuote()
66
68
configuration . AddResource ( "NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml" ,
67
69
GetType ( ) . Assembly ) ;
68
70
69
- SchemaMetadataUpdater . QuoteTableAndColumns ( configuration ) ;
71
+ var dialect = Dialect . Dialect . GetDialect ( configuration . GetDerivedProperties ( ) ) ;
72
+ dialect . Keywords . Add ( "Abracadabra" ) ;
73
+
74
+ SchemaMetadataUpdater . Update ( configuration , dialect ) ;
75
+ SchemaMetadataUpdater . QuoteTableAndColumns ( configuration , dialect ) ;
70
76
71
77
var cm = configuration . GetClassMapping ( typeof ( Order ) ) ;
72
78
Assert . That ( cm . Table . IsQuoted ) ;
73
79
var culs = new List < Column > ( cm . Table . ColumnIterator ) ;
74
80
Assert . That ( GetColumnByName ( culs , "From" ) . IsQuoted ) ;
75
81
Assert . That ( GetColumnByName ( culs , "And" ) . IsQuoted ) ;
76
82
Assert . That ( GetColumnByName ( culs , "Select" ) . IsQuoted ) ;
83
+ Assert . That ( GetColumnByName ( culs , "Abracadabra" ) . IsQuoted ) ;
77
84
Assert . That ( ! GetColumnByName ( culs , "Name" ) . IsQuoted ) ;
78
85
}
79
86
@@ -97,7 +104,7 @@ public void AutoQuoteTableAndColumnsAtStratup()
97
104
[ Test ]
98
105
public void AutoQuoteTableAndColumnsAtStratupIncludeKeyWordsImport ( )
99
106
{
100
- var reservedDb = new HashSet < string > ( ) ;
107
+ var reservedDb = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
101
108
var configuration = TestConfigurationHelper . GetDefaultConfiguration ( ) ;
102
109
var dialect = Dialect . Dialect . GetDialect ( configuration . Properties ) ;
103
110
var connectionHelper = new ManagedProviderConnectionHelper ( configuration . Properties ) ;
@@ -119,8 +126,8 @@ public void AutoQuoteTableAndColumnsAtStratupIncludeKeyWordsImport()
119
126
configuration . AddResource ( "NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml" ,
120
127
GetType ( ) . Assembly ) ;
121
128
var sf = ( ISessionFactoryImplementor ) configuration . BuildSessionFactory ( ) ;
122
- var match = reservedDb . Intersect ( sf . Dialect . Keywords ) ;
123
- Assert . That ( match , Is . EquivalentTo ( reservedDb ) ) ;
129
+ var match = reservedDb . Intersect ( sf . Dialect . Keywords , StringComparer . OrdinalIgnoreCase ) ;
130
+ Assert . That ( match , Is . EquivalentTo ( reservedDb ) . IgnoreCase ) ;
124
131
}
125
132
126
133
private static Column GetColumnByName ( IEnumerable < Column > columns , string colName )
@@ -167,14 +174,19 @@ public void WhenConfiguredOnlyExplicitAutoQuote()
167
174
configuration . AddResource ( "NHibernate.Test.Tools.hbm2ddl.SchemaMetadataUpdaterTest.HeavyEntity.hbm.xml" ,
168
175
GetType ( ) . Assembly ) ;
169
176
170
- SchemaMetadataUpdater . QuoteTableAndColumns ( configuration ) ;
177
+ var dialect = Dialect . Dialect . GetDialect ( configuration . GetDerivedProperties ( ) ) ;
178
+ dialect . Keywords . Add ( "Abracadabra" ) ;
179
+
180
+ SchemaMetadataUpdater . Update ( configuration , dialect ) ;
181
+ SchemaMetadataUpdater . QuoteTableAndColumns ( configuration , dialect ) ;
171
182
172
183
var cm = configuration . GetClassMapping ( typeof ( Order ) ) ;
173
184
Assert . That ( cm . Table . IsQuoted ) ;
174
185
var culs = new List < Column > ( cm . Table . ColumnIterator ) ;
175
186
Assert . That ( GetColumnByName ( culs , "From" ) . IsQuoted ) ;
176
187
Assert . That ( GetColumnByName ( culs , "And" ) . IsQuoted ) ;
177
188
Assert . That ( GetColumnByName ( culs , "Select" ) . IsQuoted ) ;
189
+ Assert . That ( GetColumnByName ( culs , "Abracadabra" ) . IsQuoted ) ;
178
190
Assert . That ( ! GetColumnByName ( culs , "Name" ) . IsQuoted ) ;
179
191
}
180
192
}
0 commit comments