

using Yuna.Website.Server.Infrastructure;
using Yuna.Website.Server.Model;
using Yuna.Website.Server.Storage;
using Yuna.Website.Server.Storage.Repositories.User;

namespace Yuna.Tests.Repositories
{
    public class UserRepositoriesTests
    {
        [Fact]
        public async Task Create_Creates_User()
        {
            //arrange
            Settings.Init();
            var _context = new DapperContext(true);
            var repo = new UserRepository(_context);
            //act
            User user = new User("test", "123");
            var result = await repo.Create(user);

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.UserName, user.UserName);
            Assert.Equal(result.HashedPassword, user.HashedPassword);
            Assert.Equal(result.IsAdmin, user.IsAdmin);
        }

        [Fact]
        public async Task GetById_Gets_UserWithId()
        {
            //arrange
            Settings.Init();
            var _context = new DapperContext(true);
            var repo = new UserRepository(_context);
            //act
            var result = await repo.GetById(1);

            //assert
            Assert.NotNull(result);
            Assert.Equal(1, result.Id);
        }

        [Fact]
        public async Task GetByUserName_Gets_UserWithName()
        {
            //arrange
            Settings.Init();
            var _context = new DapperContext(true);
            var repo = new UserRepository(_context);
            //act
            var result = await repo.GetByUsername("test");

            //assert
            Assert.NotNull(result);
            Assert.Equal("test", result.UserName);
        }

        [Fact]
        public async Task GetList_Gets_List()
        {
            //arrange
            Settings.Init();
            var _context = new DapperContext(true);
            var repo = new UserRepository(_context);
            //act
            var result = await repo.GetList();

            //assert
            Assert.NotNull(result);
            Assert.NotEmpty(result);
        }
    }
}
