完成设备删除单元测试

This commit is contained in:
2025-07-24 18:09:46 +08:00
parent ac38128e4d
commit 7b9c91eee1
18 changed files with 119 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
using System.Diagnostics;
using AutoMapper;
using DMS.Core.Enums;
using DMS.Core.Helper;
using DMS.Core.Interfaces.Repositories;
using DMS.Core.Models;
@@ -54,7 +55,7 @@ public class MenuRepository : BaseRepository<DbMenu>, IMenuRepository
public async Task<int> DeleteAsync(MenuBean entity) => await base.DeleteAsync(_mapper.Map<DbMenu>(entity));
public async Task<int> DeleteAsync(int id)
public async Task<int> DeleteByIdAsync(int id)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
@@ -64,11 +65,45 @@ public class MenuRepository : BaseRepository<DbMenu>, IMenuRepository
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
public async Task<int> DeleteMenuTreeByIdAsync(int id)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
int delConut = 0;
var childList = await Db.Queryable<DbMenu>()
.ToChildListAsync(c => c.ParentId, id);
delConut = await Db.Deleteable<DbMenu>(childList)
.ExecuteCommandAsync();
delConut += await Db.Deleteable<DbMenu>()
.Where(m => m.Id == id)
.ExecuteCommandAsync();
stopwatch.Stop();
NlogHelper.Info($"Delete {typeof(DbMenu)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
return delConut;
}
public async Task<int> DeleteMenuTreeByTargetIdAsync(MenuType menuType, int targetId)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var menu = await Db.Queryable<DbMenu>().FirstAsync(m => m.MenuType == menuType && m.TargetId == targetId);
if (menu == null) return 0;
var childList = await Db.Queryable<DbMenu>()
.ToChildListAsync(c => c.ParentId, menu.Id);
var delConut = await Db.Deleteable<DbMenu>(childList)
.ExecuteCommandAsync();
delConut += await Db.Deleteable<DbMenu>()
.Where(m => m.Id == menu.Id)
.ExecuteCommandAsync();
stopwatch.Stop();
NlogHelper.Info($"Delete {typeof(DbMenu)},TargetId={targetId},耗时:{stopwatch.ElapsedMilliseconds}ms");
return delConut;
}
public new async Task<List<MenuBean>> TakeAsync(int number)
{
var dbList = await base.TakeAsync(number);
return _mapper.Map<List<MenuBean>>(dbList);
}
}
}