mirror of https://github.com/abpframework/abp.git
50 changed files with 2100 additions and 11666 deletions
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
public class BlogPostGetListInput : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string Filter { get; set; } |
|||
|
|||
public Guid? BlogId { get; set; } |
|||
} |
|||
} |
|||
@ -1,15 +0,0 @@ |
|||
using System; |
|||
using Volo.CmsKit.Entities; |
|||
|
|||
namespace Volo.CmsKit.Contents |
|||
{ |
|||
public static class ContentConsts |
|||
{ |
|||
public static int MaxEntityTypeLength { get; set; } = CmsEntityConsts.MaxEntityTypeLength; |
|||
|
|||
public static int MaxEntityIdLength { get; set; } = CmsEntityConsts.MaxEntityIdLength; |
|||
|
|||
// TODO: consider
|
|||
public static int MaxValueLength { get; set; } = int.MaxValue; |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Services; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class PageManager : DomainService |
|||
{ |
|||
protected IPageRepository PageRepository { get; } |
|||
|
|||
public PageManager(IPageRepository pageRepository) |
|||
{ |
|||
PageRepository = pageRepository; |
|||
} |
|||
|
|||
public virtual async Task<Page> CreateAsync( |
|||
[NotNull] string title, |
|||
[NotNull] string slug, |
|||
[CanBeNull] string content = null) |
|||
{ |
|||
Check.NotNullOrEmpty(title, nameof(title)); |
|||
Check.NotNullOrEmpty(slug, nameof(slug)); |
|||
|
|||
await CheckPageSlugAsync(slug); |
|||
|
|||
return new Page( |
|||
GuidGenerator.Create(), |
|||
title, |
|||
slug, |
|||
content, |
|||
CurrentTenant.Id); |
|||
} |
|||
|
|||
public virtual async Task SetSlugAsync(Page page, string newSlug) |
|||
{ |
|||
if (page.Slug != newSlug) |
|||
{ |
|||
await CheckPageSlugAsync(newSlug); |
|||
page.SetSlug(newSlug); |
|||
} |
|||
} |
|||
|
|||
protected virtual async Task CheckPageSlugAsync(string slug) |
|||
{ |
|||
if (await PageRepository.ExistsAsync(slug)) |
|||
{ |
|||
throw new PageSlugAlreadyExistsException(slug); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,12 +1,12 @@ |
|||
using Slugify; |
|||
using Unidecode.NET; |
|||
|
|||
namespace Volo.CmsKit.Blogs.Extensions |
|||
namespace Volo.CmsKit |
|||
{ |
|||
public static class SlugExtensions |
|||
public static class SlugNormalizer |
|||
{ |
|||
static readonly SlugHelper SlugHelper = new (); |
|||
public static string NormalizeSlug(this string value) |
|||
public static string Normalize(string value) |
|||
{ |
|||
return SlugHelper.GenerateSlug(value?.Unidecode()); |
|||
} |
|||
@ -0,0 +1,70 @@ |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Pages |
|||
{ |
|||
public class PageManager_Test : CmsKitDomainTestBase |
|||
{ |
|||
private readonly PageManager pageManager; |
|||
private readonly CmsKitTestData testData; |
|||
private readonly IPageRepository pageRepository; |
|||
|
|||
public PageManager_Test() |
|||
{ |
|||
pageManager = GetRequiredService<PageManager>(); |
|||
testData = GetRequiredService<CmsKitTestData>(); |
|||
pageRepository = GetRequiredService<IPageRepository>(); |
|||
} |
|||
|
|||
public async Task CreateAsync_ShouldWorkProperly_WithNonExistingSlug() |
|||
{ |
|||
var title = "My awesome page"; |
|||
var slug = "my-awesome-page"; |
|||
var content = "<h1>My Awesome Page</h1><p>This is my awesome page content!</p>"; |
|||
|
|||
var page = await pageManager.CreateAsync(title, slug, content); |
|||
|
|||
page.ShouldNotBeNull(); |
|||
page.Title.ShouldBe(title); |
|||
page.Slug.ShouldBe(slug); |
|||
page.Content.ShouldBe(content); |
|||
} |
|||
|
|||
public async Task CreateAsync_ShouldThrowException_WithExistingSlug() |
|||
{ |
|||
var title = "My awesome page"; |
|||
var slug = testData.Page_1_Slug; |
|||
var content = "<h1>My Awesome Page</h1><p>This is my awesome page content!</p>"; |
|||
|
|||
var exception = await Should.ThrowAsync<PageSlugAlreadyExistsException>(async () => |
|||
await pageManager.CreateAsync(title, slug, content)); |
|||
|
|||
exception.ShouldNotBeNull(); |
|||
} |
|||
|
|||
public async Task SetSlugAsync_ShouldWorkProperly_WithNonExistingSlug() |
|||
{ |
|||
var newSlug = "freshly-generated-new-slug"; |
|||
var page = await pageRepository.GetAsync(testData.Page_1_Id); |
|||
|
|||
await pageManager.SetSlugAsync(page, newSlug); |
|||
|
|||
page.Slug.ShouldBe(newSlug); |
|||
} |
|||
|
|||
public async Task SetSlugAsync_ShouldThrowException_WithExistingSlug() |
|||
{ |
|||
var newSlug = testData.Page_2_Slug; |
|||
var page = await pageRepository.GetAsync(testData.Page_1_Id); |
|||
|
|||
var exception = await Should.ThrowAsync<PageSlugAlreadyExistsException>(async () => |
|||
await pageManager.SetSlugAsync(page, newSlug)); |
|||
|
|||
exception.ShouldNotBeNull(); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
Loading…
Reference in new issue