diff --git a/DMS.Infrastructure.UnitTests/Repository_Test/DeviceRepositoryTests.cs b/DMS.Infrastructure.UnitTests/Repository_Test/DeviceRepositoryTests.cs index 61c4d33..3fd923b 100644 --- a/DMS.Infrastructure.UnitTests/Repository_Test/DeviceRepositoryTests.cs +++ b/DMS.Infrastructure.UnitTests/Repository_Test/DeviceRepositoryTests.cs @@ -22,26 +22,64 @@ namespace DMS.Infrastructure.UnitTests.Repository_Test } [Fact] - public async Task GetAllAsync_ShouldReturnListOfDbDevices() + public async Task GetAllAsync_Test() { - // Act var result = await _deviceRepository.GetAllAsync(); // Assert Assert.NotNull(result); } + + [Fact] + public async Task UpdateByIdAsync_Test() + { + var device = await _deviceRepository.GetByIdAsync(33); + device.Name = "张飞"; + // 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] public async Task AddAsync_Test() { - for (var i = 0; i < 10; i++) + try { - var dbDevice = FakerHelper.FakeDbDevice(); - //await _sqlSugarDbContext.GetInstance().Insertable(dbDevice).ExecuteCommandAsync(); + //await _sqlSugarDbContext.BeginTranAsync(); + for (var i = 0; i < 10; i++) + { + var dbDevice = FakerHelper.FakeDbDevice(); + //await _sqlSugarDbContext.GetInstance().Insertable(dbDevice).ExecuteCommandAsync(); - // Act - var result = await _deviceRepository.AddAsync(dbDevice); + // Act + var result = await _deviceRepository.AddAsync(dbDevice); + } + throw new Exception("模拟错误。。。"); + //await _sqlSugarDbContext.CommitTranAsync(); } + catch (Exception e) + { + //await _sqlSugarDbContext.RollbackTranAsync(); + Console.WriteLine($"添加设备时发生了错误:{e}"); + } + // Assert //Assert.NotNull(result); diff --git a/DMS.Infrastructure/Repositories/DeviceRepository.cs b/DMS.Infrastructure/Repositories/DeviceRepository.cs index c4309cf..f219317 100644 --- a/DMS.Infrastructure/Repositories/DeviceRepository.cs +++ b/DMS.Infrastructure/Repositories/DeviceRepository.cs @@ -19,23 +19,5 @@ public class DeviceRepository : BaseRepository } - - public override async Task> GetAllAsync() - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var dlist = await Db.Queryable() - .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; - } - - - } \ No newline at end of file diff --git a/DMS.Infrastructure/Repositories/MenuRepository.cs b/DMS.Infrastructure/Repositories/MenuRepository.cs index 5b67ab3..b09e6d6 100644 --- a/DMS.Infrastructure/Repositories/MenuRepository.cs +++ b/DMS.Infrastructure/Repositories/MenuRepository.cs @@ -37,49 +37,11 @@ public class MenuRepository : BaseRepository } - public override async Task AddAsync(DbMenu menu) - { - return await base.AddAsync(menu); - } - - - /// - /// 娣诲姞鑿滃崟锛屾敮鎸佷簨鍔 - /// - /// - /// - /// - - - - - - - /// - /// 娣诲姞璁惧鑿滃崟 - /// - /// - /// - /// - /// - - - /// - /// 缂栬緫鑿滃崟 - /// - /// - /// - public override async Task UpdateAsync(DbMenu menu) - { - return await base.UpdateAsync(menu); - } - /// /// 缂栬緫鑿滃崟,鏀寔浜嬪姟 /// /// /// - public async Task GetMenuByDataIdAsync(int dataId, MenuType menuType) { diff --git a/DMS.Infrastructure/Repositories/VarDataRepository.cs b/DMS.Infrastructure/Repositories/VarDataRepository.cs index b5e4e34..f53e1e7 100644 --- a/DMS.Infrastructure/Repositories/VarDataRepository.cs +++ b/DMS.Infrastructure/Repositories/VarDataRepository.cs @@ -44,94 +44,10 @@ public class VarDataRepository : BaseRepository return result; } - //public override async Task 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 AddAsync(IEnumerable variableDatas) - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - Stopwatch stopwatch2 = new Stopwatch(); - stopwatch2.Start(); - var dbList = variableDatas.Select(vb => _mapper.Map(vb)) - .ToList(); - stopwatch2.Stop(); - //NlogHelper.Info($"澶嶅埗 Variable'{variableDatas.Count()}'涓紝 鑰楁椂锛歿stopwatch2.ElapsedMilliseconds}ms"); - - var res = await Db.Insertable(dbList) - .ExecuteCommandAsync(); - - stopwatch.Stop(); - //NlogHelper.Info($"鏂板VariableData '{variableDatas.Count()}'涓紝 鑰楁椂锛歿stopwatch.ElapsedMilliseconds}ms"); - return res; - } -*/ + - public override async Task 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 UpdateAsync(List variableDatas) - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - - var dbVarDatas = variableDatas.Select(vd => _mapper.Map(vd)); - var result = await Db.Updateable(dbVarDatas.ToList()) - .ExecuteCommandAsync(); - - stopwatch.Stop(); - //NlogHelper.Info($"鏇存柊VariableData {variableDatas.Count()}涓 鑰楁椂锛歿stopwatch.ElapsedMilliseconds}ms"); - return result; - } -*/ - - public override async Task DeleteAsync(DbVariable entity) - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - var result = await Db.Deleteable() - .Where(d => d.Id == entity.Id) - .ExecuteCommandAsync(); - stopwatch.Stop(); - //NlogHelper.Info($"鍒犻櫎VariableData: '{entity.Name}' 鑰楁椂锛歿stopwatch.ElapsedMilliseconds}ms"); - return result; - } - - /* - public async Task DeleteAsync(IEnumerable variableDatas) - { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - - var dbList = variableDatas.Select(vd => _mapper.Map(vd)) - .ToList(); - var result = await Db.Deleteable(dbList) - .ExecuteCommandAsync(); - - stopwatch.Stop(); - //NlogHelper.Info($"鍒犻櫎VariableData: '{variableDatas.Count()}'涓 鑰楁椂锛歿stopwatch.ElapsedMilliseconds}ms"); - return result; - } -*/ // public VarDataRepository(IMapper mapper) // {