22using System . Collections . Generic ;
33using NHibernate . Bytecode ;
44using NHibernate . Connection ;
5+ using NHibernate . Linq . Functions ;
56using NHibernate . Test . CfgTest ;
67using NHibernate . Util ;
78using NUnit . Framework ;
@@ -58,6 +59,42 @@ public void GetInstanceByDefault()
5859 Assert . That ( instance , Is . TypeOf < DebugConnectionProvider > ( ) ) ;
5960 }
6061
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+
6198 [ Test ]
6299 public void GetInstanceByRegistration ( )
63100 {
@@ -77,12 +114,38 @@ public void GetInstanceByProperty()
77114 {
78115 var instance = PropertiesHelper . GetInstance < IConnectionProvider > (
79116 "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 } } ,
81130 typeof ( DebugConnectionProvider ) ) ;
82131 Assert . That ( instance , Is . Not . Null ) ;
83132 Assert . That ( instance , Is . TypeOf < DriverConnectionProvider > ( ) ) ;
84133 }
85134
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+
86149 [ Test ]
87150 public void GetInstanceByInvalidDefault ( )
88151 {
@@ -113,14 +176,55 @@ public void GetInstanceByInvalidRegistration()
113176 }
114177
115178 [ 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 ( )
117220 {
221+ Cfg . Environment . ServiceProvider = new SimpleServiceProvider ( true ) ;
118222 Assert . Throws < HibernateException > (
119223 ( ) =>
120224 {
121225 PropertiesHelper . GetInstance < IConnectionProvider > (
122226 "conn" ,
123- new Dictionary < string , string > { { "conn" , typeof ( PropertiesHelperTest ) . AssemblyQualifiedName } } ,
227+ new Dictionary < string , string > { { "conn" , "test" } } ,
124228 typeof ( DriverConnectionProvider ) ) ;
125229 } ) ;
126230 }
0 commit comments