2
2
using System . Collections . Generic ;
3
3
using NHibernate . Bytecode ;
4
4
using NHibernate . Connection ;
5
+ using NHibernate . Linq . Functions ;
5
6
using NHibernate . Test . CfgTest ;
6
7
using NHibernate . Util ;
7
8
using NUnit . Framework ;
@@ -58,6 +59,42 @@ public void GetInstanceByDefault()
58
59
Assert . That ( instance , Is . TypeOf < DebugConnectionProvider > ( ) ) ;
59
60
}
60
61
62
+ [ Test ]
63
+ public void GetInstanceByDefaultNull ( )
64
+ {
65
+ var instance = PropertiesHelper . GetInstance < IConnectionProvider > (
66
+ "conn" ,
67
+ new Dictionary < string , string > ( ) ,
68
+ null ) ;
69
+ Assert . That ( instance , Is . Null ) ;
70
+ }
71
+
72
+ [ Test ]
73
+ public void GetInstanceByDefaultWithExplicitServiceProvider ( )
74
+ {
75
+ Cfg . Environment . ServiceProvider = new SimpleServiceProvider ( true ) ;
76
+ var instance = PropertiesHelper . GetInstance < IConnectionProvider > (
77
+ "conn" ,
78
+ new Dictionary < string , string > ( ) ,
79
+ typeof ( DriverConnectionProvider ) ) ;
80
+ Assert . That ( instance , Is . Not . Null ) ;
81
+ Assert . That ( instance , Is . TypeOf < DriverConnectionProvider > ( ) ) ;
82
+ }
83
+
84
+ [ Test ]
85
+ public void GetExternalInstanceByDefaultWithExplicitServiceProvider ( )
86
+ {
87
+ Cfg . Environment . ServiceProvider = new SimpleServiceProvider ( true ) ;
88
+ Assert . Throws < HibernateException > (
89
+ ( ) =>
90
+ {
91
+ PropertiesHelper . GetInstance < IConnectionProvider > (
92
+ "conn" ,
93
+ new Dictionary < string , string > ( ) ,
94
+ typeof ( DebugConnectionProvider ) ) ;
95
+ } ) ;
96
+ }
97
+
61
98
[ Test ]
62
99
public void GetInstanceByRegistration ( )
63
100
{
@@ -77,12 +114,38 @@ public void GetInstanceByProperty()
77
114
{
78
115
var instance = PropertiesHelper . GetInstance < IConnectionProvider > (
79
116
"conn" ,
80
- new Dictionary < string , string > { { "conn" , typeof ( DriverConnectionProvider ) . AssemblyQualifiedName } } ,
117
+ new Dictionary < string , string > { { "conn" , typeof ( DriverConnectionProvider ) . AssemblyQualifiedName } } ,
118
+ typeof ( DebugConnectionProvider ) ) ;
119
+ Assert . That ( instance , Is . Not . Null ) ;
120
+ Assert . That ( instance , Is . TypeOf < DriverConnectionProvider > ( ) ) ;
121
+ }
122
+
123
+ [ Test ]
124
+ public void GetInstanceByPropertyWithExplicitServiceProvider ( )
125
+ {
126
+ Cfg . Environment . ServiceProvider = new SimpleServiceProvider ( true ) ;
127
+ var instance = PropertiesHelper . GetInstance < IConnectionProvider > (
128
+ "conn" ,
129
+ new Dictionary < string , string > { { "conn" , typeof ( DriverConnectionProvider ) . AssemblyQualifiedName } } ,
81
130
typeof ( DebugConnectionProvider ) ) ;
82
131
Assert . That ( instance , Is . Not . Null ) ;
83
132
Assert . That ( instance , Is . TypeOf < DriverConnectionProvider > ( ) ) ;
84
133
}
85
134
135
+ [ Test ]
136
+ public void GetExternalInstanceByPropertyWithExplicitServiceProvider ( )
137
+ {
138
+ Cfg . Environment . ServiceProvider = new SimpleServiceProvider ( true ) ;
139
+ Assert . Throws < HibernateException > (
140
+ ( ) =>
141
+ {
142
+ PropertiesHelper . GetInstance < IConnectionProvider > (
143
+ "conn" ,
144
+ new Dictionary < string , string > { { "conn" , typeof ( DebugConnectionProvider ) . AssemblyQualifiedName } } ,
145
+ typeof ( DriverConnectionProvider ) ) ;
146
+ } ) ;
147
+ }
148
+
86
149
[ Test ]
87
150
public void GetInstanceByInvalidDefault ( )
88
151
{
@@ -113,14 +176,55 @@ public void GetInstanceByInvalidRegistration()
113
176
}
114
177
115
178
[ Test ]
116
- public void GetInstanceByInvalidProperty ( )
179
+ public void GetInstanceByInvalidPropertyClassType ( )
180
+ {
181
+ Assert . Throws < HibernateException > (
182
+ ( ) =>
183
+ {
184
+ PropertiesHelper . GetInstance < IConnectionProvider > (
185
+ "conn" ,
186
+ new Dictionary < string , string > { { "conn" , typeof ( DefaultLinqToHqlGeneratorsRegistry ) . AssemblyQualifiedName } } ,
187
+ typeof ( DriverConnectionProvider ) ) ;
188
+ } ) ;
189
+ }
190
+
191
+ [ Test ]
192
+ public void GetInstanceByInvalidPropertyClassTypeWithExplicitServiceProvider ( )
193
+ {
194
+ Cfg . Environment . ServiceProvider = new SimpleServiceProvider ( true ) ;
195
+ Assert . Throws < HibernateException > (
196
+ ( ) =>
197
+ {
198
+ PropertiesHelper . GetInstance < IConnectionProvider > (
199
+ "conn" ,
200
+ new Dictionary < string , string > { { "conn" , typeof ( DefaultLinqToHqlGeneratorsRegistry ) . AssemblyQualifiedName } } ,
201
+ typeof ( DriverConnectionProvider ) ) ;
202
+ } ) ;
203
+ }
204
+
205
+ [ Test ]
206
+ public void GetInstanceByInvalidPropertyClassName ( )
207
+ {
208
+ Assert . Throws < HibernateException > (
209
+ ( ) =>
210
+ {
211
+ PropertiesHelper . GetInstance < IConnectionProvider > (
212
+ "conn" ,
213
+ new Dictionary < string , string > { { "conn" , "test" } } ,
214
+ typeof ( DriverConnectionProvider ) ) ;
215
+ } ) ;
216
+ }
217
+
218
+ [ Test ]
219
+ public void GetInstanceByInvalidPropertyClassNameWithExplicitServiceProvider ( )
117
220
{
221
+ Cfg . Environment . ServiceProvider = new SimpleServiceProvider ( true ) ;
118
222
Assert . Throws < HibernateException > (
119
223
( ) =>
120
224
{
121
225
PropertiesHelper . GetInstance < IConnectionProvider > (
122
226
"conn" ,
123
- new Dictionary < string , string > { { "conn" , typeof ( PropertiesHelperTest ) . AssemblyQualifiedName } } ,
227
+ new Dictionary < string , string > { { "conn" , "test" } } ,
124
228
typeof ( DriverConnectionProvider ) ) ;
125
229
} ) ;
126
230
}
0 commit comments