implement Delete TwitterUser by Id + tests

This commit is contained in:
Nicolas Constant 2021-02-14 01:29:06 -05:00
parent a2597b72a9
commit 537270cceb
No known key found for this signature in database
GPG key ID: 1E9F677FB01A5688
3 changed files with 42 additions and 2 deletions

View file

@ -59,7 +59,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
return result;
}
}
public async Task<int> GetTwitterUsersCountAsync()
{
var query = $"SELECT COUNT(*) FROM {_settings.TwitterUserTableName}";
@ -131,5 +131,19 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
await dbConnection.QueryAsync(query, new { acct });
}
}
public async Task DeleteTwitterUserAsync(int id)
{
if (id == default) throw new ArgumentException("id");
var query = $"DELETE FROM {_settings.TwitterUserTableName} WHERE id = @id";
using (var dbConnection = Connection)
{
dbConnection.Open();
await dbConnection.QueryAsync(query, new { id });
}
}
}
}

View file

@ -13,6 +13,7 @@ namespace BirdsiteLive.DAL.Contracts
Task<SyncTwitterUser[]> GetAllTwitterUsersAsync();
Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId, DateTime lastSync);
Task DeleteTwitterUserAsync(string acct);
Task DeleteTwitterUserAsync(int id);
Task<int> GetTwitterUsersCountAsync();
}
}

View file

@ -128,7 +128,7 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
[TestMethod]
public async Task CreateAndDeleteUser()
{
var acct = "myid";
var acct = "myacct";
var lastTweetId = 1548L;
var dal = new TwitterUserPostgresDal(_settings);
@ -150,6 +150,31 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
await dal.DeleteTwitterUserAsync(string.Empty);
}
[TestMethod]
public async Task CreateAndDeleteUser_byId()
{
var acct = "myacct";
var lastTweetId = 1548L;
var dal = new TwitterUserPostgresDal(_settings);
await dal.CreateTwitterUserAsync(acct, lastTweetId);
var result = await dal.GetTwitterUserAsync(acct);
Assert.IsNotNull(result);
await dal.DeleteTwitterUserAsync(result.Id);
result = await dal.GetTwitterUserAsync(acct);
Assert.IsNull(result);
}
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public async Task DeleteUser_NotAcct_byId()
{
var dal = new TwitterUserPostgresDal(_settings);
await dal.DeleteTwitterUserAsync(default(int));
}
[TestMethod]
public async Task GetAllTwitterUsers_Top()
{