添加了测试WPF的单元测试
This commit is contained in:
33
DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj
Normal file
33
DMS.WPF.UnitTests/DMS.WPF.UnitTests.csproj
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0-windows7.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||||
|
<PackageReference Include="Bogus" Version="35.6.3" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||||
|
<PackageReference Include="JetBrains.Annotations" Version="2025.1.0-eap1" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.7" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||||
|
<PackageReference Include="Moq" Version="4.20.72" />
|
||||||
|
<PackageReference Include="xunit" Version="2.5.3" />
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Xunit" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DMS.Application\DMS.Application.csproj" />
|
||||||
|
<ProjectReference Include="..\DMS.WPF\DMS.WPF.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
10
DMS.WPF.UnitTests/UnitTest1.cs
Normal file
10
DMS.WPF.UnitTests/UnitTest1.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace DMS.WPF.UnitTests;
|
||||||
|
|
||||||
|
public class UnitTest1
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void Test1()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
36
DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs
Normal file
36
DMS.WPF.UnitTests/ViewModelTest/DevicesViewModelTests.cs
Normal file
@@ -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<DevicesViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddDevice_Test()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
|
||||||
|
// Act
|
||||||
|
await _devicesViewModel.AddDevice();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
24
DMS.WPF/Profiles/MappingProfile.cs
Normal file
24
DMS.WPF/Profiles/MappingProfile.cs
Normal file
@@ -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<DeviceDto, DeviceItemViewModel>().ConstructUsing(src => new DeviceItemViewModel(src));
|
||||||
|
CreateMap<DeviceItemViewModel, DeviceDto>();
|
||||||
|
CreateMap<MenuBeanDto, MenuBeanItemViewModel>()
|
||||||
|
.ForMember(dest => dest.Children, opt => opt.Ignore())
|
||||||
|
.ConstructUsing(src => new MenuBeanItemViewModel(src, null)); // 假设 NavigationService 可以通过依赖注入获取或在ViewModel中处理
|
||||||
|
CreateMap<MqttServerDto, MqttServerItemViewModel>().ConstructUsing(src => new MqttServerItemViewModel(src));
|
||||||
|
CreateMap<UserDto, UserItemViewModel>().ConstructUsing(src => new UserItemViewModel(src));
|
||||||
|
CreateMap<VariableHistoryDto, VariableHistoryItemViewModel>().ConstructUsing(src => new VariableHistoryItemViewModel(src));
|
||||||
|
CreateMap<VariableDto, VariableItemViewModel>().ConstructUsing(src => new VariableItemViewModel(src));
|
||||||
|
CreateMap<VariableMqttAliasDto, VariableMqttAliasItemViewModel>().ConstructUsing(src => new VariableMqttAliasItemViewModel(src));
|
||||||
|
CreateMap<VariableTableDto, VariableTableItemViewModel>().ConstructUsing(src => new VariableTableItemViewModel(src));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
DMS.WPF/ViewModels/Dialogs/DialogViewModelBase.cs
Normal file
27
DMS.WPF/ViewModels/Dialogs/DialogViewModelBase.cs
Normal file
@@ -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<TResult> : ObservableObject
|
||||||
|
{
|
||||||
|
[ObservableProperty]
|
||||||
|
private string _title;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
private string _primaryButContent;
|
||||||
|
|
||||||
|
public event Func<TResult, Task> CloseRequested;
|
||||||
|
|
||||||
|
[RelayCommand]
|
||||||
|
protected virtual async Task Close(TResult result)
|
||||||
|
{
|
||||||
|
if (CloseRequested != null)
|
||||||
|
{
|
||||||
|
await CloseRequested(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user