namespace WebApi.Test.Repository;

public class MessageRecordRepositoryTest : RepositoryTestBase
{
    private readonly IMessageRecordRepository _repository;

    public MessageRecordRepositoryTest()
    {
        _repository = new MessageRecordRepository(FreeSql);
    }

    [Fact]
    public async Task GetPagedListAsync_分页_Test()
    {
        for (int i = 0; i < 5; i++)
        {
            await _repository.AddAsync(new MessageRecord { Content = $"Msg{i}" });
        }

        var result = await _repository.GetPagedListAsync(1, 2);
        result.Total.Should().Be(5);
        result.List.Should().HaveCount(2);
    }

    [Fact]
    public async Task MarkAllAsReadAsync_全部标记已读_Test()
    {
        await _repository.AddAsync(new MessageRecord { IsRead = false });
        await _repository.AddAsync(new MessageRecord { IsRead = false });
        await _repository.AddAsync(new MessageRecord { IsRead = true });

        await _repository.MarkAllAsReadAsync();

        var all = await _repository.GetAllAsync();
        all.All(x => x.IsRead).Should().BeTrue();
    }
}
