Browse Source

CmsKit - BlogPosts Domain tests

pull/7596/head
enisn 6 years ago
parent
commit
69c42890a4
  1. 16
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Blogs/BlogPostAdminAppService_Tests.cs
  2. 75
      modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Blogs/BlogPostManager_Tests.cs
  3. 39
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs
  4. 14
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs

16
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Blogs/BlogPostAdminAppService_Tests.cs

@ -0,0 +1,16 @@
using System;
using Shouldly;
using Volo.CmsKit.Admin.Blogs;
namespace Volo.CmsKit.Blogs
{
public class BlogPostAdminAppService_Tests : CmsKitApplicationTestBase
{
private readonly IBlogPostAdminAppService blogPostAdminAppService;
public BlogPostAdminAppService_Tests()
{
blogPostAdminAppService = GetRequiredService<IBlogPostAdminAppService>();
}
}
}

75
modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Blogs/BlogPostManager_Tests.cs

@ -0,0 +1,75 @@
using Shouldly;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Guids;
using Volo.CmsKit.Tags;
using Xunit;
namespace Volo.CmsKit.Blogs
{
public class BlogPostManager_Tests : CmsKitDomainTestBase
{
private readonly IBlogPostManager blogPostManager;
private readonly IGuidGenerator guidGenerator;
private readonly IBlogPostRepository blogPostRepository;
private readonly CmsKitTestData cmsKitTestData;
public BlogPostManager_Tests(
IBlogPostManager blogPostManager,
IGuidGenerator guidGenerator,
IBlogPostRepository blogPostRepository,
CmsKitTestData cmsKitTestData)
{
this.blogPostManager = blogPostManager;
this.guidGenerator = guidGenerator;
this.blogPostRepository = blogPostRepository;
this.cmsKitTestData = cmsKitTestData;
}
[Fact]
public async Task CreateAsync_ShouldWorkProperly_WithCorrectData()
{
var title = "New blog post";
var urlSlug = "new-blog-post";
var created = await blogPostManager.CreateAsync(
new BlogPost(guidGenerator.Create(), title, urlSlug));
created.Id.ShouldNotBe(Guid.Empty);
var blogPost = await blogPostRepository.GetAsync(created.Id);
blogPost.Title.ShouldBe(title);
blogPost.UrlSlug.ShouldBe(urlSlug);
}
[Fact]
public async Task CreateAsync_ShouldThrowException_WhenUrlSlugAlreadyExists()
{
var blogPost = new BlogPost(guidGenerator.Create(), "Any New Title", cmsKitTestData.Blog_1_UrlSlug);
await Should.ThrowAsync<BlogPostUrlSlugAlreadyExistException>(async () =>
await blogPostManager.CreateAsync(blogPost));
}
[Fact]
public async Task UpdateAsync_ShoudlWorkProperly_WithCorrectData()
{
var newTitle = "Yet Another Post";
var newUrlSlug = "yet-another-post";
var blogPost = await blogPostRepository.GetAsync(cmsKitTestData.Blog_1_Id);
blogPost.SetTitle(newTitle);
blogPost.SetUrlSlug(newUrlSlug);
await blogPostManager.UpdateAsync(blogPost);
var updated = await blogPostRepository.GetAsync(cmsKitTestData.Blog_1_Id);
updated.Title.ShouldBe(newTitle);
updated.UrlSlug.ShouldBe(newUrlSlug);
}
}
}

39
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs

@ -6,6 +6,7 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
using Volo.Abp.Users; using Volo.Abp.Users;
using Volo.CmsKit.Blogs;
using Volo.CmsKit.Comments; using Volo.CmsKit.Comments;
using Volo.CmsKit.Contents; using Volo.CmsKit.Contents;
using Volo.CmsKit.Pages; using Volo.CmsKit.Pages;
@ -29,6 +30,9 @@ namespace Volo.CmsKit
private readonly IEntityTagRepository _entityTagRepository; private readonly IEntityTagRepository _entityTagRepository;
private readonly ITagManager _tagManager; private readonly ITagManager _tagManager;
private readonly IPageRepository _pageRepository; private readonly IPageRepository _pageRepository;
private readonly IBlogRepository _blogRepository;
private readonly IBlogPostRepository _blogPostRepository;
public CmsKitDataSeedContributor( public CmsKitDataSeedContributor(
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
ICmsUserRepository cmsUserRepository, ICmsUserRepository cmsUserRepository,
@ -36,11 +40,13 @@ namespace Volo.CmsKit
ICommentRepository commentRepository, ICommentRepository commentRepository,
ReactionManager reactionManager, ReactionManager reactionManager,
IRatingRepository ratingRepository, IRatingRepository ratingRepository,
ICurrentTenant currentTenant, ICurrentTenant currentTenant,
IContentRepository contentRepository, IContentRepository contentRepository,
ITagManager tagManager, ITagManager tagManager,
IEntityTagRepository entityTagRepository, IEntityTagRepository entityTagRepository,
IPageRepository pageRepository) IPageRepository pageRepository,
IBlogRepository blogRepository,
IBlogPostRepository blogPostRepository)
{ {
_guidGenerator = guidGenerator; _guidGenerator = guidGenerator;
_cmsUserRepository = cmsUserRepository; _cmsUserRepository = cmsUserRepository;
@ -53,6 +59,8 @@ namespace Volo.CmsKit
_tagManager = tagManager; _tagManager = tagManager;
_entityTagRepository = entityTagRepository; _entityTagRepository = entityTagRepository;
_pageRepository = pageRepository; _pageRepository = pageRepository;
_blogRepository = blogRepository;
_blogPostRepository = blogPostRepository;
} }
public async Task SeedAsync(DataSeedContext context) public async Task SeedAsync(DataSeedContext context)
@ -72,6 +80,8 @@ namespace Volo.CmsKit
await SeedTagsAsync(); await SeedTagsAsync();
await SeedPagesAsync(); await SeedPagesAsync();
await SeedBlogsAsync();
} }
} }
@ -208,14 +218,14 @@ namespace Volo.CmsKit
_cmsKitTestData.Content_1_EntityId, _cmsKitTestData.Content_1_EntityId,
_cmsKitTestData.Content_1 _cmsKitTestData.Content_1
); );
var content2 = new Content( var content2 = new Content(
_cmsKitTestData.Content_2_Id, _cmsKitTestData.Content_2_Id,
_cmsKitTestData.Content_2_EntityType, _cmsKitTestData.Content_2_EntityType,
_cmsKitTestData.Content_2_EntityId, _cmsKitTestData.Content_2_EntityId,
_cmsKitTestData.Content_2 _cmsKitTestData.Content_2
); );
var content3 = new Content( var content3 = new Content(
Guid.NewGuid(), Guid.NewGuid(),
"deleted_entity_type", "deleted_entity_type",
@ -239,11 +249,11 @@ namespace Volo.CmsKit
await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_EntityId)); await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_EntityId));
} }
foreach (var tag in _cmsKitTestData.Content_2_Tags) foreach (var tag in _cmsKitTestData.Content_2_Tags)
{ {
var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, tag); var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, tag);
await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_EntityId)); await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_EntityId));
} }
} }
@ -252,15 +262,24 @@ namespace Volo.CmsKit
{ {
var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Url, _cmsKitTestData.Page_1_Description); var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Url, _cmsKitTestData.Page_1_Description);
var page1Content = new Content(_guidGenerator.Create(), nameof(Page), page1.Id.ToString(), _cmsKitTestData.Page_1_Content); var page1Content = new Content(_guidGenerator.Create(), nameof(Page), page1.Id.ToString(), _cmsKitTestData.Page_1_Content);
await _pageRepository.InsertAsync(page1); await _pageRepository.InsertAsync(page1);
await _contentRepository.InsertAsync(page1Content); await _contentRepository.InsertAsync(page1Content);
var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Url, _cmsKitTestData.Page_2_Description); var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Url, _cmsKitTestData.Page_2_Description);
var page2Content = new Content(_guidGenerator.Create(), nameof(Page), page2.Id.ToString(), _cmsKitTestData.Page_2_Content); var page2Content = new Content(_guidGenerator.Create(), nameof(Page), page2.Id.ToString(), _cmsKitTestData.Page_2_Content);
await _pageRepository.InsertAsync(page2); await _pageRepository.InsertAsync(page2);
await _contentRepository.InsertAsync(page2Content); await _contentRepository.InsertAsync(page2Content);
} }
private async Task SeedBlogsAsync()
{
var blog = await _blogRepository.InsertAsync(new Blog(_cmsKitTestData.BlogName));
await _blogPostRepository.InsertAsync(new BlogPost(blog.Id, _cmsKitTestData.Blog_1_Title, _cmsKitTestData.Blog_1_UrlSlug, "Short desc 1"));
await _blogPostRepository.InsertAsync(new BlogPost(blog.Id, _cmsKitTestData.Blog_2_Title, _cmsKitTestData.Blog_2_UrlSlug, "Short desc 2"));
}
} }
} }

14
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs

@ -59,5 +59,19 @@ namespace Volo.CmsKit
public Guid Page_2_Id { get; } = Guid.NewGuid(); public Guid Page_2_Id { get; } = Guid.NewGuid();
public string Page_2_Content => Content_2; public string Page_2_Content => Content_2;
public string BlogName => "Cms Blog";
public Guid Blog_1_Id { get; } = Guid.NewGuid();
public string Blog_1_Title => "How to install CmsKit?";
public string Blog_1_UrlSlug => "how-to-install-cms-kit";
public Guid Blog_2_Id { get; } = Guid.NewGuid();
public string Blog_2_Title => "How to use CmsKit?";
public string Blog_2_UrlSlug => "how-to-use-cms-kit?";
} }
} }

Loading…
Cancel
Save