mirror of https://github.com/abpframework/abp.git
committed by
GitHub
7 changed files with 82 additions and 5 deletions
@ -1,12 +1,17 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
using Volo.CmsKit.Tags; |
|||
|
|||
namespace Volo.CmsKit.Admin.Tags |
|||
{ |
|||
public class TagCreateDto |
|||
{ |
|||
[Required] |
|||
[DynamicMaxLength(typeof(TagConsts), nameof(TagConsts.MaxEntityTypeLength))] |
|||
public string EntityType { get; set; } |
|||
|
|||
[Required] |
|||
[DynamicMaxLength(typeof(TagConsts), nameof(TagConsts.MaxNameLength))] |
|||
public string Name { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -1,10 +1,13 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
using Volo.CmsKit.Tags; |
|||
|
|||
namespace Volo.CmsKit.Admin.Tags |
|||
{ |
|||
public class TagUpdateDto |
|||
{ |
|||
[Required] |
|||
[DynamicMaxLength(typeof(TagConsts), nameof(TagConsts.MaxNameLength))] |
|||
public string Name { get; set; } |
|||
} |
|||
} |
|||
|
|||
@ -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); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using NSubstitute; |
|||
using Shouldly; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Users; |
|||
using Volo.CmsKit.Admin.Tags; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Tags |
|||
{ |
|||
public class TagAdminAppService_Tests : CmsKitApplicationTestBase |
|||
{ |
|||
private readonly ITagAdminAppService _tagAdminAppService; |
|||
private ICurrentUser _currentUser; |
|||
private readonly CmsKitTestData _cmsKitTestData; |
|||
|
|||
public TagAdminAppService_Tests() |
|||
{ |
|||
_tagAdminAppService = GetRequiredService<ITagAdminAppService>(); |
|||
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); |
|||
} |
|||
|
|||
protected override void AfterAddApplication(IServiceCollection services) |
|||
{ |
|||
_currentUser = Substitute.For<ICurrentUser>(); |
|||
services.AddSingleton(_currentUser); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldCreateProperly() |
|||
{ |
|||
var list = await _tagAdminAppService.CreateAsync(new TagCreateDto |
|||
{ |
|||
EntityType = "any_new_type", |
|||
Name = "1", |
|||
}); |
|||
|
|||
list.Id.ShouldNotBe(Guid.Empty); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldThrowException_WhenTagAlreadyExist() |
|||
{ |
|||
await Should.ThrowAsync<TagAlreadyExistException>(async () => await _tagAdminAppService.CreateAsync(new TagCreateDto |
|||
{ |
|||
EntityType = _cmsKitTestData.Content_1_EntityType, |
|||
Name = _cmsKitTestData.Content_1_Tags[0], |
|||
})); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue