Browse Source

CmsKit - Add TagAlreadyExistException

pull/6901/head
enisn 6 years ago
parent
commit
bf6b37f3e9
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs
  2. 17
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagAlreadyExistException.cs
  3. 4
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/TagManager.cs
  4. 6
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs

2
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";
}
}

17
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);
}
}
}

4
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);

6
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<BusinessException>(async () => await _tagAdminAppService.CreateAsync(new TagCreateDto
await Should.ThrowAsync<TagAlreadyExistException>(async () => await _tagAdminAppService.CreateAsync(new TagCreateDto
{
EntityType = _cmsKitTestData.Content_1_EntityType,
Name = _cmsKitTestData.Content_1_Tags[0],

Loading…
Cancel
Save