From 8b9b096df9b718d8551e237b6efde0b8591d1733 Mon Sep 17 00:00:00 2001 From: "David P.G" Date: Sun, 27 Jul 2025 21:09:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=B5=8B=E8=AF=95WP?= =?UTF-8?q?F=E7=9A=84=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj | 33 +++++++++++++++++ DMS.WPF.UnitTests/UnitTest1.cs | 10 ++++++ .../ViewModelTest/DevicesViewModelTests.cs | 36 +++++++++++++++++++ DMS.WPF/Profiles/MappingProfile.cs | 24 +++++++++++++ .../ViewModels/Dialogs/DialogViewModelBase.cs | 27 ++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj create mode 100644 DMS.WPF.UnitTests/UnitTest1.cs create mode 100644 DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs create mode 100644 DMS.WPF/Profiles/MappingProfile.cs create mode 100644 DMS.WPF/ViewModels/Dialogs/DialogViewModelBase.cs diff --git a/DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj b/DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj new file mode 100644 index 0000000..f36b8b0 --- /dev/null +++ b/DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj @@ -0,0 +1,33 @@ + + + + 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 new file mode 100644 index 0000000..cbd3518 --- /dev/null +++ b/DMS.WPF.UnitTests/UnitTest1.cs @@ -0,0 +1,10 @@ +namespace DMS.WPF.UnitTests; + +public class UnitTest1 +{ + [Fact] + public void Test1() + { + + } +} \ No newline at end of file diff --git a/DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs b/DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs new file mode 100644 index 0000000..52bc15c --- /dev/null +++ b/DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs @@ -0,0 +1,36 @@ +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/Profiles/MappingProfile.cs b/DMS.WPF/Profiles/MappingProfile.cs new file mode 100644 index 0000000..f219148 --- /dev/null +++ b/DMS.WPF/Profiles/MappingProfile.cs @@ -0,0 +1,24 @@ +using AutoMapper; +using DMS.Application.DTOs; +using DMS.WPF.ViewModels.Items; + +namespace DMS.WPF.Profiles +{ + public class MappingProfile : Profile + { + public MappingProfile() + { + CreateMap().ConstructUsing(src => new DeviceItemViewModel(src)); + CreateMap(); + CreateMap() + .ForMember(dest => dest.Children, opt => opt.Ignore()) + .ConstructUsing(src => new MenuBeanItemViewModel(src, null)); // 假设 NavigationService 可以通过依赖注入获取或在ViewModel中处理 + CreateMap().ConstructUsing(src => new MqttServerItemViewModel(src)); + CreateMap().ConstructUsing(src => new UserItemViewModel(src)); + CreateMap().ConstructUsing(src => new VariableHistoryItemViewModel(src)); + CreateMap().ConstructUsing(src => new VariableItemViewModel(src)); + CreateMap().ConstructUsing(src => new VariableMqttAliasItemViewModel(src)); + CreateMap().ConstructUsing(src => new VariableTableItemViewModel(src)); + } + } +} \ No newline at end of file diff --git a/DMS.WPF/ViewModels/Dialogs/DialogViewModelBase.cs b/DMS.WPF/ViewModels/Dialogs/DialogViewModelBase.cs new file mode 100644 index 0000000..1eadab3 --- /dev/null +++ b/DMS.WPF/ViewModels/Dialogs/DialogViewModelBase.cs @@ -0,0 +1,27 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using CommunityToolkit.Mvvm.Input; +using System; +using System.Threading.Tasks; + +namespace DMS.WPF.ViewModels.Dialogs +{ + public abstract partial class DialogViewModelBase : ObservableObject + { + [ObservableProperty] + private string _title; + + [ObservableProperty] + private string _primaryButContent; + + public event Func CloseRequested; + + [RelayCommand] + protected virtual async Task Close(TResult result) + { + if (CloseRequested != null) + { + await CloseRequested(result); + } + } + } +} \ No newline at end of file