using System.Threading.Tasks;
using Util.Tests.Fakes;
using Util.Tests.Infrastructure;
using Util.Tests.Repositories;
using Util.Tests.UnitOfWorks;
using Xunit;
namespace Util.Data.EntityFrameworkCore.Tests {
///
/// 操作日志仓储测试
/// 说明:
/// 测试自增长long类型标识
///
public class OperationLogRepositoryTest : TestBase {
///
/// 仓储
///
private readonly IOperationLogRepository _repository;
///
/// 测试初始化
///
public OperationLogRepositoryTest( IOperationLogRepository operationLogRepository, ITestUnitOfWork unitOfWork ) : base( unitOfWork ) {
_repository = operationLogRepository;
}
///
/// 测试添加实体
///
[Fact]
public async Task TestAdd() {
//添加实体
var entity = OperationLogFakeService.GetOperationLog();
await _repository.AddAsync( entity );
await UnitOfWork.CommitAsync();
//验证
Assert.True( entity.Id > 0 );
Assert.True( _repository.Exists( t => t.Id == entity.Id ) );
}
///
/// 测试通过标识移除实体 - 物理删除
///
[Fact]
public async Task TestRemove_Id() {
//添加实体
var entity = OperationLogFakeService.GetOperationLog();
await _repository.AddAsync( entity );
await UnitOfWork.CommitAsync();
UnitOfWork.ClearCache();
//移除实体
await _repository.RemoveAsync( entity.Id );
await UnitOfWork.CommitAsync();
UnitOfWork.ClearCache();
//验证
var result = await _repository.FindByIdAsync( entity.Id );
Assert.Null( result );
}
}
}