mirror of https://github.com/abpframework/abp.git
committed by
GitHub
39 changed files with 490 additions and 95 deletions
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.CmsKit.Admin.Contents |
|||
{ |
|||
public class ContentDto : EntityDto<Guid> |
|||
{ |
|||
public string Value { get; set; } |
|||
} |
|||
} |
|||
@ -1,7 +1,6 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public class CheckUrlInputDto |
|||
{ |
|||
@ -1,7 +1,6 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public class CreatePageInputDto |
|||
{ |
|||
@ -1,8 +1,6 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public class CreatePageWithContentInputDto |
|||
{ |
|||
@ -1,14 +1,11 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public interface IPageAppService |
|||
public interface IPageAdminAppService |
|||
{ |
|||
Task<PageDto> GetAsync(Guid id); |
|||
|
|||
Task<PageDto> GetByUrlAsync([NotNull] string url); |
|||
|
|||
Task<PageDto> CreatePageAsync(CreatePageInputDto input); |
|||
|
|||
@ -1,7 +1,7 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public class PageDto : EntityDto<Guid> |
|||
{ |
|||
@ -1,8 +1,8 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.CmsKit.Contents; |
|||
using Volo.CmsKit.Admin.Contents; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public class PageWithContentDto : EntityDto<Guid> |
|||
{ |
|||
@ -1,8 +1,6 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public class UpdatePageContentInputDto |
|||
{ |
|||
@ -1,7 +1,6 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
namespace Volo.CmsKit.Admin.Pages |
|||
{ |
|||
public class UpdatePageInputDto |
|||
{ |
|||
@ -1,7 +0,0 @@ |
|||
@using Microsoft.AspNetCore.Mvc.Localization |
|||
@using Volo.CmsKit.Localization |
|||
@model Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.Contents.ContentViewComponent.ContentViewModel |
|||
|
|||
<div> |
|||
@Html.Raw(Model.Rendered) |
|||
</div> |
|||
@ -1,4 +1,4 @@ |
|||
namespace Volo.CmsKit.Contents |
|||
namespace Volo.CmsKit.Public.Contents |
|||
{ |
|||
public class GetContentInput |
|||
{ |
|||
@ -1,6 +1,7 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
namespace Volo.CmsKit.Public.Contents |
|||
{ |
|||
public interface IContentAppService |
|||
{ |
|||
@ -0,0 +1,10 @@ |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.CmsKit.Public.Pages |
|||
{ |
|||
public interface IPageAppService |
|||
{ |
|||
Task<PageDto> GetByUrlAsync([NotNull] string url); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.CmsKit.Public.Pages |
|||
{ |
|||
public class PageDto : EntityDto<Guid> |
|||
{ |
|||
public string Title { get; set; } |
|||
|
|||
public string Url { get; set; } |
|||
|
|||
public string Description { get; set; } |
|||
} |
|||
} |
|||
@ -1,10 +1,7 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Contents; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
namespace Volo.CmsKit.Public.Contents |
|||
{ |
|||
public class ContentAppService : CmsKitAppServiceBase, IContentAppService |
|||
{ |
|||
@ -0,0 +1,22 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Pages; |
|||
|
|||
namespace Volo.CmsKit.Public.Pages |
|||
{ |
|||
public class PageAppService : CmsKitPublicAppServiceBase, IPageAppService |
|||
{ |
|||
protected readonly IPageRepository PageRepository; |
|||
|
|||
public PageAppService(IPageRepository pageRepository) |
|||
{ |
|||
PageRepository = pageRepository; |
|||
} |
|||
|
|||
public virtual async Task<PageDto> GetByUrlAsync(string url) |
|||
{ |
|||
var page = await PageRepository.GetByUrlAsync(url); |
|||
|
|||
return ObjectMapper.Map<Page, PageDto>(page); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.Abp; |
|||
|
|||
namespace Volo.CmsKit.Public.Pages |
|||
{ |
|||
[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)] |
|||
[Area("cms-kit")] |
|||
[Route("api/cms-kit-public/comments")] |
|||
public class PagesPublicController |
|||
{ |
|||
protected readonly IPageAppService PageAppService; |
|||
|
|||
public PagesPublicController(IPageAppService pageAppService) |
|||
{ |
|||
PageAppService = pageAppService; |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("url/{url}")] |
|||
public Task<PageDto> GetByUrlAsync(string url) |
|||
{ |
|||
return PageAppService.GetByUrlAsync(url); |
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +1,8 @@ |
|||
@page "{pageUrl}" |
|||
@using Microsoft.AspNetCore.Mvc.Localization |
|||
@using Volo.CmsKit.Localization |
|||
@using Volo.CmsKit.Web.Pages.CmsKit.Pages |
|||
@using Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.Pages |
|||
@model IndexModel |
|||
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages |
|||
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Pages.IndexModel |
|||
@inject IHtmlLocalizer<CmsKitResource> L |
|||
|
|||
@await Component.InvokeAsync(typeof(DefaultPageViewComponent), |
|||
@ -1,8 +1,9 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using Volo.CmsKit.Pages; |
|||
using Volo.CmsKit.Public.Pages; |
|||
using Volo.CmsKit.Web.Pages; |
|||
|
|||
namespace Volo.CmsKit.Web.Pages.CmsKit.Pages |
|||
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Pages |
|||
{ |
|||
public class IndexModel : CommonPageModel |
|||
{ |
|||
@ -0,0 +1,3 @@ |
|||
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents.ContentViewComponent.ContentViewModel |
|||
|
|||
@Html.Raw(Model.Rendered) |
|||
@ -1,8 +1,8 @@ |
|||
@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap |
|||
|
|||
@using Microsoft.AspNetCore.Mvc.RazorPages |
|||
@using Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.Contents |
|||
@model Volo.CmsKit.Web.Pages.CmsKit.Shared.Components.Pages.PageViewModel |
|||
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Contents |
|||
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages.PageViewModel |
|||
|
|||
<abp-card> |
|||
<abp-card-header> |
|||
@ -0,0 +1,183 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Uow; |
|||
using Volo.CmsKit.Admin.Pages; |
|||
using Volo.CmsKit.Contents; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class PageAdminAppService_Tests : CmsKitApplicationTestBase |
|||
{ |
|||
private readonly CmsKitTestData _data; |
|||
private readonly IPageAdminAppService _pageAdminAppService; |
|||
|
|||
private readonly IPageRepository _pageRepository; |
|||
private readonly IContentRepository _contentRepository; |
|||
|
|||
public PageAdminAppService_Tests() |
|||
{ |
|||
_data = GetRequiredService<CmsKitTestData>(); |
|||
_pageAdminAppService = GetRequiredService<IPageAdminAppService>(); |
|||
_pageRepository = GetRequiredService<IPageRepository>(); |
|||
_contentRepository = GetRequiredService<IContentRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldGetAsync() |
|||
{ |
|||
var page = await _pageAdminAppService.GetAsync(_data.Page_1_Id); |
|||
|
|||
page.Description.ShouldBe(_data.Page_1_Description); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldCreateAsync() |
|||
{ |
|||
var dto = new CreatePageInputDto |
|||
{ |
|||
Title = "test", |
|||
Url = "test-url" |
|||
}; |
|||
|
|||
await Should.NotThrowAsync(async () => await _pageAdminAppService.CreatePageAsync(dto)); |
|||
|
|||
var page = await _pageRepository.GetByUrlAsync(dto.Url); |
|||
|
|||
page.Title.ShouldBe(dto.Title); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotCreateAsync() |
|||
{ |
|||
var dto = new CreatePageInputDto |
|||
{ |
|||
Title = "test", |
|||
Url = _data.Page_1_Url |
|||
}; |
|||
|
|||
await Should.ThrowAsync<Exception>(async () => await _pageAdminAppService.CreatePageAsync(dto)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldCreateWithContentAsync() |
|||
{ |
|||
var dto = new CreatePageWithContentInputDto |
|||
{ |
|||
Title = "test", |
|||
Url = "test-url", |
|||
Content = "my-test-content" |
|||
}; |
|||
|
|||
await Should.NotThrowAsync(async () => await _pageAdminAppService.CreatePageWithContentAsync(dto)); |
|||
|
|||
var page = await _pageRepository.GetByUrlAsync(dto.Url); |
|||
|
|||
var content = await _contentRepository.GetAsync(nameof(Page), page.Id.ToString()); |
|||
|
|||
content.Value.ShouldBe(dto.Content); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotCreateWithContentAsync() |
|||
{ |
|||
var dto = new CreatePageWithContentInputDto |
|||
{ |
|||
Title = "test", |
|||
Url = _data.Page_1_Url, |
|||
Content = "my-test-content" |
|||
}; |
|||
|
|||
await Should.ThrowAsync<Exception>(async () => await _pageAdminAppService.CreatePageWithContentAsync(dto)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldUpdatePageAsync() |
|||
{ |
|||
var dto = new UpdatePageInputDto |
|||
{ |
|||
Title = _data.Page_1_Title + "++", |
|||
Description = "new description", |
|||
Url = _data.Page_1_Url+ "test" |
|||
}; |
|||
|
|||
await Should.NotThrowAsync(async () => await _pageAdminAppService.UpdatePageAsync(_data.Page_1_Id, dto)); |
|||
|
|||
var updatedPage = await _pageRepository.GetAsync(_data.Page_1_Id); |
|||
|
|||
updatedPage.Title.ShouldNotBe(_data.Page_1_Title); |
|||
updatedPage.Title.ShouldBe(dto.Title); |
|||
|
|||
updatedPage.Url.ShouldNotBe(_data.Page_1_Url); |
|||
updatedPage.Url.ShouldBe(dto.Url); |
|||
|
|||
updatedPage.Description.ShouldNotBe(_data.Page_1_Description); |
|||
updatedPage.Description.ShouldBe(dto.Description); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotUpdatePageAsync() |
|||
{ |
|||
var dto = new UpdatePageInputDto |
|||
{ |
|||
Title = _data.Page_1_Title + "++", |
|||
Description = "new description", |
|||
Url = _data.Page_2_Url |
|||
}; |
|||
|
|||
await Should.ThrowAsync<Exception>(async () => await _pageAdminAppService.UpdatePageAsync(_data.Page_1_Id, dto)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldBeExistAsync() |
|||
{ |
|||
var dto = new CheckUrlInputDto |
|||
{ |
|||
Url = _data.Page_1_Url |
|||
}; |
|||
|
|||
var doesExist = await _pageAdminAppService.DoesUrlExistAsync(dto); |
|||
|
|||
doesExist.ShouldBeTrue(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotBeExistAsync() |
|||
{ |
|||
var dto = new CheckUrlInputDto |
|||
{ |
|||
Url = _data.Page_1_Url+ "+" |
|||
}; |
|||
|
|||
var doesExist = await _pageAdminAppService.DoesUrlExistAsync(dto); |
|||
|
|||
doesExist.ShouldBeFalse(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldUpdateContentAsync() |
|||
{ |
|||
var dto = new UpdatePageContentInputDto |
|||
{ |
|||
Content = "my-new-content" |
|||
}; |
|||
|
|||
await Should.NotThrowAsync(async () => await _pageAdminAppService.UpdatePageContentAsync(_data.Page_1_Id, dto)); |
|||
|
|||
var content = await _contentRepository.GetAsync(nameof(Page), _data.Page_1_Id.ToString()); |
|||
|
|||
content.Value.ShouldBe(dto.Content); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldDeleteAsync() |
|||
{ |
|||
await _pageAdminAppService.DeleteAsync(_data.Page_1_Id); |
|||
|
|||
await Should.ThrowAsync<Exception>(async () => await _pageRepository.GetAsync(_data.Page_1_Id)); |
|||
|
|||
await Should.ThrowAsync<Exception>(async () => await _contentRepository.GetAsync(nameof(Page), _data.Page_1_Id.ToString())); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.CmsKit.Public.Pages; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class PagePublicAppService_Tests : CmsKitApplicationTestBase |
|||
{ |
|||
private readonly CmsKitTestData _data; |
|||
private readonly IPageAppService _pageAppService; |
|||
|
|||
public PagePublicAppService_Tests() |
|||
{ |
|||
_data = GetRequiredService<CmsKitTestData>(); |
|||
_pageAppService = GetRequiredService<IPageAppService>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldGetByUrlAsync() |
|||
{ |
|||
await Should.NotThrowAsync(async () => await _pageAppService.GetByUrlAsync(_data.Page_1_Url)); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotGetByUrlAsync() |
|||
{ |
|||
await Should.ThrowAsync<Exception>(async () => await _pageAppService.GetByUrlAsync("not-exist-url")); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Volo.CmsKit.Pages; |
|||
|
|||
namespace Volo.CmsKit.EntityFrameworkCore.Pages |
|||
{ |
|||
public class PageRepository_Test : PageRepository_Test<CmsKitEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using Volo.CmsKit.Pages; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.MongoDB.Pages |
|||
{ |
|||
[Collection(MongoTestCollection.Name)] |
|||
public class PageRepository_Test : PageRepository_Test<CmsKitMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,62 @@ |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public abstract class PageRepository_Test<TStartupModule> : CmsKitTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly CmsKitTestData _cmsKitTestData; |
|||
private readonly IPageRepository _pageRepository; |
|||
|
|||
protected PageRepository_Test() |
|||
{ |
|||
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); |
|||
_pageRepository = GetRequiredService<IPageRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldGetByUrlAsync() |
|||
{ |
|||
var page = await _pageRepository.GetByUrlAsync(_cmsKitTestData.Page_1_Url); |
|||
|
|||
page.ShouldNotBeNull(); |
|||
page.Description.ShouldBe(_cmsKitTestData.Page_1_Description); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldFindByUrlAsync() |
|||
{ |
|||
var page = await _pageRepository.FindByUrlAsync(_cmsKitTestData.Page_1_Url); |
|||
|
|||
page.ShouldNotBeNull(); |
|||
page.Description.ShouldBe(_cmsKitTestData.Page_1_Description); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotFindByUrlAsync() |
|||
{ |
|||
var page = await _pageRepository.FindByUrlAsync("not-exist-lyrics"); |
|||
|
|||
page.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldBeExistAsync() |
|||
{ |
|||
var page = await _pageRepository.DoesExistAsync(_cmsKitTestData.Page_1_Url); |
|||
|
|||
page.ShouldBeTrue(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShouldNotBeExistAsync() |
|||
{ |
|||
var page = await _pageRepository.DoesExistAsync("not-exist-lyrics"); |
|||
|
|||
page.ShouldBeFalse(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue