临时提交
This commit is contained in:
@@ -28,16 +28,16 @@ namespace DMS.Infrastructure.UnitTests
|
||||
return dbDevice;
|
||||
}
|
||||
|
||||
// public static DbVariableTable FakeDbVariableTable()
|
||||
// {
|
||||
// var dbVarTable = new Faker<DbVariableTable>()
|
||||
// .RuleFor(d => d.Name, f => f.Commerce.ProductName())
|
||||
// .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
|
||||
// .Generate();
|
||||
// dbVarTable.ProtocolType = Core.Enums.ProtocolType.S7;
|
||||
// dbVarTable.IsActive=true;
|
||||
// return dbVarTable;
|
||||
// }
|
||||
public static DbVariableTable FakeDbVariableTable()
|
||||
{
|
||||
var dbVarTable = new Faker<DbVariableTable>()
|
||||
.RuleFor(d => d.Name, f => f.Commerce.ProductName())
|
||||
.RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
|
||||
.Generate();
|
||||
dbVarTable.Protocol = ProtocolType.S7;
|
||||
dbVarTable.IsActive=true;
|
||||
return dbVarTable;
|
||||
}
|
||||
|
||||
// public static DbVariable FakeDbVariable()
|
||||
// {
|
||||
|
||||
@@ -55,4 +55,19 @@ public class DeviceServiceTest
|
||||
var device= await _deviceService.TakeAsync(2);
|
||||
Assert.Equal(2,device.Count);
|
||||
}
|
||||
[Fact]
|
||||
public async Task UpdateAsync_Test()
|
||||
{
|
||||
var devices= await _deviceService.TakeAsync(1);
|
||||
devices[0].IpAddress = "127.0.0.1";
|
||||
var res= await _deviceService.UpdateAsync(devices[0]);
|
||||
Assert.Equal(1,res);
|
||||
}
|
||||
[Fact]
|
||||
public async Task DeleteAsync_Test()
|
||||
{
|
||||
var devices= await _deviceService.TakeAsync(1);
|
||||
var res= await _deviceService.DeleteAsync(devices[0]);
|
||||
Assert.Equal(1,res);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using AutoMapper;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Configurations;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Profiles;
|
||||
using DMS.Infrastructure.Repositories;
|
||||
using DMS.Infrastructure.Services;
|
||||
|
||||
namespace DMS.Infrastructure.UnitTests.Services;
|
||||
|
||||
public class VariableTableServieTest
|
||||
{
|
||||
private readonly VariableTableRepository _variableTableRepository;
|
||||
private readonly VariableTableService _variableTableService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public VariableTableServieTest()
|
||||
{
|
||||
// 1. 创建 MapperConfiguration
|
||||
var mappingConfig = new MapperConfiguration(mc =>
|
||||
|
||||
{
|
||||
// 添加你的所有 Profile
|
||||
mc.AddProfile(new MappingProfile());
|
||||
// 如果有其他 Profile,也可以在这里添加
|
||||
// mc.AddProfile(new AnotherProfile());
|
||||
});
|
||||
|
||||
// 2. 验证映射配置是否有效 (可选,但在开发环境中推荐)
|
||||
mappingConfig.AssertConfigurationIsValid();
|
||||
// 3. 创建 IMapper 实例
|
||||
_mapper = mappingConfig.CreateMapper();
|
||||
|
||||
|
||||
AppSettings appSettings = new AppSettings();
|
||||
appSettings.Database.Database = "dms_test";
|
||||
SqlSugarDbContext dbContext = new SqlSugarDbContext(appSettings);
|
||||
_variableTableRepository= new VariableTableRepository(_mapper,dbContext);
|
||||
_variableTableService = new VariableTableService(_variableTableRepository);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AddAsync_Test()
|
||||
{
|
||||
// var dbDevice = FakerHelper
|
||||
// var addDevice= await _variableTableService.AddAsync(_mapper.Map<Device>(dbDevice));
|
||||
// Assert.NotEqual(0, addDevice.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TakeAsync_Test()
|
||||
{
|
||||
var device= await _variableTableService.TakeAsync(2);
|
||||
Assert.Equal(2,device.Count);
|
||||
}
|
||||
[Fact]
|
||||
public async Task UpdateAsync_Test()
|
||||
{
|
||||
var devices= await _variableTableService.TakeAsync(1);
|
||||
// devices[0].IpAddress = "127.0.0.1";
|
||||
var res= await _variableTableService.UpdateAsync(devices[0]);
|
||||
Assert.Equal(1,res);
|
||||
}
|
||||
[Fact]
|
||||
public async Task DeleteAsync_Test()
|
||||
{
|
||||
var devices= await _variableTableService.TakeAsync(1);
|
||||
var res= await _variableTableService.DeleteAsync(devices[0]);
|
||||
Assert.Equal(1,res);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,51 @@
|
||||
using SqlSugar;
|
||||
using DMS.Core.Enums;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace DMS.Infrastructure.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 变量表
|
||||
/// </summary>
|
||||
public class DbVariableTable
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键ID
|
||||
/// </summary>
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 变量表名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 描述
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// 是否激活
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
/// <summary>
|
||||
/// 设备ID
|
||||
/// </summary>
|
||||
public int DeviceId { get; set; }
|
||||
public int Protocol { get; set; } // 对应 ProtocolType 枚举
|
||||
/// <summary>
|
||||
/// 关联的设备
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public DbDevice Device { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 协议类型
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnDataType="varchar(20)",SqlParameterDbType=typeof(EnumToStringConvert))]
|
||||
public ProtocolType Protocol { get; set; } // 对应 ProtocolType 枚举
|
||||
|
||||
/// <summary>
|
||||
/// 此设备包含的变量表集合。
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<DbVariable> Variables { get; set; } = new();
|
||||
}
|
||||
Reference in New Issue
Block a user