From 5a882a420574cb3b199acf022deb6099fc62bc77 Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Fri, 6 Jul 2018 10:43:24 +0300 Subject: [PATCH] Fix tests for blogging module --- .../Volo/Blogging/PostAppService_Tests.cs | 34 +++++++++++-------- .../Volo/Blogging/BloggingTestBase.cs | 5 +++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs index 2e81e45b2a..799b8c12c5 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs +++ b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/PostAppService_Tests.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System.Linq; using System.Threading.Tasks; using Shouldly; using Volo.Blogging.Blogs; @@ -27,23 +24,28 @@ namespace Volo.Blogging public async Task Should_Create_A_Post() { var blogId = (await _blogRepository.GetListAsync()).First().Id; - var title = "title"; - var content = "content"; + var title = "test title"; + var content = "test content"; - var newPost = await _postAppService.CreateAsync(new CreatePostDto() + var newPostDto = await _postAppService.CreateAsync(new CreatePostDto() { BlogId = blogId, Title = title, - Content = content + Content = content, + Url = title.Replace(" ", "-") }); + newPostDto.Id.ShouldNotBeNull(); + UsingDbContext(context => { var post = context.Posts.FirstOrDefault(q => q.Title == title); post.ShouldNotBeNull(); - post.Title.ShouldBe(title); - post.Content.ShouldBe(content); + post.Id.ShouldBe(newPostDto.Id); + post.Title.ShouldBe(newPostDto.Title); + post.Content.ShouldBe(newPostDto.Content); post.BlogId.ShouldBe(blogId); + post.Url.ShouldBe(newPostDto.Url); }); } @@ -52,24 +54,25 @@ namespace Volo.Blogging { var blogId = (await _blogRepository.GetListAsync()).First().Id; var title = "title"; - var newTitle = "newtitle"; + var newTitle = "new title"; var content = "content"; var newPost = await _postAppService.CreateAsync(new CreatePostDto() { BlogId = blogId, Title = title, - Content = content + Content = content, + Url = title.Replace(" ", "-") }); await _postAppService.UpdateAsync(newPost.Id, new UpdatePostDto() { BlogId = blogId, Title = newTitle, - Content = content + Content = content, + Url = newTitle.Replace(" ", "-") }); - - + UsingDbContext(context => { var post = context.Posts.FirstOrDefault(q => q.Id == newPost.Id); @@ -77,6 +80,7 @@ namespace Volo.Blogging post.Title.ShouldBe(newTitle); post.Content.ShouldBe(content); post.BlogId.ShouldBe(blogId); + post.Url.ShouldBe(newTitle.Replace(" ", "-")); }); } } diff --git a/modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/BloggingTestBase.cs b/modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/BloggingTestBase.cs index abc5f4153b..69b752a32b 100644 --- a/modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/BloggingTestBase.cs +++ b/modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/BloggingTestBase.cs @@ -12,6 +12,11 @@ namespace Volo.Blogging { protected Guid? CurrentUserId { get; set; } + protected BloggingTestBase() + { + CurrentUserId = Guid.NewGuid(); + } + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) { options.UseAutofac();