diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAppService_Tests.cs new file mode 100644 index 0000000000..35b46b5a04 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAppService_Tests.cs @@ -0,0 +1,78 @@ +using Microsoft.Extensions.DependencyInjection; +using NSubstitute; +using Shouldly; +using System.Threading.Tasks; +using Volo.Abp.Clients; +using Volo.Abp.Users; +using Volo.Abp.Validation; +using Volo.CmsKit.Public.Tags; +using Xunit; + +namespace Volo.CmsKit.Tags +{ + public class TagAppService_Tests : CmsKitApplicationTestBase + { + private readonly ITagAppService _tagAppService; + private ICurrentUser _currentUser; + private readonly CmsKitTestData _cmsKitTestData; + + public TagAppService_Tests() + { + _tagAppService = GetRequiredService(); + _cmsKitTestData = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + _currentUser = Substitute.For(); + services.AddSingleton(_currentUser); + } + + [Fact] + public async Task GetAllRelatedTagsAsync() + { + var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput + { + EntityType = _cmsKitTestData.Content_1_EntityType, + EntityId = _cmsKitTestData.EntityId1 + }); + + list.ShouldNotBeEmpty(); + list.Count.ShouldBe(2); + } + + [Fact] + public async Task ShouldntGet_GetAllRelatedTagsAsync() + { + var list = await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput + { + EntityType = "any_other_type", + EntityId = "1" + }); + + list.ShouldBeEmpty(); + } + + [Fact] + public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityType() + { + await Assert.ThrowsAsync(async () => + await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput + { + EntityType = null, + EntityId = _cmsKitTestData.EntityId1 + })); + } + + [Fact] + public async Task GetRelatedTagsAsync_ShouldThrowValidationException_WithoutEntityId() + { + await Assert.ThrowsAsync(async () => + await _tagAppService.GetAllRelatedTagsAsync(new GetRelatedTagsInput + { + EntityType = null, + EntityId = _cmsKitTestData.EntityId1 + })); + } + } +}