@@ -180,6 +180,52 @@ public void Generate_T_SimpleClass_HasSelect()
180180 Compare ( q , expected ) ;
181181 }
182182
183+ [ Fact ]
184+ public void ForType_NullQuery_Throws ( )
185+ {
186+ Query query = null ;
187+ Action act = ( ) => query . ForType < MyClass > ( ) ;
188+ act . Should ( ) . Throw < ArgumentNullException > ( ) ;
189+ }
190+
191+ [ Fact ]
192+ public void GenerateSelect_NullQuery_Throws ( )
193+ {
194+ Query query = null ;
195+ Action act = ( ) => query . GenerateSelect < MyClass > ( ) ;
196+ act . Should ( ) . Throw < ArgumentNullException > ( ) ;
197+ }
198+
199+ [ Fact ]
200+ public void ForType_NullMapper_Throws ( )
201+ {
202+ try
203+ {
204+ SqlKataExtensions . DefaultMapper = null ;
205+ Action act = ( ) => new Query ( ) . ForType < MyClass > ( null ) ;
206+ act . Should ( ) . Throw < ArgumentNullException > ( ) ;
207+ }
208+ finally
209+ {
210+ SqlKataExtensions . DefaultMapper = new ConventionMapper ( ) ;
211+ }
212+ }
213+
214+ [ Fact ]
215+ public void GenerateSelect_NullMapper_Throws ( )
216+ {
217+ try
218+ {
219+ SqlKataExtensions . DefaultMapper = null ;
220+ Action act = ( ) => new Query ( ) . GenerateSelect < MyClass > ( null ) ;
221+ act . Should ( ) . Throw < ArgumentNullException > ( ) ;
222+ }
223+ finally
224+ {
225+ SqlKataExtensions . DefaultMapper = new ConventionMapper ( ) ;
226+ }
227+ }
228+
183229 [ Theory ]
184230 [ MemberData ( nameof ( Mappers ) ) ]
185231 public void Different_Mappers ( IMapper mapper , string tableName , params string [ ] fieldNames )
@@ -200,24 +246,28 @@ public void Different_Mappers(IMapper mapper, string tableName, params string[]
200246 [ MemberData ( nameof ( Mappers ) ) ]
201247 public void Different_Default_Mappers ( IMapper mapper , string tableName , params string [ ] fieldNames )
202248 {
203- try
249+ if ( mapper != null )
204250 {
205- SqlKataExtensions . DefaultMapper = mapper ;
206- var q = new Query ( ) . GenerateSelect < MyOtherClass > ( ) ;
207- var expected = new Query ( tableName ) . Select ( fieldNames ) ;
208- Compare ( q , expected ) ;
209- }
210- finally
211- {
212- SqlKataExtensions . DefaultMapper = new ConventionMapper ( ) ;
213- PetaPoco . Mappers . RevokeAll ( ) ;
251+ try
252+ {
253+ SqlKataExtensions . DefaultMapper = mapper ;
254+ var q = new Query ( ) . GenerateSelect < MyOtherClass > ( ) ;
255+ var expected = new Query ( tableName ) . Select ( fieldNames ) ;
256+ Compare ( q , expected ) ;
257+ }
258+ finally
259+ {
260+ SqlKataExtensions . DefaultMapper = new ConventionMapper ( ) ;
261+ PetaPoco . Mappers . RevokeAll ( ) ;
262+ }
214263 }
215264 }
216265
217266 public static IEnumerable < object [ ] > Mappers => new [ ]
218267 {
219268 new object [ ] { new UnderscoreMapper ( ) , "my_other_class" , "other_id" , "other_name" } ,
220269 new object [ ] { new ConventionMapper ( ) , "MyOtherClass" , "OtherID" , "OtherName" } ,
270+ new object [ ] { null , "MyOtherClass" , "OtherID" , "OtherName" } ,
221271 } ;
222272 }
223273
0 commit comments