From a1fd94dc7f4f43b3939cdd7b09512b3ec60c2459 Mon Sep 17 00:00:00 2001 From: WangJunZzz <510423039@qq.com> Date: Sat, 14 Aug 2021 02:27:29 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=AE=8C=E6=88=90=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=AD=97=E5=85=B8=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataDictionaryAppService.cs | 6 +- .../Aggregates/DataDictionary.cs | 2 +- .../Aggregates/DataDictionaryDetail.cs | 2 +- .../DataDictionaryAppService_Tests.cs | 75 +++++++++++++++++++ 4 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 aspnet-core/modules/DataDictionaryManagement/test/CompanyName.ProjectName.DataDictionaryManagement.Application.Tests/DataDictionaries/DataDictionaryAppService_Tests.cs diff --git a/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs b/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs index 023c8958..bb105597 100644 --- a/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs +++ b/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Application/DataDictionaries/DataDictionaryAppService.cs @@ -18,9 +18,11 @@ namespace CompanyName.ProjectName.DataDictionaryManagement.DataDictionaries /// 如果是其他的操作全部通过对应manger进行操作 /// private readonly IDataDictionaryRepository _dataDictionaryRepository; - private readonly DataDictionaryManager _dataDictionaryManager; - public DataDictionaryAppService(IDataDictionaryRepository dataDictionaryRepository, DataDictionaryManager dataDictionaryManager) + + public DataDictionaryAppService( + IDataDictionaryRepository dataDictionaryRepository, + DataDictionaryManager dataDictionaryManager) { _dataDictionaryRepository = dataDictionaryRepository; _dataDictionaryManager = dataDictionaryManager; diff --git a/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionary.cs b/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionary.cs index 46910368..11992271 100644 --- a/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionary.cs +++ b/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionary.cs @@ -90,7 +90,7 @@ namespace CompanyName.ProjectName.DataDictionaryManagement.DataDictionaries.Aggr private void SetDescription(string description) { Guard.Length(description, nameof(description), DataDictionaryMaxLengths.Description); - Description = description; + Description = description ?? string.Empty; } public void AddDetail(Guid dataDictionayDetailId, string code, string displayText, int order = 1, diff --git a/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionaryDetail.cs b/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionaryDetail.cs index 14d98899..c78ed685 100644 --- a/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionaryDetail.cs +++ b/aspnet-core/modules/DataDictionaryManagement/src/CompanyName.ProjectName.DataDictionaryManagement.Domain/DataDictionaries/Aggregates/DataDictionaryDetail.cs @@ -86,7 +86,7 @@ namespace CompanyName.ProjectName.DataDictionaryManagement.DataDictionaries.Aggr public void SetDescription(string description) { Guard.Length(description, nameof(description), DataDictionaryMaxLengths.Description); - Description = description; + Description = Description = description ?? string.Empty; } } } \ No newline at end of file diff --git a/aspnet-core/modules/DataDictionaryManagement/test/CompanyName.ProjectName.DataDictionaryManagement.Application.Tests/DataDictionaries/DataDictionaryAppService_Tests.cs b/aspnet-core/modules/DataDictionaryManagement/test/CompanyName.ProjectName.DataDictionaryManagement.Application.Tests/DataDictionaries/DataDictionaryAppService_Tests.cs new file mode 100644 index 00000000..33624dfc --- /dev/null +++ b/aspnet-core/modules/DataDictionaryManagement/test/CompanyName.ProjectName.DataDictionaryManagement.Application.Tests/DataDictionaries/DataDictionaryAppService_Tests.cs @@ -0,0 +1,75 @@ +using System.Linq; +using System.Threading.Tasks; +using CompanyName.ProjectName.DataDictionaryManagement.DataDictionaries.Dtos; +using Shouldly; +using Xunit; + +namespace CompanyName.ProjectName.DataDictionaryManagement.DataDictionaries +{ + public class DataDictionaryAppService_Tests : DataDictionaryManagementApplicationTestBase + { + private readonly IDataDictionaryAppService _dataDictionaryAppService; + + public DataDictionaryAppService_Tests() + { + _dataDictionaryAppService = GetRequiredService(); + } + + [Fact] + public async Task Test_GetPagingListAsync_Ok() + { + var result = await _dataDictionaryAppService.GetPagingListAsync(new PagingDataDictionaryInput() + { + Filter = "Gender" + }); + + result.TotalCount.ShouldBe(1); + result.Items.FirstOrDefault().DisplayText.ShouldBe("性别"); + var result1 = await _dataDictionaryAppService.GetPagingListAsync(new PagingDataDictionaryInput() + { + Filter = "性别" + }); + + result1.TotalCount.ShouldBe(1); + result1.Items.FirstOrDefault().Code.ShouldBe("Gender"); + } + + [Fact] + public async Task Test_CreateAsync_Ok() + { + var input = new CreateDataDictinaryInput() + { + Code = "Xunit", + DisplayText = "单元测试" + }; + await _dataDictionaryAppService.CreateAsync(input); + + var result = await _dataDictionaryAppService.GetPagingListAsync(new PagingDataDictionaryInput()); + result.TotalCount.ShouldBe(2); + } + + [Fact] + public async Task Test_CreateDetailAsync_Ok() + { + var input = new CreateDataDictinaryDetailInput() + { + Id = DataDictionaryManagementConsts.SeedDataDictionaryId, + Code = "Detail", + DisplayText = "明细", + Description = "单元测试", + }; + + await _dataDictionaryAppService.CreateDetailAsync(input); + + var result = await _dataDictionaryAppService.GetPagingDetailListAsync( + new PagingDataDictionaryDetailInput() + { + DataDictionaryId = DataDictionaryManagementConsts.SeedDataDictionaryId, + Filter = "Detail" + } + ); + + result.Items.Any(e => e.Code == "Detail" && e.IsEnabled == true).ShouldBeTrue(); + } + } +} \ No newline at end of file