From 8736f5470c37775d69553bc1417f7a851c38c143 Mon Sep 17 00:00:00 2001 From: "DESKTOP-G961P6V\\Zhh" <839860190@qq.com> Date: Wed, 13 Mar 2024 04:24:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=80=A7=E5=88=AB=E8=AE=BE=E7=BD=AE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E6=94=AF=E6=8C=81=E7=AE=80=E7=A0=81=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sexs/UpdateSexDto.cs | 4 +- .../Sexs/SexAppService.cs | 23 ++++----- .../MedicalReportTypeManager.cs | 1 + .../SexAppServiceTest.cs | 51 +++++++++++++++++++ 4 files changed, 63 insertions(+), 16 deletions(-) create mode 100644 test/Shentun.Peis.Application.Tests/SexAppServiceTest.cs diff --git a/src/Shentun.Peis.Application.Contracts/Sexs/UpdateSexDto.cs b/src/Shentun.Peis.Application.Contracts/Sexs/UpdateSexDto.cs index 4a8428c6..a5a09edc 100644 --- a/src/Shentun.Peis.Application.Contracts/Sexs/UpdateSexDto.cs +++ b/src/Shentun.Peis.Application.Contracts/Sexs/UpdateSexDto.cs @@ -11,8 +11,8 @@ namespace Shentun.Peis.Sexs { [Required] public string DisplayName { get; set; } - //[Required] - //public string SimpleCode { get; set; } + [Required] + public string SimpleCode { get; set; } } diff --git a/src/Shentun.Peis.Application/Sexs/SexAppService.cs b/src/Shentun.Peis.Application/Sexs/SexAppService.cs index 6946e81a..fe550d4b 100644 --- a/src/Shentun.Peis.Application/Sexs/SexAppService.cs +++ b/src/Shentun.Peis.Application/Sexs/SexAppService.cs @@ -56,27 +56,22 @@ namespace Shentun.Peis.Sexs /// 修改参数 /// [HttpPost] - public async Task UpdateAsync(char Id, UpdateSexDto input) + public async Task UpdateAsync(char Id, UpdateSexDto input) { var ent = await _repository.GetAsync(m => m.Id == Id); - if (ent != null) - { - if (DateHelper.IsNullOrEmpty(input.DisplayName)) - throw new UserFriendlyException("名称不能为空"); + if (DateHelper.IsNullOrEmpty(input.DisplayName)) + throw new UserFriendlyException("名称不能为空"); - ent.DisplayName = input.DisplayName; - ent.SimpleCode = LanguageConverter.GetPYSimpleCode(input.DisplayName); + ent.DisplayName = input.DisplayName; + ent.SimpleCode = input.SimpleCode; + + var newent = await _repository.UpdateAsync(ent); + + return ObjectMapper.Map(newent); - var newent = await _repository.UpdateAsync(ent); - return ObjectMapper.Map(newent); - } - else - { - return ObjectMapper.Map(ent); - } } diff --git a/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs b/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs index acf8361a..fb85bf28 100644 --- a/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs +++ b/src/Shentun.Peis.Domain/MedicalReportTypes/MedicalReportTypeManager.cs @@ -36,6 +36,7 @@ namespace Shentun.Peis.MedicalReportTypes { Check.NotNullOrWhiteSpace(entity.DisplayName, nameof(entity.DisplayName)); await EntityHelper.CheckSameName(_repository, entity.DisplayName); + return new MedicalReportType( GuidGenerator.Create() ) diff --git a/test/Shentun.Peis.Application.Tests/SexAppServiceTest.cs b/test/Shentun.Peis.Application.Tests/SexAppServiceTest.cs new file mode 100644 index 00000000..a3a15353 --- /dev/null +++ b/test/Shentun.Peis.Application.Tests/SexAppServiceTest.cs @@ -0,0 +1,51 @@ +using Microsoft.EntityFrameworkCore; +using Shentun.Peis.GuideTypes; +using Shentun.Peis.Models; +using Shentun.Peis.Sexs; +using Shouldly; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Uow; +using Xunit; +using Xunit.Abstractions; + +namespace Shentun.Peis +{ + public class SexAppServiceTest:PeisApplicationTestBase + { + private readonly IRepository _repository; + private readonly SexAppService _appService; + private readonly ITestOutputHelper _output; + private readonly IUnitOfWorkManager _unitOfWorkManager; + public SexAppServiceTest(ITestOutputHelper testOutputHelper) + { + _output = testOutputHelper; + _unitOfWorkManager = GetRequiredService(); + _repository = GetRequiredService>(); + _appService = GetRequiredService(); + } + [Fact] + public async Task UpdateAsync() + { + var dto = new UpdateSexDto() { + DisplayName = "未知", + SimpleCode = "A", + }; + try + { + await _appService.UpdateAsync('U', dto); + } + catch (Exception ex) + { + _output.WriteLine(ex.ToString()); + } + + } + + } +}