Browse Source

Blogging Module: Fixed broken tests

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
a935bc934c
  1. 23
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/CommentAppService_Tests.cs
  2. 30
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs
  3. 11
      modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/BloggingTestDataBuilder.cs

23
modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/CommentAppService_Tests.cs

@ -1,7 +1,10 @@
using System; using System;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Shouldly; using Shouldly;
using Volo.Blogging.Blogs;
using Volo.Blogging.Comments; using Volo.Blogging.Comments;
using Volo.Blogging.Comments.Dtos;
using Volo.Blogging.Posts; using Volo.Blogging.Posts;
using Xunit; using Xunit;
@ -12,25 +15,29 @@ namespace Volo.Blogging
private readonly ICommentAppService _commentAppService; private readonly ICommentAppService _commentAppService;
private readonly ICommentRepository _commentRepository; private readonly ICommentRepository _commentRepository;
private readonly IPostRepository _postRepository; private readonly IPostRepository _postRepository;
private readonly IBlogRepository _blogRepository;
public CommentAppService_Tests() public CommentAppService_Tests()
{ {
_commentAppService = GetRequiredService<ICommentAppService>(); ; _commentAppService = GetRequiredService<ICommentAppService>();
_commentRepository = GetRequiredService<ICommentRepository>(); ; _commentRepository = GetRequiredService<ICommentRepository>();
_postRepository = GetRequiredService<IPostRepository>(); ; _postRepository = GetRequiredService<IPostRepository>();
_blogRepository = GetRequiredService<IBlogRepository>();
} }
[Fact] [Fact]
public async Task Should_Get_List_Of_Comments() public async Task Should_Get_List_Of_Comments()
{ {
var post = await _postRepository.InsertAsync(new Post(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "asd", "asd", "asd")); var blog = (await _blogRepository.GetListAsync()).FirstOrDefault();
var comment1 = await _commentRepository.InsertAsync(new Comment(Guid.NewGuid(), post.Id, Guid.Empty, "qweasd")); var post = (await _postRepository.GetListAsync()).FirstOrDefault();
var comment2 = await _commentRepository.InsertAsync(new Comment(Guid.NewGuid(), post.Id, comment1.Id, "qweasd")); var comment1 = await _commentRepository.InsertAsync(new Comment(Guid.NewGuid(), post.Id, null, "qweasd"));
var comment2 = await _commentRepository.InsertAsync(new Comment(Guid.NewGuid(), post.Id, null, "qweasd"));
var comments = await _commentRepository.GetListOfPostAsync(post.Id); var comments =
await _commentAppService.GetHierarchicalListOfPostAsync(
new GetCommentListOfPostAsync() { PostId = post.Id });
comments.Count.ShouldBe(2); comments.Count.ShouldBe(2);
} }
} }
} }

30
modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs

@ -11,6 +11,7 @@ namespace Volo.Blogging
{ {
private readonly IPostAppService _postAppService; private readonly IPostAppService _postAppService;
private readonly IBlogRepository _blogRepository; private readonly IBlogRepository _blogRepository;
private readonly IPostRepository _postRepository;
private readonly BloggingTestData _testData; private readonly BloggingTestData _testData;
public PostAppService_Tests() public PostAppService_Tests()
@ -18,6 +19,7 @@ namespace Volo.Blogging
_testData = GetRequiredService<BloggingTestData>(); _testData = GetRequiredService<BloggingTestData>();
_postAppService = GetRequiredService<IPostAppService>(); _postAppService = GetRequiredService<IPostAppService>();
_blogRepository = GetRequiredService<IBlogRepository>(); _blogRepository = GetRequiredService<IBlogRepository>();
_postRepository = GetRequiredService<IPostRepository>();
} }
[Fact] [Fact]
@ -26,12 +28,14 @@ namespace Volo.Blogging
var blogId = (await _blogRepository.GetListAsync()).First().Id; var blogId = (await _blogRepository.GetListAsync()).First().Id;
var title = "test title"; var title = "test title";
var content = "test content"; var content = "test content";
var coverImage = "new.jpg";
var newPostDto = await _postAppService.CreateAsync(new CreatePostDto() var newPostDto = await _postAppService.CreateAsync(new CreatePostDto()
{ {
BlogId = blogId, BlogId = blogId,
Title = title, Title = title,
Content = content, Content = content,
CoverImage = coverImage,
Url = title.Replace(" ", "-") Url = title.Replace(" ", "-")
}); });
@ -44,43 +48,35 @@ namespace Volo.Blogging
post.Id.ShouldBe(newPostDto.Id); post.Id.ShouldBe(newPostDto.Id);
post.Title.ShouldBe(newPostDto.Title); post.Title.ShouldBe(newPostDto.Title);
post.Content.ShouldBe(newPostDto.Content); post.Content.ShouldBe(newPostDto.Content);
post.CoverImage.ShouldBe(newPostDto.CoverImage);
post.BlogId.ShouldBe(blogId); post.BlogId.ShouldBe(blogId);
post.Url.ShouldBe(newPostDto.Url); post.Url.ShouldBe(newPostDto.Url);
}); });
} }
[Fact] [Fact]
public async Task Should_Create_And_Update_A_Post() public async Task Should_Update_A_Post()
{ {
var blogId = (await _blogRepository.GetListAsync()).First().Id; var blogId = (await _blogRepository.GetListAsync()).First().Id;
var title = "title";
var newTitle = "new title"; var newTitle = "new title";
var content = "content"; var newContent = "content";
var newPost = await _postAppService.CreateAsync(new CreatePostDto() var oldPost = (await _postRepository.GetListAsync()).FirstOrDefault(); ;
{
BlogId = blogId,
Title = title,
Content = content,
Url = title.Replace(" ", "-")
});
await _postAppService.UpdateAsync(newPost.Id, new UpdatePostDto() await _postAppService.UpdateAsync(oldPost.Id, new UpdatePostDto()
{ {
BlogId = blogId, BlogId = blogId,
Title = newTitle, Title = newTitle,
Content = content, CoverImage = oldPost.CoverImage,
Content = newContent,
Url = newTitle.Replace(" ", "-") Url = newTitle.Replace(" ", "-")
}); });
UsingDbContext(context => UsingDbContext(context =>
{ {
var post = context.Posts.FirstOrDefault(q => q.Id == newPost.Id); var post = context.Posts.FirstOrDefault(q => q.Id == oldPost.Id);
post.ShouldNotBeNull();
post.Title.ShouldBe(newTitle); post.Title.ShouldBe(newTitle);
post.Content.ShouldBe(content); post.Content.ShouldBe(newContent);
post.BlogId.ShouldBe(blogId);
post.Url.ShouldBe(newTitle.Replace(" ", "-"));
}); });
} }
} }

11
modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/BloggingTestDataBuilder.cs

@ -1,7 +1,9 @@
using System.Threading.Tasks; using System;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Threading; using Volo.Abp.Threading;
using Volo.Blogging.Blogs; using Volo.Blogging.Blogs;
using Volo.Blogging.Posts;
namespace Volo.Blogging namespace Volo.Blogging
{ {
@ -9,13 +11,16 @@ namespace Volo.Blogging
{ {
private readonly BloggingTestData _testData; private readonly BloggingTestData _testData;
private readonly IBlogRepository _blogRepository; private readonly IBlogRepository _blogRepository;
private readonly IPostRepository _postRepository;
public BloggingTestDataBuilder( public BloggingTestDataBuilder(
BloggingTestData testData, BloggingTestData testData,
IBlogRepository blogRepository) IBlogRepository blogRepository,
IPostRepository postRepository)
{ {
_testData = testData; _testData = testData;
_blogRepository = blogRepository; _blogRepository = blogRepository;
_postRepository = postRepository;
} }
public void Build() public void Build()
@ -26,6 +31,8 @@ namespace Volo.Blogging
public async Task BuildAsync() public async Task BuildAsync()
{ {
await _blogRepository.InsertAsync(new Blog(_testData.Blog1Id, "The First Blog", "blog-1")); await _blogRepository.InsertAsync(new Blog(_testData.Blog1Id, "The First Blog", "blog-1"));
await _postRepository.InsertAsync(new Post(_testData.Blog1Post1Id, _testData.Blog1Id, Guid.Empty, "title", "coverImage", "url"));
await _postRepository.InsertAsync(new Post(_testData.Blog1Post2Id, _testData.Blog1Id, Guid.Empty, "title", "coverImage", "url"));
} }
} }
} }

Loading…
Cancel
Save