Browse Source

implement Delete TwitterUser by Id + tests

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

+ 15
- 1
src/DataAccessLayers/BirdsiteLive.DAL.Postgres/DataAccessLayers/TwitterUserPostgresDal.cs 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 });
}
}
}
}

+ 1
- 0
src/DataAccessLayers/BirdsiteLive.DAL/Contracts/ITwitterUserDal.cs 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();
}
}

+ 26
- 1
src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/TwitterUserPostgresDalTests.cs 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()
{


Loading…
Cancel
Save