This repository has been archived on 2023-05-27. You can view files and clone it, but cannot push or open issues or pull requests.
BirdsiteLIVE/src/Tests/BirdsiteLive.DAL.Postgres.Tests/DataAccessLayers/CachedTweetsPostgresDalTests.cs
Nicolas Constant b4c01ad326
save last sync
2021-01-22 21:05:01 -05:00

88 lines
2.5 KiB
C#

using System;
using System.Threading.Tasks;
using BirdsiteLive.DAL.Models;
using BirdsiteLive.DAL.Postgres.DataAccessLayers;
using BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers.Base;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
{
[TestClass]
public class CachedTweetsPostgresDalTests : PostgresTestingBase
{
[TestInitialize]
public async Task TestInit()
{
var dal = new DbInitializerPostgresDal(_settings, _tools);
var init = new DatabaseInitializer(dal);
await init.InitAndMigrateDbAsync();
}
[TestCleanup]
public async Task CleanUp()
{
var dal = new DbInitializerPostgresDal(_settings, _tools);
try
{
await dal.DeleteAllAsync();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
[TestMethod]
public async Task CreateAndGet()
{
var id = 152L;
var userId = 15;
var tweet = new CachedTweet
{
UserId = userId,
Id = id,
Text = "text data",
FullText = "full text data",
CreatedAt = DateTime.UtcNow
};
var dal = new CachedTweetsPostgresDal(_settings);
await dal.CreateTweetAsync(id, userId, tweet);
var result = await dal.GetTweetAsync(id);
Assert.IsNotNull(result);
Assert.AreEqual(id, result.Id);
Assert.AreEqual(tweet.Text, result.Text);
Assert.AreEqual(tweet.FullText, result.FullText);
Assert.AreEqual(tweet.CreatedAt, result.CreatedAt);
}
[TestMethod]
public async Task CreateAndDelete()
{
var id = 152L;
var userId = 15;
var tweet = new CachedTweet
{
UserId = userId,
Id = id,
Text = "text data",
FullText = "full text data",
CreatedAt = DateTime.UtcNow
};
var dal = new CachedTweetsPostgresDal(_settings);
await dal.CreateTweetAsync(id, userId, tweet);
var result = await dal.GetTweetAsync(id);
Assert.IsNotNull(result);
await dal.DeleteTweetAsync(id);
result = await dal.GetTweetAsync(id);
Assert.IsNull(result);
}
}
}