mirror of https://github.com/abpframework/abp.git
7 changed files with 262 additions and 10 deletions
@ -0,0 +1,88 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Shouldly; |
||||
|
using Volo.Blogging.Blogs; |
||||
|
using Volo.Blogging.Blogs.Dtos; |
||||
|
using Volo.Blogging.Comments; |
||||
|
using Volo.Blogging.Comments.Dtos; |
||||
|
using Volo.Blogging.Posts; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Blogging |
||||
|
{ |
||||
|
public class BlogAppService_Tests : BloggingApplicationTestBase |
||||
|
{ |
||||
|
private readonly IBlogAppService _blogAppService; |
||||
|
private readonly IBlogRepository _blogRepository; |
||||
|
|
||||
|
public BlogAppService_Tests() |
||||
|
{ |
||||
|
_blogAppService = GetRequiredService<IBlogAppService>(); |
||||
|
_blogRepository = GetRequiredService<IBlogRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Get_List_Of_Blogs() |
||||
|
{ |
||||
|
var blogs = await _blogAppService.GetListAsync(); |
||||
|
|
||||
|
blogs.Items.Count.ShouldBeGreaterThan(0); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Get_Blog_By_Shortname() |
||||
|
{ |
||||
|
var targetBlog = (await _blogAppService.GetListAsync()).Items.First(); |
||||
|
|
||||
|
var blog = await _blogAppService.GetByShortNameAsync(targetBlog.ShortName); |
||||
|
|
||||
|
blog.ShouldNotBeNull(); |
||||
|
blog.Name.ShouldBe(targetBlog.Name); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Create_A_Blog() |
||||
|
{ |
||||
|
var name = "test name"; |
||||
|
var shortName = "test shortName"; |
||||
|
var description = "test description"; |
||||
|
|
||||
|
var blogDto = await _blogAppService.Create(new CreateBlogDto() { Name = name, ShortName = name, Description = description }); |
||||
|
|
||||
|
UsingDbContext(context => |
||||
|
{ |
||||
|
var blog = context.Blogs.FirstOrDefault(q => q.Id == blogDto.Id); |
||||
|
blog.ShouldNotBeNull(); |
||||
|
blog.Name.ShouldBe(blogDto.Name); |
||||
|
blog.ShortName.ShouldBe(blogDto.ShortName); |
||||
|
blog.Description.ShouldBe(blogDto.Description); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Update_A_Blog() |
||||
|
{ |
||||
|
var newDescription = "new description"; |
||||
|
|
||||
|
var oldBlog = (await _blogRepository.GetListAsync()).FirstOrDefault(); ; |
||||
|
|
||||
|
await _blogAppService.Update(oldBlog.Id, new UpdateBlogDto() |
||||
|
{ Description = newDescription, Name = oldBlog.Name, ShortName = oldBlog.ShortName }); |
||||
|
|
||||
|
UsingDbContext(context => |
||||
|
{ |
||||
|
var blog = context.Blogs.FirstOrDefault(q => q.Id == oldBlog.Id); |
||||
|
blog.Description.ShouldBe(newDescription); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Delete_A_Blog() |
||||
|
{ |
||||
|
var blog = (await _blogRepository.GetListAsync()).First(); |
||||
|
|
||||
|
await _blogAppService.Delete(blog.Id); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,85 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Shouldly; |
||||
|
using Volo.Blogging.Blogs; |
||||
|
using Volo.Blogging.Blogs.Dtos; |
||||
|
using Volo.Blogging.Comments; |
||||
|
using Volo.Blogging.Comments.Dtos; |
||||
|
using Volo.Blogging.Posts; |
||||
|
using Volo.Blogging.Tagging; |
||||
|
using Volo.Blogging.Tagging.Dtos; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Blogging |
||||
|
{ |
||||
|
public class TagAppService_Tests : BloggingApplicationTestBase |
||||
|
{ |
||||
|
private readonly ITagAppService _tagAppService; |
||||
|
private readonly ITagRepository _tagRepository; |
||||
|
|
||||
|
public TagAppService_Tests() |
||||
|
{ |
||||
|
_tagAppService = GetRequiredService<ITagAppService>(); |
||||
|
_tagRepository = GetRequiredService<ITagRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Get_List_Of_Tags() |
||||
|
{ |
||||
|
var tags = await _tagAppService.GetListAsync(); |
||||
|
|
||||
|
tags.Count.ShouldBeGreaterThan(0); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Get_Popular_Tags() |
||||
|
{ |
||||
|
var tags = await _tagAppService.GetPopularTags(new GetPopularTagsInput() { ResultCount = 5, MinimumPostCount = 0 }); |
||||
|
|
||||
|
tags.Count.ShouldBeGreaterThan(0); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Create_A_Tag() |
||||
|
{ |
||||
|
var name = "test name"; |
||||
|
var description = "test description"; |
||||
|
|
||||
|
var tagDto = await _tagAppService.CreateAsync(new CreateTagDto() { Name = name, Description = description }); |
||||
|
|
||||
|
UsingDbContext(context => |
||||
|
{ |
||||
|
var tag = context.Tags.FirstOrDefault(q => q.Id == tagDto.Id); |
||||
|
tag.ShouldNotBeNull(); |
||||
|
tag.Name.ShouldBe(tagDto.Name); |
||||
|
tag.Description.ShouldBe(tagDto.Description); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Update_A_Tag() |
||||
|
{ |
||||
|
var newDescription = "new description"; |
||||
|
|
||||
|
var oldTag = (await _tagRepository.GetListAsync()).FirstOrDefault(); ; |
||||
|
|
||||
|
await _tagAppService.UpdateAsync(oldTag.Id, new UpdateTagDto() |
||||
|
{ Description = newDescription, Name = oldTag.Name}); |
||||
|
|
||||
|
UsingDbContext(context => |
||||
|
{ |
||||
|
var tag = context.Tags.FirstOrDefault(q => q.Id == oldTag.Id); |
||||
|
tag.Description.ShouldBe(newDescription); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Delete_A_Tag() |
||||
|
{ |
||||
|
var tag = (await _tagRepository.GetListAsync()).First(); |
||||
|
|
||||
|
await _tagAppService.DeleteAsync(tag.Id); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue