Skip to content

Commit a928c36

Browse files
Add Tests for UpdateAsyncWithInterface
Fix TestDeleteAsync to await, Sleep was not alway sufficient
1 parent 601a557 commit a928c36

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

Dapper.SimpleCRUD/SimpleCRUDAsync.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,9 @@ public static async Task<int> UpdateAsync<TEntity>(this IDbConnection connection
331331
if (typeof(TEntity).IsInterface) //FallBack to BaseType Generic Method : https://stackoverflow.com/questions/4101784/calling-a-generic-method-with-a-dynamic-type
332332
{
333333
return await(Task<int>)typeof(SimpleCRUD)
334-
.GetMethods().Where(methodInfo => methodInfo.Name == nameof(UpdateAsync) && methodInfo.GetGenericArguments().Count() == 2).Single()
334+
.GetMethods().Where(methodInfo => methodInfo.Name == nameof(UpdateAsync) && methodInfo.GetGenericArguments().Count() == 1).Single()
335335
.MakeGenericMethod(new Type[] { entityToUpdate.GetType() })
336-
.Invoke(null, new object[] { connection, entityToUpdate, transaction, commandTimeout });
336+
.Invoke(null, new object[] { connection, entityToUpdate, transaction, commandTimeout, token });
337337
}
338338
var idProps = GetIdProperties(entityToUpdate).ToList();
339339

Dapper.SimpleCRUDTests/Tests.cs

+37-3
Original file line numberDiff line numberDiff line change
@@ -815,14 +815,13 @@ public void TestMultipleKeyGetAsync()
815815
}
816816
}
817817

818-
public void TestDeleteByIdAsync()
818+
public async void TestDeleteByIdAsync()
819819
{
820820
using (var connection = GetOpenConnection())
821821
{
822822
var id = connection.Insert(new User { Name = "UserAsyncDelete", Age = 10 });
823-
connection.DeleteAsync<User>(id);
823+
await connection.DeleteAsync<User>(id);
824824
//tiny wait to let the delete happen
825-
System.Threading.Thread.Sleep(300);
826825
connection.Get<User>(id).IsNull();
827826
}
828827
}
@@ -1396,6 +1395,41 @@ public void TestUpdateUsingInterface()
13961395
}
13971396
}
13981397

1398+
public async void TestUpdateAsyncUsingInterface()
1399+
{
1400+
using (var connection = GetOpenConnection())
1401+
using (var transaction = connection.BeginTransaction())
1402+
{
1403+
INameColumn newUser = new UserWithIName
1404+
{
1405+
Age = 40,
1406+
Name = "Jonathan Larouche",
1407+
ScheduledDayOff = DayOfWeek.Sunday,
1408+
CreatedDate = new DateTime(2000, 1, 1)
1409+
};
1410+
1411+
((UserWithIName)newUser).Id = connection.Insert(newUser, transaction).Value;
1412+
((UserWithIName)newUser).Age = 41;
1413+
await connection.UpdateAsync(newUser, transaction);
1414+
1415+
INameColumn newCity = new CityWithIName
1416+
{
1417+
Name = "Montreal",
1418+
Population = 5675
1419+
};
1420+
1421+
connection.Insert<string, INameColumn>(newCity, transaction);
1422+
((CityWithIName)newCity).Population = 6000;
1423+
await connection.UpdateAsync(newCity, transaction);
1424+
1425+
var user = connection.GetList<UserWithIName>(new { Name = "Jonathan Larouche" }, transaction).FirstOrDefault();
1426+
user.Age.IsEqualTo(41);
1427+
var city = connection.GetList<CityWithIName>(new { Name = "Montreal" }, transaction).FirstOrDefault();
1428+
city.Population.IsEqualTo(6000);
1429+
1430+
}
1431+
}
1432+
13991433
//ignore attribute tests
14001434
//i cheated here and stuffed all of these in one test
14011435
//didn't implement in postgres or mysql tests yet

0 commit comments

Comments
 (0)