diff --git a/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs new file mode 100644 index 0000000000..b7d2d4d80d --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.Application.Tests/Contents/ContentAdminAppService_Tests.cs @@ -0,0 +1,88 @@ +using Microsoft.Extensions.DependencyInjection; +using NSubstitute; +using Shouldly; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Domain.Entities; +using Volo.Abp.Users; +using Volo.CmsKit.Admin.Contents; +using Xunit; + +namespace Volo.CmsKit.Contents +{ + public class ContentAdminAppService_Tests : CmsKitApplicationTestBase + { + private ICurrentUser _currentUser; + private readonly CmsKitTestData _data; + private readonly IContentAdminAppService _service; + public ContentAdminAppService_Tests() + { + _data = GetRequiredService(); + _service = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + _currentUser = Substitute.For(); + services.AddSingleton(_currentUser); + } + + [Fact] + public async Task ShouldGetListAsync() + { + var result = await _service.GetListAsync(new ContentGetListInput()); + + result.ShouldNotBeNull(); + result.Items.ShouldNotBeEmpty(); + result.Items.Count.ShouldBe(4); + } + + [Fact] + public async Task ShouldGetAsync() + { + var result = await _service.GetAsync(_data.Content_1_Id); + + result.ShouldNotBeNull(); + } + + [Fact] + public async Task ShouldCreateAsync() + { + var created = await _service.CreateAsync(new ContentCreateDto + { + EntityId = "test_case_id", + EntityType = "test_case_type", + Value = "Some long content" + }); + + created.ShouldNotBeNull(); + } + + [Fact] + public async Task ShouldUpdateAsync() + { + string newValue = "Newly created fresh value"; + var updateDto = new ContentUpdateDto + { + Value = newValue + }; + + await _service.UpdateAsync(_data.Content_1_Id, updateDto); + + var content = await _service.GetAsync(_data.Content_1_Id); + content.ShouldNotBeNull(); + content.Value.ShouldBe(newValue); + } + + [Fact] + public async Task ShouldDeleteAsync() + { + await _service.DeleteAsync(_data.Content_2_Id); + + await Should.ThrowAsync(async () => await _service.GetAsync(_data.Content_2_Id)); + } + } +} diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index b0f820a4f2..442a86c0b9 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; @@ -202,16 +203,16 @@ namespace Volo.CmsKit private async Task SeedContentsAsync() { var content1 = new Content( - _guidGenerator.Create(), - _cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_Id, + _cmsKitTestData.Content_1_EntityType, + _cmsKitTestData.Content_1_EntityId, _cmsKitTestData.Content_1 ); var content2 = new Content( - _guidGenerator.Create(), - _cmsKitTestData.Content_2_EntityType, _cmsKitTestData.Content_2_Id, + _cmsKitTestData.Content_2_EntityType, + _cmsKitTestData.Content_2_EntityId, _cmsKitTestData.Content_2 ); @@ -225,14 +226,14 @@ namespace Volo.CmsKit { var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_1_EntityType, tag); - await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_Id)); + await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_EntityId)); } foreach (var tag in _cmsKitTestData.Content_2_Tags) { var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, tag); - await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_Id)); + await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_EntityId)); } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs index 11aa185ddd..7433759f40 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs @@ -21,39 +21,43 @@ namespace Volo.CmsKit public string EntityId2 { get; } = "2"; public string Content_1_EntityType { get; } = "Lyrics"; - + public string Content_1 { get; } = "First things first\nI'ma say all the words inside my head\nI'm fired up and tired of the way that things have been, oh-ooh\nThe way that things have been, oh-ooh"; - public string Content_1_Id { get; } = "1"; + public Guid Content_1_Id { get; } = Guid.NewGuid(); + + public string Content_1_EntityId { get; } = "1"; + + public string[] Content_1_Tags => new string[] { "Imagine Dragons", "Music" }; - public string[] Content_1_Tags => new string[] {"Imagine Dragons", "Music"}; - public string Content_2_EntityType { get; } = "LyricsAlso"; - + public string Content_2 { get; } = "Second thing second\nDon't you tell me what you think that I could be\nI'm the one at the sail, I'm the master of my sea, oh-ooh\nThe master of my sea, oh-ooh"; - - public string Content_2_Id { get; } = "2"; - - public string[] Content_2_Tags => new string[] {"Imagine Dragons", "Music", "Most Loved Part"}; + + public Guid Content_2_Id { get; } = Guid.NewGuid(); + + public string Content_2_EntityId { get; } = "2"; + + public string[] Content_2_Tags => new string[] { "Imagine Dragons", "Music", "Most Loved Part" }; public string Page_1_Title { get; } = "Imagine Dragons - Believer Lyrics"; public string Page_1_Url { get; } = "imagine-dragons-believer-lyrics"; - + public string Page_1_Description { get; } = "You can get the lyrics of the music."; - + public Guid Page_1_Id { get; } = Guid.NewGuid(); public string Page_1_Content => Content_1; - + public string Page_2_Title { get; } = "Imagine Dragons - Believer Lyrics (Page 2)"; public string Page_2_Url { get; } = "imagine-dragons-believer-lyrics-2"; - + public string Page_2_Description { get; } = "You can get the lyrics of the music."; - + public Guid Page_2_Id { get; } = Guid.NewGuid(); - + public string Page_2_Content => Content_2; } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs index c92383694e..c5b166551e 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs @@ -47,7 +47,7 @@ namespace Volo.CmsKit.Contents public async Task ShouldFindAsync() { var content = - await _contentRepository.FindAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_Id); + await _contentRepository.FindAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityId); content.ShouldNotBeNull(); }