mirror of https://github.com/abpframework/abp.git
4 changed files with 134 additions and 10 deletions
@ -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>(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue