diff --git a/DMS.Infrastructure.UnitTests/DMS.Infrastructure.UnitTests.csproj b/DMS.Infrastructure.UnitTests/DMS.Infrastructure.UnitTests.csproj
deleted file mode 100644
index f5a0273..0000000
--- a/DMS.Infrastructure.UnitTests/DMS.Infrastructure.UnitTests.csproj
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
- net8.0
- enable
- enable
-
- false
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/DMS.Infrastructure.UnitTests/ExampleTest.cs b/DMS.Infrastructure.UnitTests/ExampleTest.cs
deleted file mode 100644
index 7422db1..0000000
--- a/DMS.Infrastructure.UnitTests/ExampleTest.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Xunit;
-
-namespace DMS.Infrastructure.UnitTests
-{
- public class VariableTableRepositoryTests
- {
- public VariableTableRepositoryTests()
- {
-
- }
-
- [Fact]
- public void AddAsync()
- {
- Assert.True(true);
- }
- }
-}
\ No newline at end of file
diff --git a/DMS.Infrastructure.UnitTests/FakerHelper.cs b/DMS.Infrastructure.UnitTests/FakerHelper.cs
deleted file mode 100644
index b7665f7..0000000
--- a/DMS.Infrastructure.UnitTests/FakerHelper.cs
+++ /dev/null
@@ -1,171 +0,0 @@
-using Bogus;
-using DMS.Infrastructure.Entities;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using DMS.Application.DTOs;
-using DMS.Core.Enums;
-using DMS.Core.Models;
-
-namespace DMS.Infrastructure.UnitTests
-{
- public static class FakerHelper
- {
- public static Device FakeDevice()
- {
- var dbDevice = new Faker()
- .RuleFor(d => d.Name, f => f.Commerce.ProductName())
- .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
- .RuleFor(d => d.IpAddress, f => f.Internet.Ip())
- .RuleFor(d => d.OpcUaServerUrl, f => f.Internet.Url())
- .Generate();
- dbDevice.Port = 102;
- dbDevice.Protocol = ProtocolType.S7;
- dbDevice.Slot = 1;
- dbDevice.Rack = 0;
- dbDevice.CpuType = CpuType.S71200;
- dbDevice.DeviceType = Core.Enums.DeviceType.SiemensPLC;
-
- return dbDevice;
- }
-
- public static VariableTable FakeVariableTable()
- {
- var varTable = new Faker()
- .RuleFor(d => d.Name, f => f.Commerce.ProductName())
- .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
- .Generate();
- varTable.IsActive = true;
- return varTable;
- }
-
-
- public static VariableTableDto FakeVariableTableDto()
- {
- var varTable = new Faker()
- .RuleFor(d => d.Name, f => f.Commerce.ProductName())
- .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
- .Generate();
- varTable.IsActive = true;
- return varTable;
- }
-
- public static Variable FakeVariable()
- {
- var dbVariable = new Faker()
- .RuleFor(d => d.Name, f => f.Commerce.ProductName())
- .RuleFor(d => d.S7Address, f => $"DB1.DBD{f.Random.Int(0, 1000)}")
- .RuleFor(d => d.OpcUaNodeId, f => $"ns=2;s=My.DbDevice.Variable{f.Random.Int(1, 100)}")
- .RuleFor(d => d.ConversionFormula, f => "x * 1.0")
- .RuleFor(d => d.UpdatedBy, f => f.Name.FullName())
- .Generate();
-
- // dbVariable.DataType = 1;
- // dbVariable.PollLevel = 1;
- dbVariable.IsActive = true;
- dbVariable.VariableTableId = 1;
- dbVariable.IsHistoryEnabled = true;
- dbVariable.HistoryDeadband = 0.1;
- dbVariable.IsAlarmEnabled = false;
- dbVariable.AlarmMinValue = 0;
- dbVariable.AlarmMaxValue = 100;
- dbVariable.AlarmDeadband = 1;
- dbVariable.Protocol = 0;
- dbVariable.DataType = 0;
- dbVariable.CreatedAt = DateTime.Now;
- dbVariable.UpdatedAt = DateTime.Now;
- dbVariable.IsModified = false;
-
- return dbVariable;
- }
-
- public static DbMenu FakeDbMenu()
- {
- var dbMenu = new Faker()
- .RuleFor(d => d.Header, f => f.Commerce.Department())
- .RuleFor(d => d.Icon, f => f.Random.Word())
- .RuleFor(d => d.DisplayOrder, f => f.Random.Number(1, 10))
- .Generate();
- dbMenu.ParentId = 0;
- dbMenu.Childrens = new List();
- return dbMenu;
- }
-
- public static DbMqttServer FakeDbMqttServer()
- {
- var dbMqttServer = new Faker()
- .RuleFor(d => d.ServerName, f => f.Company.CompanyName())
- .RuleFor(d => d.ServerUrl, f => f.Internet.Ip())
- .RuleFor(d => d.Username, f => f.Internet.UserName())
- .RuleFor(d => d.Password, f => f.Internet.Password())
- .RuleFor(d => d.SubscribeTopic, f => "/topic/sub")
- .RuleFor(d => d.PublishTopic, f => "/topic/pub")
- .RuleFor(d => d.ClientId, f => Guid.NewGuid()
- .ToString())
- .RuleFor(d => d.MessageFormat, f => "JSON")
- .Generate();
- dbMqttServer.Port = 1883;
- dbMqttServer.IsActive = true;
- dbMqttServer.CreatedAt = DateTime.Now;
- return dbMqttServer;
- }
-
- // public static CreateDeviceDto FakeCreateDeviceDto()
- // {
- // var deviceDto = new Faker()
- // .RuleFor(d => d.Name, f => f.Commerce.ProductName())
- // .RuleFor(d => d.Description, f => f.Commerce.ProductDescription())
- // .RuleFor(d => d.IpAddress, f => f.Internet.Ip())
- // .RuleFor(d => d.OpcUaServerUrl, f => f.Internet.Url())
- // .Generate();
- // deviceDto.Port = 102;
- // deviceDto.Protocol = ProtocolType.S7;
- // deviceDto.Slot = 1;
- // deviceDto.Rack = 0;
- // deviceDto.CpuType = "S7-1200";
- // deviceDto.DeviceType = Core.Enums.DeviceType.SiemensPLC;
- //
- // return deviceDto;
- // }
-
- public static MenuBeanDto FakeCreateMenuDto()
- {
- var menuDto = new Faker()
- .RuleFor(m => m.Header, f => f.Commerce.ProductName())
- .RuleFor(m => m.Icon, f => f.Random.Word())
- .RuleFor(m => m.DisplayOrder, f => f.Random.Number(1, 100))
- .RuleFor(m => m.ParentId, f => f.Random.Number(0, 10)) // 假设可以有父菜单
- .Generate();
- return menuDto;
- }
-
- public static VariableDto FakeVariableDto()
- {
- var variableDto = new Faker()
- .RuleFor(v => v.Name, f => f.Commerce.ProductName())
- .RuleFor(v => v.S7Address, f => $"DB1.DBD{f.Random.Int(0, 1000)}")
- .RuleFor(v => v.SignalType, f => f.PickRandom())
- .RuleFor(v => v.PollingInterval, f => f.Random.Int(10, 1800000))
- .RuleFor(v => v.IsActive, f => f.Random.Bool())
- .RuleFor(v => v.IsHistoryEnabled, f => f.Random.Bool())
- .RuleFor(v => v.HistoryDeadband, f => f.Random.Double(0.0, 1.0))
- .RuleFor(v => v.IsAlarmEnabled, f => f.Random.Bool())
- .RuleFor(v => v.AlarmMinValue, f => f.Random.Double(0.0, 50.0))
- .RuleFor(v => v.AlarmMaxValue, f => f.Random.Double(50.0, 100.0))
- .RuleFor(v => v.AlarmDeadband, f => f.Random.Double(0.0, 1.0))
- .RuleFor(v => v.Protocol, f => f.PickRandom())
- .RuleFor(v => v.DataType, f => f.PickRandom(Enum.GetValues()))
- .RuleFor(v => v.OpcUaNodeId, f => $"ns=2;s=My.Variable{f.Random.Int(1, 100)}")
- .RuleFor(v => v.ConversionFormula, f => "x * 1.0")
- .RuleFor(v => v.UpdatedBy, f => f.Name.FullName())
- .RuleFor(v => v.DataValue, f => f.Random.Double(0, 100).ToString())
- .RuleFor(v => v.DisplayValue, f => f.Random.Word())
- .RuleFor(v => v.Description, f => f.Lorem.Sentence())
- .Generate();
- variableDto.VariableTableId = 1; // Default to 1 for testing purposes
- return variableDto;
- }
- }
-}
diff --git a/DMS.Infrastructure.UnitTests/Services/BaseServiceTest.cs b/DMS.Infrastructure.UnitTests/Services/BaseServiceTest.cs
deleted file mode 100644
index df40f39..0000000
--- a/DMS.Infrastructure.UnitTests/Services/BaseServiceTest.cs
+++ /dev/null
@@ -1,64 +0,0 @@
-// DMS.Infrastructure.UnitTests/Services/BaseServiceTest.cs
-
-using AutoMapper;
-using AutoMapper.Internal;
-using DMS.Application.Configurations;
-using DMS.Application.Interfaces;
-using DMS.Application.Interfaces.Database;
-using DMS.Application.Services;
-using DMS.Application.Services.Database;
-using DMS.Core.Interfaces;
-using DMS.Core.Interfaces.Repositories;
-using DMS.Infrastructure.Data;
-using DMS.Infrastructure.Repositories;
-using Microsoft.Extensions.DependencyInjection;
-
-
-namespace DMS.Infrastructure.UnitTests.Services;
-
-public class BaseServiceTest
-{
- // ServiceProvider 将是所有测试的服务容器
- protected readonly IServiceProvider ServiceProvider;
-
- public BaseServiceTest()
- {
- var services = new ServiceCollection();
-
- // --- 核心配置 ---
- services.AddAutoMapper(cfg =>
- {
- // 最终解决方案:根据异常信息的建议,设置此标记以忽略重复的Profile加载。
- // 注意:此属性位于 Internal() 方法下。
- cfg.Internal().AllowAdditiveTypeMapCreation = true;
-
- cfg.AddProfile(new DMS.Application.Profiles.MappingProfile());
- cfg.AddProfile(new DMS.Infrastructure.Profiles.MappingProfile());
- });
-
- // 2. 配置数据库上下文 (在测试中通常使用单例)
- services.AddSingleton();
-
- // --- 注册服务和仓储 ---
- // 使用 Transient 或 Scoped 取决于服务的生命周期需求,对于测试,Transient 通常更安全。
-
- // 注册仓储管理器
- services.AddTransient();
- services.AddTransient();
-
- // 注册应用服务
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- // services.AddTransient(); // 如果需要测试 VariableService,取消此行注释
- // ... 在这里注册所有其他的应用服务 ...
-
-
- // --- 构建服务提供程序 ---
- ServiceProvider = services.BuildServiceProvider();
-
- // 验证 AutoMapper 配置 (可选,但强烈推荐)
- var mapper = ServiceProvider.GetService();
- mapper?.ConfigurationProvider.AssertConfigurationIsValid();
- }
-}
diff --git a/DMS.Infrastructure.UnitTests/Services/DeviceAppServiceTest.cs b/DMS.Infrastructure.UnitTests/Services/DeviceAppServiceTest.cs
deleted file mode 100644
index 25a5ca0..0000000
--- a/DMS.Infrastructure.UnitTests/Services/DeviceAppServiceTest.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using DMS.Application.DTOs;
-using DMS.Application.Interfaces;
-using DMS.Application.Interfaces.Database;
-using DMS.Application.Services;
-using DMS.Application.Services.Database;
-using JetBrains.Annotations;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DMS.Infrastructure.UnitTests.Services;
-
-[TestSubject(typeof(DeviceAppService))]
-public class DeviceAppServiceTest : BaseServiceTest // 继承基类
-{
- private readonly IDeviceAppService _deviceService;
-
- public DeviceAppServiceTest() : base()
- {
- // 从 IoC 容器中解析出需要测试的服务
- // 使用 GetRequiredService 可以确保如果服务未注册,测试会立即失败,这通常是我们想要的。
- _deviceService = ServiceProvider.GetRequiredService();
- }
-
- [Fact]
- public async Task CreateDeviceWithDetailsAsyncTest()
- {
- // Arrange
- // var dto = new CreateDeviceWithDetailsDto
- // {
- // Device = FakerHelper.FakeCreateDeviceDto(),
- // VariableTable = FakerHelper.FakeVariableTableDto(),
- // DeviceMenu = FakerHelper.FakeCreateMenuDto(),
- // VariableTableMenu = FakerHelper.FakeCreateMenuDto()
- //
- // // ... 填充其他需要的数据
- // };
- //
- // // Act
- // var addDto = await _deviceService.CreateDeviceWithDetailsAsync(dto);
- //
- // // Assert
- // Assert.NotEqual(0, addDto.Device.Id);
- }
-
- [Fact]
- public async Task DeleteDeviceAsyncTest()
- {
- // Act
- var isSuccess = await _deviceService.DeleteDeviceByIdAsync(4);
-
- // Assert
- Assert.Equal(isSuccess,true);
- }
-
- [Fact]
- public async Task UpdateDeviceAsyncTest()
- {
- // UpdateDeviceDto dto = new UpdateDeviceDto()
- // {
- // Id = 5,
- // Name = "lalala",
- // IsActive = true,
- // Rack = 0,
- // Slot = 0
- //
- // };
- // var res = await _deviceService.UpdateDeviceAsync(dto);
- // Assert.NotEqual(res,0);
- }
-}
\ No newline at end of file
diff --git a/DMS.Infrastructure.UnitTests/Services/InitializeServiceTest.cs b/DMS.Infrastructure.UnitTests/Services/InitializeServiceTest.cs
deleted file mode 100644
index b0f837c..0000000
--- a/DMS.Infrastructure.UnitTests/Services/InitializeServiceTest.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using DMS.Application.Interfaces;
-using DMS.Application.Services;
-using DMS.Core.Interfaces.Repositories;
-using JetBrains.Annotations;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DMS.Infrastructure.UnitTests.Services;
-
-[TestSubject(typeof(InitializeService))]
-public class InitializeServiceTest:BaseServiceTest
-{
- private readonly IInitializeRepository _initializeRepository;
-
- public InitializeServiceTest()
- {
- _initializeRepository = ServiceProvider.GetRequiredService();
- }
-
- [Fact]
- public void InitializeTablesTest()
- {
- _initializeRepository.InitializeTables();
- }
-}
\ No newline at end of file
diff --git a/DMS.Infrastructure.UnitTests/Services/VariableAppServiceTest.cs b/DMS.Infrastructure.UnitTests/Services/VariableAppServiceTest.cs
deleted file mode 100644
index a74cd02..0000000
--- a/DMS.Infrastructure.UnitTests/Services/VariableAppServiceTest.cs
+++ /dev/null
@@ -1,80 +0,0 @@
-using DMS.Application.DTOs;
-using DMS.Application.Interfaces;
-using DMS.Application.Interfaces.Database;
-using DMS.Application.Services;
-using DMS.Application.Services.Database;
-using JetBrains.Annotations;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DMS.Infrastructure.UnitTests.Services;
-
-[TestSubject(typeof(VariableAppService))]
-public class VariableAppServiceTest : BaseServiceTest
-{
- private readonly IVariableAppService _variableAppService;
-
- public VariableAppServiceTest()
- {
- _variableAppService = ServiceProvider.GetRequiredService();
- }
-
- [Fact]
- public async Task CreateVariableAsyncTest()
- {
- // Arrange
- var dto = FakerHelper.FakeVariableDto();
- dto.VariableTableId = 1; // Assuming a variable table with ID 1 exists for testing
-
- // Act
- var createdId = await _variableAppService.CreateVariableAsync(dto);
-
- // Assert
- //Assert.NotEqual(0, createdId);
- }
-
- [Fact]
- public async Task UpdateVariableAsyncTest()
- {
- // Arrange: Create a variable first
- var createDto = FakerHelper.FakeVariableDto();
- createDto.VariableTableId = 1; // Assuming a variable table with ID 1 exists for testing
- var createdId = await _variableAppService.CreateVariableAsync(createDto);
- //Assert.NotEqual(0, createdId);
-
- //// Retrieve the created variable to update
- //var variableToUpdate = await _variableAppService.GetVariableByIdAsync(createdId);
- //Assert.NotNull(variableToUpdate);
-
- //// Modify some properties
- //variableToUpdate.Name = "Updated Variable Name";
- //variableToUpdate.Description = "Updated Description";
-
- //// Act
- //var affectedRows = await _variableAppService.UpdateVariableAsync(variableToUpdate);
-
- //// Assert
- //Assert.Equal(1, affectedRows);
- //var updatedVariable = await _variableAppService.GetVariableByIdAsync(createdId);
- //Assert.NotNull(updatedVariable);
- //Assert.Equal("Updated Variable Name", updatedVariable.Name);
- //Assert.Equal("Updated Description", updatedVariable.Description);
- }
-
- [Fact]
- public async Task DeleteVariableAsyncTest()
- {
- // Arrange: Create a variable first
- //var createDto = FakerHelper.FakeVariableDto();
- //createDto.VariableTableId = 1; // Assuming a variable table with ID 1 exists for testing
- //var createdId = await _variableAppService.CreateVariableAsync(createDto);
- //Assert.NotEqual(0, createdId);
-
- //// Act
- //var isDeleted = await _variableAppService.DeleteVariableAsync(createdId);
-
- //// Assert
- //Assert.True(isDeleted);
- //var deletedVariable = await _variableAppService.GetVariableByIdAsync(createdId);
- //Assert.Null(deletedVariable);
- }
-}
\ No newline at end of file
diff --git a/DMS.Infrastructure.UnitTests/Services/VariableTableAppServiceTest.cs b/DMS.Infrastructure.UnitTests/Services/VariableTableAppServiceTest.cs
deleted file mode 100644
index 9c51353..0000000
--- a/DMS.Infrastructure.UnitTests/Services/VariableTableAppServiceTest.cs
+++ /dev/null
@@ -1,87 +0,0 @@
-using DMS.Application.DTOs;
-using DMS.Application.Interfaces;
-using DMS.Application.Interfaces.Database;
-using DMS.Application.Services;
-using DMS.Application.Services.Database;
-using JetBrains.Annotations;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DMS.Infrastructure.UnitTests.Services;
-
-[TestSubject(typeof(VariableTableAppService))]
-public class VariableTableAppServiceTest : BaseServiceTest
-{
- private readonly IVariableTableAppService _variableTableAppService;
-
- public VariableTableAppServiceTest()
- {
- _variableTableAppService = ServiceProvider.GetRequiredService();
- }
-
- [Fact]
- public async Task CreateVariableTableAsyncTest()
- {
- var dto = new CreateVariableTableWithMenuDto()
- {
- VariableTable = FakerHelper.FakeVariableTableDto(),
- Menu = FakerHelper.FakeCreateMenuDto(),
- DeviceId = 5
- };
- var addVarTable= await _variableTableAppService.CreateVariableTableAsync(dto);
- Assert.NotEqual(addVarTable.VariableTable.Id, 0);
- }
-
- [Fact]
- public async Task DeleteVariableTableAsyncTest()
- {
- // Arrange: Create a variable table first
- var createDto = new CreateVariableTableWithMenuDto()
- {
- VariableTable = FakerHelper.FakeVariableTableDto(),
- Menu = FakerHelper.FakeCreateMenuDto(),
- DeviceId = 5 // Assuming a device with ID 5 exists for testing
- };
- var createdVariableTable = await _variableTableAppService.CreateVariableTableAsync(createDto);
- Assert.NotEqual(createdVariableTable.VariableTable.Id, 0);
-
- // Act: Delete the created variable table
- var isDeleted = await _variableTableAppService.DeleteVariableTableAsync(createdVariableTable.VariableTable.Id);
-
- // Assert: Verify deletion was successful
- Assert.True(isDeleted);
-
- // Optionally, try to retrieve the deleted variable table to confirm it's gone
- var deletedTable = await _variableTableAppService.GetVariableTableByIdAsync(createdVariableTable.VariableTable.Id);
- Assert.Null(deletedTable);
- }
-
- [Fact]
- public async Task UpdateVariableTableAsyncTest()
- {
- // Arrange: Create a variable table first
- var createDto = new CreateVariableTableWithMenuDto()
- {
- VariableTable = FakerHelper.FakeVariableTableDto(),
- Menu = FakerHelper.FakeCreateMenuDto(),
- DeviceId = 5 // Assuming a device with ID 5 exists for testing
- };
- var createdVariableTable = await _variableTableAppService.CreateVariableTableAsync(createDto);
- Assert.NotEqual(createdVariableTable.VariableTable.Id, 0);
-
- // Modify some properties of the DTO
- createdVariableTable.VariableTable.Name = "Updated Variable Table Name";
- createdVariableTable.VariableTable.Description = "This is an updated description.";
-
- // Act: Update the variable table
- var affectedRows = await _variableTableAppService.UpdateVariableTableAsync(createdVariableTable.VariableTable);
-
- // Assert: Verify update was successful
- Assert.Equal(1, affectedRows);
-
- // Retrieve the updated variable table to confirm changes
- var updatedTable = await _variableTableAppService.GetVariableTableByIdAsync(createdVariableTable.VariableTable.Id);
- Assert.NotNull(updatedTable);
- Assert.Equal("Updated Variable Table Name", updatedTable.Name);
- Assert.Equal("This is an updated description.", updatedTable.Description);
- }
-}
\ No newline at end of file
diff --git a/DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj b/DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj
deleted file mode 100644
index f36b8b0..0000000
--- a/DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
- net8.0-windows7.0
- enable
- enable
-
- false
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DMS.WPF.UnitTests/UnitTest1.cs b/DMS.WPF.UnitTests/UnitTest1.cs
deleted file mode 100644
index cbd3518..0000000
--- a/DMS.WPF.UnitTests/UnitTest1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace DMS.WPF.UnitTests;
-
-public class UnitTest1
-{
- [Fact]
- public void Test1()
- {
-
- }
-}
\ No newline at end of file
diff --git a/DMS.WPF.UnitTests/ViewModelTest/BaseServiceTest.cs b/DMS.WPF.UnitTests/ViewModelTest/BaseServiceTest.cs
deleted file mode 100644
index 827a0e2..0000000
--- a/DMS.WPF.UnitTests/ViewModelTest/BaseServiceTest.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-// DMS.Infrastructure.UnitTests/Services/BaseServiceTest.cs
-
-using AutoMapper;
-using AutoMapper.Internal;
-using DMS.Application.Configurations;
-using DMS.Application.Interfaces.Database;
-using DMS.Application.Services.Database;
-using DMS.Core.Interfaces;
-using DMS.Core.Interfaces.Repositories;
-using DMS.Infrastructure.Data;
-using DMS.Infrastructure.Repositories;
-using DMS.WPF.Interfaces;
-using DMS.WPF.Services;
-using DMS.WPF.ViewModels;
-using Microsoft.Extensions.DependencyInjection;
-
-namespace DMS.WPF.UnitTests.ViewModelTest;
-
-public class BaseServiceTest
-{
- // ServiceProvider 将是所有测试的服务容器
- protected readonly IServiceProvider ServiceProvider;
-
- public BaseServiceTest()
- {
- var services = new ServiceCollection();
-
- // --- 核心配置 ---
- services.AddAutoMapper(cfg =>
- {
- // 最终解决方案:根据异常信息的建议,设置此标记以忽略重复的Profile加载。
- // 注意:此属性位于 Internal() 方法下。
- cfg.Internal().AllowAdditiveTypeMapCreation = true;
-
- cfg.AddProfile(new DMS.Application.Profiles.MappingProfile());
- cfg.AddProfile(new DMS.Infrastructure.Profiles.MappingProfile());
- cfg.AddProfile(new DMS.WPF.Profiles.MappingProfile());
- });
-
- // 2. 配置数据库上下文 (在测试中通常使用单例)
- services.AddSingleton();
-
- // --- 注册服务和仓储 ---
- // 使用 Transient 或 Scoped 取决于服务的生命周期需求,对于测试,Transient 通常更安全。
-
- // 注册仓储管理器
- services.AddTransient();
- services.AddTransient();
-
- // 注册应用服务
- services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- // services.AddTransient();
- services.AddTransient();
- services.AddTransient();
- // services.AddTransient();
- services.AddTransient();
- // services.AddTransient(); // 如果需要测试
- // VariableService,取消此行注释
- // ... 在这里注册所有其他的应用服务 ...
-
-
-
- // --- 构建服务提供程序 ---
- ServiceProvider = services.BuildServiceProvider();
-
- // 验证 AutoMapper 配置 (可选,但强烈推荐)
- var mapper = ServiceProvider.GetService();
- mapper?.ConfigurationProvider.AssertConfigurationIsValid();
- }
-}
diff --git a/DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs b/DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs
deleted file mode 100644
index 52bc15c..0000000
--- a/DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using AutoMapper;
-using DMS.Application.DTOs;
-using DMS.Application.Interfaces;
-using DMS.WPF.Services;
-using DMS.WPF.ViewModels;
-using DMS.WPF.ViewModels.Dialogs;
-using DMS.WPF.ViewModels.Items;
-using Microsoft.Extensions.DependencyInjection;
-using Moq;
-
-namespace DMS.WPF.UnitTests.ViewModelTest
-{
- public class DevicesViewModelTests:BaseServiceTest
- {
- private readonly DevicesViewModel _devicesViewModel;
-
-
- public DevicesViewModelTests()
- {
- _devicesViewModel= ServiceProvider.GetRequiredService();
- }
-
- [Fact]
- public async Task AddDevice_Test()
- {
- // Arrange
-
- // Act
- await _devicesViewModel.AddDevice();
-
-
- }
-
-
- }
-}
\ No newline at end of file
diff --git a/DMS.WPF/App.xaml.cs b/DMS.WPF/App.xaml.cs
index 523c241..78b42bb 100644
--- a/DMS.WPF/App.xaml.cs
+++ b/DMS.WPF/App.xaml.cs
@@ -32,7 +32,7 @@ using DMS.WPF.Logging;
using DMS.WPF.Services;
using DMS.WPF.ViewModels;
using DMS.WPF.ViewModels.Dialogs;
-using DMS.WPF.ViewModels.Items;
+using DMS.WPF.ItemViewModel;
using DMS.WPF.Views;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
@@ -81,7 +81,7 @@ public partial class App : System.Windows.Application
{
Host.Services.GetRequiredService();
Host.Services.GetRequiredService();
- DeviceItemViewModel.EventService = Host.Services.GetRequiredService();
+ DeviceItem.EventService = Host.Services.GetRequiredService();
// 初始化数据处理链
var dataProcessingService = Host.Services.GetRequiredService();
dataProcessingService.AddProcessor(Host.Services.GetRequiredService());
diff --git a/DMS.WPF/Factories/VariableItemViewModelFactory.cs b/DMS.WPF/Factories/VariableItemViewModelFactory.cs
index 46ad0a5..3fa07e6 100644
--- a/DMS.WPF/Factories/VariableItemViewModelFactory.cs
+++ b/DMS.WPF/Factories/VariableItemViewModelFactory.cs
@@ -1,5 +1,5 @@
using DMS.Application.DTOs;
-using DMS.WPF.ViewModels.Items;
+using DMS.WPF.ItemViewModel;
using DMS.Application.Configurations;
using Microsoft.Extensions.DependencyInjection;
@@ -16,7 +16,7 @@ namespace DMS.WPF.Factories
///
/// 变量数据传输对象
/// VariableItemViewModel实例
- VariableItemViewModel CreateNewVariableItemViewModel();
+ VariableItem CreateNewVariableItemViewModel();
}
@@ -35,10 +35,10 @@ namespace DMS.WPF.Factories
///
/// 变量数据传输对象
/// VariableItemViewModel实例
- public VariableItemViewModel CreateNewVariableItemViewModel()
+ public VariableItem CreateNewVariableItemViewModel()
{
- var viewModel = new VariableItemViewModel()
+ var viewModel = new VariableItem()
{
IsActive = _appSettings.VariableImportTemplate.IsActive,
diff --git a/DMS.WPF/Interfaces/IDataStorageService.cs b/DMS.WPF/Interfaces/IDataStorageService.cs
index 15a9a34..d0df143 100644
--- a/DMS.WPF/Interfaces/IDataStorageService.cs
+++ b/DMS.WPF/Interfaces/IDataStorageService.cs
@@ -1,6 +1,6 @@
using System.Collections.Concurrent;
using System.Collections.ObjectModel;
-using DMS.WPF.ViewModels.Items;
+using DMS.WPF.ItemViewModel;
using ObservableCollections;
namespace DMS.WPF.Interfaces;
@@ -10,40 +10,40 @@ public interface IDataStorageService
///
/// 设备列表。
///
- ObservableDictionary Devices { get; set; }
+ ObservableDictionary Devices { get; set; }
///
/// 设备列表。
///
- ObservableDictionary VariableTables { get; set; }
+ ObservableDictionary VariableTables { get; set; }
///
/// 变量数据列表。
///
- ObservableDictionary Variables { get; set; }
+ ObservableDictionary Variables { get; set; }
///
/// MQTT服务器列表。
///
- ObservableDictionary MqttServers { get; set; }
+ ObservableDictionary MqttServers { get; set; }
///
/// 菜单列表。
///
- ObservableCollection Menus { get; set; }
+ ObservableCollection