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.Linq;
using System.Threading.Tasks;
using Shouldly;
using Volo.Blogging.Blogs;
using Volo.Blogging.Comments;
using Volo.Blogging.Comments.Dtos;
using Volo.Blogging.Posts;
using Xunit;
@ -12,25 +15,29 @@ namespace Volo.Blogging
private readonly ICommentAppService _commentAppService;
private readonly ICommentRepository _commentRepository;
private readonly IPostRepository _postRepository;
private readonly IBlogRepository _blogRepository;
public CommentAppService_Tests()
{
_commentAppService = GetRequiredService<ICommentAppService>(); ;
_commentRepository = GetRequiredService<ICommentRepository>(); ;
_postRepository = GetRequiredService<IPostRepository>(); ;
_commentAppService = GetRequiredService<ICommentAppService>();
_commentRepository = GetRequiredService<ICommentRepository>();
_postRepository = GetRequiredService<IPostRepository>();
_blogRepository = GetRequiredService<IBlogRepository>();
}
[Fact]
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 comment1 = await _commentRepository.InsertAsync(new Comment(Guid.NewGuid(), post.Id, Guid.Empty, "qweasd"));
var comment2 = await _commentRepository.InsertAsync(new Comment(Guid.NewGuid(), post.Id, comment1.Id, "qweasd"));
var blog = (await _blogRepository.GetListAsync()).FirstOrDefault();
var post = (await _postRepository.GetListAsync()).FirstOrDefault();
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);
}
}
}

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

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.Threading;
using Volo.Blogging.Blogs;
using Volo.Blogging.Posts;
namespace Volo.Blogging
{
@ -9,13 +11,16 @@ namespace Volo.Blogging
{
private readonly BloggingTestData _testData;
private readonly IBlogRepository _blogRepository;
private readonly IPostRepository _postRepository;
public BloggingTestDataBuilder(
BloggingTestData testData,
IBlogRepository blogRepository)
IBlogRepository blogRepository,
IPostRepository postRepository)
{
_testData = testData;
_blogRepository = blogRepository;
_postRepository = postRepository;
}
public void Build()
@ -26,6 +31,8 @@ namespace Volo.Blogging
public async Task BuildAsync()
{
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