implement Delete TwitterUser by Id + tests
This commit is contained in:
parent
a2597b72a9
commit
537270cceb
3 changed files with 42 additions and 2 deletions
|
@ -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 });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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()
|
||||
{
|
||||
|
|
Reference in a new issue