@@ -102,6 +102,23 @@ public class City
102
102
public int Population { get ; set ; }
103
103
}
104
104
105
+ public interface INameColumn
106
+ {
107
+ string Name { get ; set ; }
108
+ }
109
+
110
+ [ Table ( "City" ) ]
111
+ public class CityWithIName : City , INameColumn
112
+ {
113
+
114
+ }
115
+
116
+ [ Table ( "Users" ) ]
117
+ public class UserWithIName : User , INameColumn
118
+ {
119
+
120
+ }
121
+
105
122
public class GUIDTest
106
123
{
107
124
[ Key ]
@@ -198,7 +215,7 @@ private IDbConnection GetOpenConnection()
198
215
}
199
216
else
200
217
{
201
- connection = new SqlConnection ( @"Data Source = .\sqlexpress ;Initial Catalog=DapperSimpleCrudTestDb;Integrated Security=True;MultipleActiveResultSets=true;" ) ;
218
+ connection = new SqlConnection ( $ @ "Data Source= { Program . SQLServerName } ;Initial Catalog=DapperSimpleCrudTestDb;Integrated Security=True;MultipleActiveResultSets=true;") ;
202
219
SimpleCRUD . SetDialect ( SimpleCRUD . Dialect . SQLServer ) ;
203
220
}
204
221
@@ -220,7 +237,7 @@ public void TestInsertWithSpecifiedTableName()
220
237
}
221
238
}
222
239
223
- public void TestMassInsert ( )
240
+ public void TestMassInsert ( )
224
241
{
225
242
//With cached strinb builder, this tests runs 2.5X faster (From 400ms to 180ms)
226
243
using ( var connection = GetOpenConnection ( ) )
@@ -804,14 +821,13 @@ public void TestMultipleKeyGetAsync()
804
821
}
805
822
}
806
823
807
- public void TestDeleteByIdAsync ( )
824
+ public async void TestDeleteByIdAsync ( )
808
825
{
809
826
using ( var connection = GetOpenConnection ( ) )
810
827
{
811
828
var id = connection . Insert ( new User { Name = "UserAsyncDelete" , Age = 10 } ) ;
812
- connection . DeleteAsync < User > ( id ) ;
829
+ await connection . DeleteAsync < User > ( id ) ;
813
830
//tiny wait to let the delete happen
814
- System . Threading . Thread . Sleep ( 300 ) ;
815
831
connection . Get < User > ( id ) . IsNull ( ) ;
816
832
}
817
833
}
@@ -1298,6 +1314,128 @@ public void TestGetListNullableWhere()
1298
1314
}
1299
1315
}
1300
1316
1317
+ public void TestInsertUsingInterface ( )
1318
+ {
1319
+ using ( var connection = GetOpenConnection ( ) )
1320
+ using ( var transaction = connection . BeginTransaction ( ) )
1321
+ {
1322
+ INameColumn newUser = new UserWithIName
1323
+ {
1324
+ Age = 40 ,
1325
+ Name = "Jonathan Larouche" ,
1326
+ ScheduledDayOff = DayOfWeek . Sunday ,
1327
+ CreatedDate = new DateTime ( 2000 , 1 , 1 )
1328
+ } ;
1329
+
1330
+ connection . Insert ( newUser , transaction ) ;
1331
+
1332
+ INameColumn newCity = new CityWithIName
1333
+ {
1334
+ Name = "Montreal" ,
1335
+ Population = 5675
1336
+ } ;
1337
+
1338
+ connection . Insert < string , INameColumn > ( newCity , transaction ) ;
1339
+
1340
+ var user = connection . GetList < UserWithIName > ( new { Name = "Jonathan Larouche" } , transaction ) . FirstOrDefault ( ) ;
1341
+ user . Age . IsEqualTo ( 40 ) ;
1342
+ var city = connection . GetList < CityWithIName > ( new { Name = "Montreal" } , transaction ) . FirstOrDefault ( ) ;
1343
+ city . Population . IsEqualTo ( 5675 ) ;
1344
+
1345
+ }
1346
+ }
1347
+
1348
+ public async void TestInsertAsyncUsingInterface ( )
1349
+ {
1350
+ using ( var connection = GetOpenConnection ( ) )
1351
+ using ( var transaction = connection . BeginTransaction ( ) )
1352
+ {
1353
+ INameColumn newUser = new UserWithIName
1354
+ {
1355
+ Age = 40 ,
1356
+ Name = "Jonathan Larouche" ,
1357
+ ScheduledDayOff = DayOfWeek . Sunday ,
1358
+ CreatedDate = new DateTime ( 2000 , 1 , 1 )
1359
+ } ;
1360
+
1361
+ await connection . InsertAsync ( newUser , transaction ) ;
1362
+
1363
+ var user = connection . GetList < UserWithIName > ( new { Name = "Jonathan Larouche" } , transaction ) . FirstOrDefault ( ) ;
1364
+ user . Age . IsEqualTo ( 40 ) ;
1365
+
1366
+ }
1367
+ }
1368
+
1369
+ public void TestUpdateUsingInterface ( )
1370
+ {
1371
+ using ( var connection = GetOpenConnection ( ) )
1372
+ using ( var transaction = connection . BeginTransaction ( ) )
1373
+ {
1374
+ INameColumn newUser = new UserWithIName
1375
+ {
1376
+ Age = 40 ,
1377
+ Name = "Jonathan Larouche" ,
1378
+ ScheduledDayOff = DayOfWeek . Sunday ,
1379
+ CreatedDate = new DateTime ( 2000 , 1 , 1 )
1380
+ } ;
1381
+
1382
+ ( ( UserWithIName ) newUser ) . Id = connection . Insert ( newUser , transaction ) . Value ;
1383
+ ( ( UserWithIName ) newUser ) . Age = 41 ;
1384
+ connection . Update ( newUser , transaction ) ;
1385
+
1386
+ INameColumn newCity = new CityWithIName
1387
+ {
1388
+ Name = "Montreal" ,
1389
+ Population = 5675
1390
+ } ;
1391
+
1392
+ connection . Insert < string , INameColumn > ( newCity , transaction ) ;
1393
+ ( ( CityWithIName ) newCity ) . Population = 6000 ;
1394
+ connection . Update ( newCity , transaction ) ;
1395
+
1396
+ var user = connection . GetList < UserWithIName > ( new { Name = "Jonathan Larouche" } , transaction ) . FirstOrDefault ( ) ;
1397
+ user . Age . IsEqualTo ( 41 ) ;
1398
+ var city = connection . GetList < CityWithIName > ( new { Name = "Montreal" } , transaction ) . FirstOrDefault ( ) ;
1399
+ city . Population . IsEqualTo ( 6000 ) ;
1400
+
1401
+ }
1402
+ }
1403
+
1404
+ public async void TestUpdateAsyncUsingInterface ( )
1405
+ {
1406
+ using ( var connection = GetOpenConnection ( ) )
1407
+ using ( var transaction = connection . BeginTransaction ( ) )
1408
+ {
1409
+ INameColumn newUser = new UserWithIName
1410
+ {
1411
+ Age = 40 ,
1412
+ Name = "Jonathan Larouche" ,
1413
+ ScheduledDayOff = DayOfWeek . Sunday ,
1414
+ CreatedDate = new DateTime ( 2000 , 1 , 1 )
1415
+ } ;
1416
+
1417
+ ( ( UserWithIName ) newUser ) . Id = connection . Insert ( newUser , transaction ) . Value ;
1418
+ ( ( UserWithIName ) newUser ) . Age = 41 ;
1419
+ await connection . UpdateAsync ( newUser , transaction ) ;
1420
+
1421
+ INameColumn newCity = new CityWithIName
1422
+ {
1423
+ Name = "Montreal" ,
1424
+ Population = 5675
1425
+ } ;
1426
+
1427
+ connection . Insert < string , INameColumn > ( newCity , transaction ) ;
1428
+ ( ( CityWithIName ) newCity ) . Population = 6000 ;
1429
+ await connection . UpdateAsync ( newCity , transaction ) ;
1430
+
1431
+ var user = connection . GetList < UserWithIName > ( new { Name = "Jonathan Larouche" } , transaction ) . FirstOrDefault ( ) ;
1432
+ user . Age . IsEqualTo ( 41 ) ;
1433
+ var city = connection . GetList < CityWithIName > ( new { Name = "Montreal" } , transaction ) . FirstOrDefault ( ) ;
1434
+ city . Population . IsEqualTo ( 6000 ) ;
1435
+
1436
+ }
1437
+ }
1438
+
1301
1439
//ignore attribute tests
1302
1440
//i cheated here and stuffed all of these in one test
1303
1441
//didn't implement in postgres or mysql tests yet
0 commit comments