测试了Repositories
This commit is contained in:
@@ -22,18 +22,47 @@ namespace DMS.Infrastructure.UnitTests.Repository_Test
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task GetAllAsync_ShouldReturnListOfDbDevices()
|
public async Task GetAllAsync_Test()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = await _deviceRepository.GetAllAsync();
|
var result = await _deviceRepository.GetAllAsync();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task UpdateByIdAsync_Test()
|
||||||
|
{
|
||||||
|
var device = await _deviceRepository.GetByIdAsync(33);
|
||||||
|
device.Name = "<22>ŷ<EFBFBD>";
|
||||||
|
// Act
|
||||||
|
var result = await _deviceRepository.UpdateAsync(device);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
//Assert.NotNull(result);
|
||||||
|
Assert.Equal(result, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task DeleteAsync_Test()
|
||||||
|
{
|
||||||
|
var device = await _deviceRepository.GetByIdAsync(33);
|
||||||
|
// Act
|
||||||
|
var result = await _deviceRepository.DeleteAsync(device);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
//Assert.NotNull(result);
|
||||||
|
Assert.Equal(result, 1);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AddAsync_Test()
|
public async Task AddAsync_Test()
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//await _sqlSugarDbContext.BeginTranAsync();
|
||||||
for (var i = 0; i < 10; i++)
|
for (var i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
var dbDevice = FakerHelper.FakeDbDevice();
|
var dbDevice = FakerHelper.FakeDbDevice();
|
||||||
@@ -42,6 +71,15 @@ namespace DMS.Infrastructure.UnitTests.Repository_Test
|
|||||||
// Act
|
// Act
|
||||||
var result = await _deviceRepository.AddAsync(dbDevice);
|
var result = await _deviceRepository.AddAsync(dbDevice);
|
||||||
}
|
}
|
||||||
|
throw new Exception("ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3A1A3A1><EFBFBD>");
|
||||||
|
//await _sqlSugarDbContext.CommitTranAsync();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
//await _sqlSugarDbContext.RollbackTranAsync();
|
||||||
|
Console.WriteLine($"<22><><EFBFBD><EFBFBD><EFBFBD>豸ʱ<E8B1B8><CAB1><EFBFBD><EFBFBD><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD>{e}");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
//Assert.NotNull(result);
|
//Assert.NotNull(result);
|
||||||
|
|||||||
@@ -20,22 +20,4 @@ public class DeviceRepository : BaseRepository<DbDevice>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task<List<DbDevice>> GetAllAsync()
|
|
||||||
{
|
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
|
||||||
stopwatch.Start();
|
|
||||||
var dlist = await Db.Queryable<DbDevice>()
|
|
||||||
.Includes(d => d.VariableTables, dv => dv.Device)
|
|
||||||
.Includes(d => d.VariableTables, dvd => dvd.Variables, data => data.VariableTable)
|
|
||||||
.Includes(d => d.VariableTables, vt => vt.Variables, v => v.VariableMqtts)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
stopwatch.Stop();
|
|
||||||
NlogHelper.Info($"加载设备列表总耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
||||||
return dlist;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -37,50 +37,12 @@ public class MenuRepository : BaseRepository<DbMenu>
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task<DbMenu> AddAsync(DbMenu menu)
|
|
||||||
{
|
|
||||||
return await base.AddAsync(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 添加菜单,支持事务
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menu"></param>
|
|
||||||
/// <param name="db"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 添加设备菜单
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="device"></param>
|
|
||||||
/// <param name="db"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
/// <exception cref="InvalidOperationException"></exception>
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 编辑菜单
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="menu"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public override async Task<int> UpdateAsync(DbMenu menu)
|
|
||||||
{
|
|
||||||
return await base.UpdateAsync(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 编辑菜单,支持事务
|
/// 编辑菜单,支持事务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="menu"></param>
|
/// <param name="menu"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
||||||
|
|
||||||
public async Task<DbMenu?> GetMenuByDataIdAsync(int dataId, MenuType menuType)
|
public async Task<DbMenu?> GetMenuByDataIdAsync(int dataId, MenuType menuType)
|
||||||
{
|
{
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
Stopwatch stopwatch = new Stopwatch();
|
||||||
|
|||||||
@@ -44,94 +44,10 @@ public class VarDataRepository : BaseRepository<DbVariable>
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
//public override async Task<DbVariable> AddAsync(DbVariable entity)
|
|
||||||
//{
|
|
||||||
// Stopwatch stopwatch = new Stopwatch();
|
|
||||||
// stopwatch.Start();
|
|
||||||
// var dbVarData = await Db.Insertable(entity)
|
|
||||||
// .ExecuteReturnEntityAsync();
|
|
||||||
// stopwatch.Stop();
|
|
||||||
// //NlogHelper.Info($"新增VariableData '{entity.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
||||||
// return dbVarData.Id;
|
|
||||||
//}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public async Task<int> AddAsync(IEnumerable<Variable> variableDatas)
|
|
||||||
{
|
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
|
||||||
stopwatch.Start();
|
|
||||||
Stopwatch stopwatch2 = new Stopwatch();
|
|
||||||
stopwatch2.Start();
|
|
||||||
var dbList = variableDatas.Select(vb => _mapper.Map<DbVariable>(vb))
|
|
||||||
.ToList();
|
|
||||||
stopwatch2.Stop();
|
|
||||||
//NlogHelper.Info($"复制 Variable'{variableDatas.Count()}'个, 耗时:{stopwatch2.ElapsedMilliseconds}ms");
|
|
||||||
|
|
||||||
var res = await Db.Insertable<DbVariable>(dbList)
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
|
|
||||||
stopwatch.Stop();
|
|
||||||
//NlogHelper.Info($"新增VariableData '{variableDatas.Count()}'个, 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
public override async Task<int> UpdateAsync(DbVariable entity)
|
|
||||||
{
|
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
|
||||||
stopwatch.Start();
|
|
||||||
var result = await Db.Updateable(entity)
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
stopwatch.Stop();
|
|
||||||
//NlogHelper.Info($"更新VariableData '{entity.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public async Task<int> UpdateAsync(List<Variable> variableDatas)
|
|
||||||
{
|
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
|
||||||
stopwatch.Start();
|
|
||||||
|
|
||||||
var dbVarDatas = variableDatas.Select(vd => _mapper.Map<DbVariable>(vd));
|
|
||||||
var result = await Db.Updateable<DbVariable>(dbVarDatas.ToList())
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
|
|
||||||
stopwatch.Stop();
|
|
||||||
//NlogHelper.Info($"更新VariableData {variableDatas.Count()}个 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public override async Task<int> DeleteAsync(DbVariable entity)
|
|
||||||
{
|
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
|
||||||
stopwatch.Start();
|
|
||||||
var result = await Db.Deleteable<DbVariable>()
|
|
||||||
.Where(d => d.Id == entity.Id)
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
stopwatch.Stop();
|
|
||||||
//NlogHelper.Info($"删除VariableData: '{entity.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
public async Task<int> DeleteAsync(IEnumerable<Variable> variableDatas)
|
|
||||||
{
|
|
||||||
Stopwatch stopwatch = new Stopwatch();
|
|
||||||
stopwatch.Start();
|
|
||||||
|
|
||||||
var dbList = variableDatas.Select(vd => _mapper.Map<DbVariable>(vd))
|
|
||||||
.ToList();
|
|
||||||
var result = await Db.Deleteable<DbVariable>(dbList)
|
|
||||||
.ExecuteCommandAsync();
|
|
||||||
|
|
||||||
stopwatch.Stop();
|
|
||||||
//NlogHelper.Info($"删除VariableData: '{variableDatas.Count()}'个 耗时:{stopwatch.ElapsedMilliseconds}ms");
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// public VarDataRepository(IMapper mapper)
|
// public VarDataRepository(IMapper mapper)
|
||||||
// {
|
// {
|
||||||
|
|||||||
Reference in New Issue
Block a user