Browse Source

Ended TwitterUserPostgresDal + Tests

master
Nicolas Constant 2 years ago
parent
commit
b4b1756445
No known key found for this signature in database GPG Key ID: 1E9F677FB01A5688
2 changed files with 42 additions and 8 deletions
  1. +22
    -8
      src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs
  2. +20
    -0
      src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs

+ 22
- 8
src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs View File

@ -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 });
}
}
}
}

+ 20
- 0
src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs View File

@ -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);
}
}
}

Loading…
Cancel
Save