From 022c1bc3d0c5e1014f719a92a801c7220d44fb45 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 5 Jun 2020 14:55:50 +0300 Subject: [PATCH] blog admin separation: fix unit tests & rename app service methods --- .../Admin/Blogs/IBlogManagementAppService.cs | 6 ++-- .../FodyWeavers.xsd | 30 +++++++++++++++++++ .../Admin/Blogs/BlogManagementAppService.cs | 6 ++-- .../Admin/BlogManagementController.cs | 12 ++++---- .../Blogging/Admin/Blogs/Create.cshtml.cs | 2 +- .../Pages/Blogging/Admin/Blogs/Edit.cshtml.cs | 2 +- .../Volo.Blogging.Application.Tests.csproj | 1 + .../Volo/Blogging/BlogAppService_Tests.cs | 18 +++++------ .../Blogging/BloggingApplicationTestModule.cs | 2 ++ 9 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 modules/blogging/src/Volo.Blogging.Admin.Application/FodyWeavers.xsd diff --git a/modules/blogging/src/Volo.Blogging.Admin.Application.Contracts/Volo/Blogging/Admin/Blogs/IBlogManagementAppService.cs b/modules/blogging/src/Volo.Blogging.Admin.Application.Contracts/Volo/Blogging/Admin/Blogs/IBlogManagementAppService.cs index 097945418f..3554413d5f 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.Application.Contracts/Volo/Blogging/Admin/Blogs/IBlogManagementAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Admin.Application.Contracts/Volo/Blogging/Admin/Blogs/IBlogManagementAppService.cs @@ -11,10 +11,10 @@ namespace Volo.Blogging.Admin.Blogs Task GetAsync(Guid id); - Task Create(CreateBlogDto input); + Task CreateAsync(CreateBlogDto input); - Task Update(Guid id, UpdateBlogDto input); + Task UpdateAsync(Guid id, UpdateBlogDto input); - Task Delete(Guid id); + Task DeleteAsync(Guid id); } } diff --git a/modules/blogging/src/Volo.Blogging.Admin.Application/FodyWeavers.xsd b/modules/blogging/src/Volo.Blogging.Admin.Application/FodyWeavers.xsd new file mode 100644 index 0000000000..3f3946e282 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Admin.Application/FodyWeavers.xsd @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + 'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed. + + + + + A comma-separated list of error codes that can be safely ignored in assembly verification. + + + + + 'false' to turn off automatic generation of the XML Schema file. + + + + + \ No newline at end of file diff --git a/modules/blogging/src/Volo.Blogging.Admin.Application/Volo/Blogging/Admin/Blogs/BlogManagementAppService.cs b/modules/blogging/src/Volo.Blogging.Admin.Application/Volo/Blogging/Admin/Blogs/BlogManagementAppService.cs index 1f43085461..1df6f52c9b 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.Application/Volo/Blogging/Admin/Blogs/BlogManagementAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Admin.Application/Volo/Blogging/Admin/Blogs/BlogManagementAppService.cs @@ -33,7 +33,7 @@ namespace Volo.Blogging.Admin.Blogs } [Authorize(BloggingAdminPermissions.Blogs.Create)] - public async Task Create(CreateBlogDto input) + public async Task CreateAsync(CreateBlogDto input) { var newBlog = await _blogRepository.InsertAsync(new Blog(GuidGenerator.Create(), input.Name, input.ShortName) { @@ -44,7 +44,7 @@ namespace Volo.Blogging.Admin.Blogs } [Authorize(BloggingAdminPermissions.Blogs.Update)] - public async Task Update(Guid id, UpdateBlogDto input) + public async Task UpdateAsync(Guid id, UpdateBlogDto input) { var blog = await _blogRepository.GetAsync(id); @@ -56,7 +56,7 @@ namespace Volo.Blogging.Admin.Blogs } [Authorize(BloggingAdminPermissions.Blogs.Delete)] - public async Task Delete(Guid id) + public async Task DeleteAsync(Guid id) { await _blogRepository.DeleteAsync(id); } diff --git a/modules/blogging/src/Volo.Blogging.Admin.HttpApi/Volo/Blogging/Admin/BlogManagementController.cs b/modules/blogging/src/Volo.Blogging.Admin.HttpApi/Volo/Blogging/Admin/BlogManagementController.cs index c59bad9baf..782a05a42e 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.HttpApi/Volo/Blogging/Admin/BlogManagementController.cs +++ b/modules/blogging/src/Volo.Blogging.Admin.HttpApi/Volo/Blogging/Admin/BlogManagementController.cs @@ -34,23 +34,23 @@ namespace Volo.Blogging.Admin } [HttpPost] - public async Task Create(CreateBlogDto input) + public async Task CreateAsync(CreateBlogDto input) { - return await _blogManagementAppService.Create(input); + return await _blogManagementAppService.CreateAsync(input); } [HttpPut] [Route("{id}")] - public async Task Update(Guid id, UpdateBlogDto input) + public async Task UpdateAsync(Guid id, UpdateBlogDto input) { - return await _blogManagementAppService.Update(id, input); + return await _blogManagementAppService.UpdateAsync(id, input); } [HttpDelete] [Route("{id}")] - public async Task Delete(Guid id) + public async Task DeleteAsync(Guid id) { - await _blogManagementAppService.Delete(id); + await _blogManagementAppService.DeleteAsync(id); } } } diff --git a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs index a24d94932e..b2d89fbd55 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Create.cshtml.cs @@ -35,7 +35,7 @@ namespace Volo.Blogging.Admin.Pages.Blogging.Admin.Blogs { var blogDto = ObjectMapper.Map(Blog); - await _blogAppService.Create(blogDto); + await _blogAppService.CreateAsync(blogDto); return NoContent(); } diff --git a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs index 21934d02b9..536810e015 100644 --- a/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Admin.Web/Pages/Blogging/Admin/Blogs/Edit.cshtml.cs @@ -41,7 +41,7 @@ namespace Volo.Blogging.Admin.Pages.Blogging.Admin.Blogs public virtual async Task OnPostAsync() { - await _blogAppService.Update(Blog.Id, new UpdateBlogDto() + await _blogAppService.UpdateAsync(Blog.Id, new UpdateBlogDto() { Name = Blog.Name, ShortName = Blog.ShortName, diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo.Blogging.Application.Tests.csproj b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo.Blogging.Application.Tests.csproj index e41384500b..2bc4009d26 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo.Blogging.Application.Tests.csproj +++ b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo.Blogging.Application.Tests.csproj @@ -11,6 +11,7 @@ + diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BlogAppService_Tests.cs b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BlogAppService_Tests.cs index 7c67db978b..8726330b39 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BlogAppService_Tests.cs +++ b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BlogAppService_Tests.cs @@ -1,13 +1,9 @@ -using System; -using System.Linq; +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.Pages.Blogs.Shared.Helpers; -using Volo.Blogging.Posts; +using Volo.Blogging.Admin.Blogs; using Xunit; namespace Volo.Blogging @@ -15,11 +11,13 @@ namespace Volo.Blogging public class BlogAppService_Tests : BloggingApplicationTestBase { private readonly IBlogAppService _blogAppService; + private readonly IBlogManagementAppService _blogManagementAppService; private readonly IBlogRepository _blogRepository; public BlogAppService_Tests() { _blogAppService = GetRequiredService(); + _blogManagementAppService = GetRequiredService(); _blogRepository = GetRequiredService(); } @@ -68,7 +66,7 @@ namespace Volo.Blogging var shortName = "test shortName"; var description = "test description"; - var blogDto = await _blogAppService.Create(new CreateBlogDto() { Name = name, ShortName = name, Description = description }); + var blogDto = await _blogManagementAppService.CreateAsync(new CreateBlogDto() { Name = name, ShortName = name, Description = description }); UsingDbContext(context => { @@ -85,9 +83,9 @@ namespace Volo.Blogging { var newDescription = "new description"; - var oldBlog = (await _blogRepository.GetListAsync()).FirstOrDefault(); ; + var oldBlog = (await _blogManagementAppService.GetListAsync()).Items.FirstOrDefault(); ; - await _blogAppService.Update(oldBlog.Id, new UpdateBlogDto() + await _blogManagementAppService.UpdateAsync(oldBlog.Id, new UpdateBlogDto() { Description = newDescription, Name = oldBlog.Name, ShortName = oldBlog.ShortName }); UsingDbContext(context => @@ -102,7 +100,7 @@ namespace Volo.Blogging { var blog = (await _blogRepository.GetListAsync()).First(); - await _blogAppService.Delete(blog.Id); + await _blogManagementAppService.DeleteAsync(blog.Id); } } } diff --git a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BloggingApplicationTestModule.cs b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BloggingApplicationTestModule.cs index ab2cbd12dd..fb3934ee5f 100644 --- a/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BloggingApplicationTestModule.cs +++ b/modules/blogging/test/Volo.Blogging.Application.Tests/Volo/Blogging/BloggingApplicationTestModule.cs @@ -1,11 +1,13 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Modularity; +using Volo.Blogging.Admin; using Volo.Blogging.EntityFrameworkCore; namespace Volo.Blogging { [DependsOn( typeof(BloggingApplicationModule), + typeof(BloggingAdminApplicationModule), typeof(BloggingEntityFrameworkCoreTestModule), typeof(BloggingTestBaseModule))] public class BloggingApplicationTestModule : AbpModule