diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs index 336d163cfe..76ba39c3f2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs @@ -2,6 +2,6 @@ { public static class CmsKitErrorCodes { - //Add your business exception error codes here... + public const string TagAlreadyExist = "CmsKit:0001"; } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagAlreadyExistException.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagAlreadyExistException.cs new file mode 100644 index 0000000000..6cae0dde92 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagAlreadyExistException.cs @@ -0,0 +1,17 @@ +using JetBrains.Annotations; +using System; +using Volo.Abp; + +namespace Volo.CmsKit.Tags +{ + [Serializable] + public class TagAlreadyExistException : BusinessException + { + public TagAlreadyExistException([NotNull] string entityType, [NotNull] string name) + { + Code = CmsKitErrorCodes.TagAlreadyExist; + WithData(nameof(Tag.EntityType), entityType); + WithData(nameof(Tag.Name), name); + } + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs index e1e9366a99..042b4e27a9 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs @@ -41,7 +41,7 @@ namespace Volo.CmsKit.Tags { if (await _tagRepository.AnyAsync(entityType, name, tenantId, cancellationToken)) { - throw new BusinessException(message: "Tag already exist!"); // Already Exist + throw new TagAlreadyExistException(entityType, name); } return await _tagRepository.InsertAsync( @@ -63,7 +63,7 @@ namespace Volo.CmsKit.Tags if (name != entity.Name && await _tagRepository.AnyAsync(entity.EntityType, name, entity.TenantId, cancellationToken)) { - throw new BusinessException(message: "Tag already exist!"); // Already Exist + throw new TagAlreadyExistException(entity.EntityType, name); } entity.SetName(name); diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs index 237434ef9f..4ad0d43468 100644 --- a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs @@ -3,12 +3,8 @@ using NSubstitute; using Shouldly; using System; using System.Threading.Tasks; -using Volo.Abp; -using Volo.Abp.Clients; using Volo.Abp.Users; -using Volo.Abp.Validation; using Volo.CmsKit.Admin.Tags; -using Volo.CmsKit.Public.Tags; using Xunit; namespace Volo.CmsKit.Tags @@ -46,7 +42,7 @@ namespace Volo.CmsKit.Tags [Fact] public async Task ShouldThrowException_WhenTagAlreadyExist() { - await Should.ThrowAsync(async () => await _tagAdminAppService.CreateAsync(new TagCreateDto + await Should.ThrowAsync(async () => await _tagAdminAppService.CreateAsync(new TagCreateDto { EntityType = _cmsKitTestData.Content_1_EntityType, Name = _cmsKitTestData.Content_1_Tags[0],