Ended TwitterUserPostgresDal + Tests
This commit is contained in:
parent
b23a710533
commit
b4b1756445
2 changed files with 42 additions and 8 deletions
|
@ -45,9 +45,17 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
|||
}
|
||||
}
|
||||
|
||||
public Task<SyncTwitterUser[]> GetAllTwitterUsersAsync()
|
||||
public async Task<SyncTwitterUser[]> GetAllTwitterUsersAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
var query = $"SELECT * FROM {_settings.TwitterUserTableName}";
|
||||
|
||||
using (var dbConnection = Connection)
|
||||
{
|
||||
dbConnection.Open();
|
||||
|
||||
var result = await dbConnection.QueryAsync<SyncTwitterUser>(query);
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateTwitterUserAsync(int id, long lastTweetPostedId, long lastTweetSynchronizedForAllFollowersId)
|
||||
|
@ -55,23 +63,29 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
|||
if(id == default) throw new ArgumentException("id");
|
||||
if(lastTweetPostedId == default) throw new ArgumentException("lastTweetPostedId");
|
||||
if(lastTweetSynchronizedForAllFollowersId == default) throw new ArgumentException("lastTweetSynchronizedForAllFollowersId");
|
||||
|
||||
var query = $"UPDATE {_settings.TwitterUserTableName} SET lastTweetPostedId = {lastTweetPostedId}, lastTweetSynchronizedForAllFollowersId = {lastTweetSynchronizedForAllFollowersId} WHERE id = {id}";
|
||||
|
||||
var query = $"UPDATE {_settings.TwitterUserTableName} SET lastTweetPostedId = @lastTweetPostedId, lastTweetSynchronizedForAllFollowersId = @lastTweetSynchronizedForAllFollowersId WHERE id = @id";
|
||||
|
||||
using (var dbConnection = Connection)
|
||||
using (var cmd = new NpgsqlCommand(query, dbConnection))
|
||||
{
|
||||
dbConnection.Open();
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
|
||||
await dbConnection.QueryAsync(query, new { id, lastTweetPostedId, lastTweetSynchronizedForAllFollowersId });
|
||||
}
|
||||
}
|
||||
|
||||
public Task DeleteTwitterUserAsync(string acct)
|
||||
public async Task DeleteTwitterUserAsync(string acct)
|
||||
{
|
||||
if (acct == default) throw new ArgumentException("acct");
|
||||
|
||||
var query = $"DELETE FROM {_settings.TwitterUserTableName} WHERE acct = @acct";
|
||||
|
||||
using (var dbConnection = Connection)
|
||||
{
|
||||
dbConnection.Open();
|
||||
|
||||
throw new System.NotImplementedException();
|
||||
await dbConnection.QueryAsync(query, new { acct });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -95,5 +95,25 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
|||
result = await dal.GetTwitterUserAsync(acct);
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllTwitterUsers()
|
||||
{
|
||||
var dal = new TwitterUserPostgresDal(_settings);
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var acct = $"myid{i}";
|
||||
var lastTweetId = 1548L;
|
||||
|
||||
await dal.CreateTwitterUserAsync(acct, lastTweetId);
|
||||
}
|
||||
|
||||
var result = await dal.GetAllTwitterUsersAsync();
|
||||
Assert.AreEqual(1000, result.Length);
|
||||
Assert.IsFalse(result[0].Id == default);
|
||||
Assert.IsFalse(result[0].Acct == default);
|
||||
Assert.IsFalse(result[0].LastTweetPostedId == default);
|
||||
Assert.IsFalse(result[0].LastTweetSynchronizedForAllFollowersId == default);
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue