添加单元 测试
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
using DMS.Core.Models;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace DMS.Config
|
||||
namespace DMS.Infrastructure.Configurations
|
||||
{
|
||||
public class DatabaseSettings
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using DMS.Config;
|
||||
using DMS.Infrastructure.Configurations;
|
||||
using SqlSugar;
|
||||
|
||||
namespace DMS.Infrastructure.Data;
|
||||
|
||||
@@ -56,6 +56,7 @@ public class DbDevice
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = true)]
|
||||
public string CpuType { get; set; }
|
||||
/// <summary>
|
||||
/// 设备槽号 (针对PLC等设备)。
|
||||
@@ -73,4 +74,11 @@ public class DbDevice
|
||||
/// 设备是否激活/启用。
|
||||
/// </summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 此设备包含的变量表集合。
|
||||
/// </summary>
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public List<DbVariableTable> VariableTables { get; set; } = new();
|
||||
}
|
||||
@@ -17,15 +17,30 @@ public class MappingProfile : Profile
|
||||
|
||||
// --- 设备映射 (包含List的父对象) ---
|
||||
// AutoMapper 会自动使用上面的规则来处理 VariableTables 属性
|
||||
CreateMap<DbDevice, Device>().ReverseMap();
|
||||
CreateMap<DbDevice, Device>()
|
||||
.ReverseMap();
|
||||
|
||||
// --- 变量表映射 (List中的元素) ---
|
||||
CreateMap<DbVariableTable, VariableTable>().ReverseMap();
|
||||
CreateMap<DbVariableTable, VariableTable>()
|
||||
.ForMember(dest => dest.Variables, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.Device, opt => opt.Ignore())
|
||||
.ReverseMap();
|
||||
|
||||
CreateMap<DbVariable, Variable>().ReverseMap();
|
||||
CreateMap<DbVariable, Variable>()
|
||||
.ForMember(dest => dest.Description, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.VariableTable, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.MqttAliases, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.DataValue, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.DisplayValue, opt => opt.Ignore())
|
||||
.ReverseMap();
|
||||
// --- MQTT 和 变量数据 映射 ---
|
||||
CreateMap<DbMqttServer, MqttServer>().ReverseMap();
|
||||
CreateMap<DbVariableMqttAlias, VariableMqttAlias>().ReverseMap();
|
||||
CreateMap<DbMqttServer, MqttServer>()
|
||||
.ForMember(dest => dest.VariableAliases, opt => opt.Ignore())
|
||||
.ReverseMap();
|
||||
CreateMap<DbVariableMqttAlias, VariableMqttAlias>()
|
||||
.ForMember(dest => dest.Variable, opt => opt.Ignore())
|
||||
.ForMember(dest => dest.MqttServer, opt => opt.Ignore())
|
||||
.ReverseMap();
|
||||
|
||||
CreateMap<DbMenu, MenuBean>().ReverseMap();
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using DMS.Config;
|
||||
using DMS.Core.Interfaces;
|
||||
using DMS.Core.Models;
|
||||
using DMS.Infrastructure.Configurations;
|
||||
using DMS.Infrastructure.Data;
|
||||
using DMS.Infrastructure.Entities;
|
||||
using SqlSugar;
|
||||
@@ -22,7 +22,6 @@ public class DatabaseService : IDatabaseService
|
||||
|
||||
public void InitializeTables()
|
||||
{
|
||||
|
||||
_db.DbMaintenance.CreateDatabase();
|
||||
_db.CodeFirst.InitTables<DbNlog>();
|
||||
_db.CodeFirst.InitTables<DbDevice>();
|
||||
@@ -52,8 +51,17 @@ public class DatabaseService : IDatabaseService
|
||||
nameof(DbMqttServer.ServerName)
|
||||
},true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool IsAnyTable(string tableName)
|
||||
{
|
||||
return _db.DbMaintenance.IsAnyTable(tableName, false);
|
||||
}
|
||||
|
||||
public bool IsAnyIndex(string indexName)
|
||||
{
|
||||
return _db.DbMaintenance.IsAnyIndex(indexName);
|
||||
}
|
||||
|
||||
public void InitializeMenus()
|
||||
{
|
||||
var settings = AppSettings.Load();
|
||||
|
||||
Reference in New Issue
Block a user