mirror of https://github.com/abpframework/abp.git
committed by
GitHub
63 changed files with 1468 additions and 8918 deletions
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -1,46 +0,0 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.CmsKit.Migrations |
|||
{ |
|||
public partial class Added_Page : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "CmsPages", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
Title = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
Url = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
Description = table.Column<string>(type: "nvarchar(515)", maxLength: 515, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_CmsPages", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_CmsPages_TenantId_Url", |
|||
table: "CmsPages", |
|||
columns: new[] { "TenantId", "Url" }); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "CmsPages"); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -1,24 +0,0 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.CmsKit.Migrations |
|||
{ |
|||
public partial class Updated_Tag_Removed_HexColor : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropColumn( |
|||
name: "HexColor", |
|||
table: "CmsTags"); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AddColumn<string>( |
|||
name: "HexColor", |
|||
table: "CmsTags", |
|||
type: "nvarchar(6)", |
|||
maxLength: 6, |
|||
nullable: true); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -1,95 +0,0 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.CmsKit.Migrations |
|||
{ |
|||
public partial class Added_Blob_Storing : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Description", |
|||
table: "CmsPages", |
|||
type: "nvarchar(512)", |
|||
maxLength: 512, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(515)", |
|||
oldMaxLength: 515, |
|||
oldNullable: true); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "AbpBlobContainers", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
Name = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpBlobContainers", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "AbpBlobs", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ContainerId = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
Content = table.Column<byte[]>(type: "varbinary(max)", maxLength: 2147483647, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_AbpBlobs", x => x.Id); |
|||
table.ForeignKey( |
|||
name: "FK_AbpBlobs_AbpBlobContainers_ContainerId", |
|||
column: x => x.ContainerId, |
|||
principalTable: "AbpBlobContainers", |
|||
principalColumn: "Id", |
|||
onDelete: ReferentialAction.Cascade); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpBlobContainers_TenantId_Name", |
|||
table: "AbpBlobContainers", |
|||
columns: new[] { "TenantId", "Name" }); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpBlobs_ContainerId", |
|||
table: "AbpBlobs", |
|||
column: "ContainerId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_AbpBlobs_TenantId_ContainerId_Name", |
|||
table: "AbpBlobs", |
|||
columns: new[] { "TenantId", "ContainerId", "Name" }); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "AbpBlobs"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "AbpBlobContainers"); |
|||
|
|||
migrationBuilder.AlterColumn<string>( |
|||
name: "Description", |
|||
table: "CmsPages", |
|||
type: "nvarchar(515)", |
|||
maxLength: 515, |
|||
nullable: true, |
|||
oldClrType: typeof(string), |
|||
oldType: "nvarchar(512)", |
|||
oldMaxLength: 512, |
|||
oldNullable: true); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -1,106 +0,0 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.CmsKit.Migrations |
|||
{ |
|||
public partial class UrlSlugToSlug : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "CmsBlogPosts", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
BlogId = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
Title = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false), |
|||
Slug = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
ShortDescription = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_CmsBlogPosts", x => x.Id); |
|||
table.ForeignKey( |
|||
name: "FK_CmsBlogPosts_CmsUsers_CreatorId", |
|||
column: x => x.CreatorId, |
|||
principalTable: "CmsUsers", |
|||
principalColumn: "Id", |
|||
onDelete: ReferentialAction.Restrict); |
|||
table.ForeignKey( |
|||
name: "FK_CmsBlogPosts_CmsUsers_DeleterId", |
|||
column: x => x.DeleterId, |
|||
principalTable: "CmsUsers", |
|||
principalColumn: "Id", |
|||
onDelete: ReferentialAction.Restrict); |
|||
table.ForeignKey( |
|||
name: "FK_CmsBlogPosts_CmsUsers_LastModifierId", |
|||
column: x => x.LastModifierId, |
|||
principalTable: "CmsUsers", |
|||
principalColumn: "Id", |
|||
onDelete: ReferentialAction.Restrict); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "CmsBlogs", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
Name = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false), |
|||
Slug = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_CmsBlogs", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_CmsBlogPosts_CreatorId", |
|||
table: "CmsBlogPosts", |
|||
column: "CreatorId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_CmsBlogPosts_DeleterId", |
|||
table: "CmsBlogPosts", |
|||
column: "DeleterId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_CmsBlogPosts_LastModifierId", |
|||
table: "CmsBlogPosts", |
|||
column: "LastModifierId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_CmsBlogPosts_Slug_BlogId", |
|||
table: "CmsBlogPosts", |
|||
columns: new[] { "Slug", "BlogId" }); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "CmsBlogPosts"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "CmsBlogs"); |
|||
} |
|||
} |
|||
} |
|||
@ -1,73 +0,0 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.CmsKit.Migrations |
|||
{ |
|||
public partial class Added_Media : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "CmsPages"); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "CmsMediaDescriptors", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
Name = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false), |
|||
MimeType = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false), |
|||
Size = table.Column<long>(type: "bigint", maxLength: 2147483647, nullable: false), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_CmsMediaDescriptors", x => x.Id); |
|||
}); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "CmsMediaDescriptors"); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "CmsPages", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
Title = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
Url = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_CmsPages", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_CmsPages_TenantId_Url", |
|||
table: "CmsPages", |
|||
columns: new[] { "TenantId", "Url" }); |
|||
} |
|||
} |
|||
} |
|||
@ -1,46 +0,0 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.CmsKit.Migrations |
|||
{ |
|||
public partial class PageSlugChange : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "CmsPages", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
Title = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
Slug = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false), |
|||
Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_CmsPages", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_CmsPages_TenantId_Slug", |
|||
table: "CmsPages", |
|||
columns: new[] { "TenantId", "Slug" }); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "CmsPages"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,23 @@ |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
namespace Volo.CmsKit.Migrations |
|||
{ |
|||
public partial class BlogFeatureEnabledColumnRename : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.RenameColumn( |
|||
name: "Enabled", |
|||
table: "CmsBlogFeatures", |
|||
newName: "IsEnabled"); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.RenameColumn( |
|||
name: "IsEnabled", |
|||
table: "CmsBlogFeatures", |
|||
newName: "Enabled"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
public class BlogFeatureInputDto |
|||
{ |
|||
[Required] |
|||
public string FeatureName { get; set; } |
|||
public bool IsEnabled { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Blogs; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
public interface IBlogFeatureAdminAppService |
|||
{ |
|||
Task SetAsync(Guid blogId, BlogFeatureInputDto dto); |
|||
|
|||
Task<List<BlogFeatureDto>> GetListAsync(Guid blogId); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.GlobalFeatures; |
|||
using Volo.CmsKit.Admin.Blogs; |
|||
using Volo.CmsKit.Blogs; |
|||
using Volo.CmsKit.GlobalFeatures; |
|||
using Volo.CmsKit.Permissions; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
[RequiresGlobalFeature(typeof(BlogsFeature))] |
|||
public class BlogFeatureAdminAppService : CmsKitAdminAppServiceBase, IBlogFeatureAdminAppService |
|||
{ |
|||
protected IBlogFeatureRepository BlogFeatureRepository { get; } |
|||
|
|||
protected IBlogFeatureManager BlogFeatureManager { get; } |
|||
|
|||
protected IDistributedEventBus EventBus { get; } |
|||
|
|||
public BlogFeatureAdminAppService( |
|||
IBlogFeatureRepository blogFeatureRepository, |
|||
IBlogFeatureManager blogFeatureManager, |
|||
IDistributedEventBus eventBus) |
|||
{ |
|||
BlogFeatureRepository = blogFeatureRepository; |
|||
BlogFeatureManager = blogFeatureManager; |
|||
EventBus = eventBus; |
|||
} |
|||
|
|||
[Authorize(CmsKitAdminPermissions.Blogs.Features)] |
|||
public async Task<List<BlogFeatureDto>> GetListAsync(Guid blogId) |
|||
{ |
|||
var blogFeatures = await BlogFeatureManager.GetListAsync(blogId); |
|||
|
|||
return ObjectMapper.Map<List<BlogFeature>, List<BlogFeatureDto>>(blogFeatures); |
|||
} |
|||
|
|||
[Authorize(CmsKitAdminPermissions.Blogs.Features)] |
|||
public Task SetAsync(Guid blogId, BlogFeatureInputDto dto) |
|||
{ |
|||
return BlogFeatureManager.SetAsync(blogId, dto.FeatureName, dto.IsEnabled); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.GlobalFeatures; |
|||
using Volo.CmsKit.Blogs; |
|||
using Volo.CmsKit.GlobalFeatures; |
|||
using Volo.CmsKit.Permissions; |
|||
|
|||
namespace Volo.CmsKit.Admin.Blogs |
|||
{ |
|||
[RequiresGlobalFeature(typeof(BlogsFeature))] |
|||
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] |
|||
[Area("cms-kit")] |
|||
[Authorize(CmsKitAdminPermissions.Blogs.Features)] |
|||
[Route("api/cms-kit-admin/blogs/{blogId}/features")] |
|||
public class BlogFeatureAdminController : CmsKitAdminController, IBlogFeatureAdminAppService |
|||
{ |
|||
protected IBlogFeatureAdminAppService BlogFeatureAdminAppService { get; } |
|||
|
|||
public BlogFeatureAdminController(IBlogFeatureAdminAppService blogFeatureAdminAppService) |
|||
{ |
|||
BlogFeatureAdminAppService = blogFeatureAdminAppService; |
|||
} |
|||
|
|||
[HttpGet] |
|||
public Task<List<BlogFeatureDto>> GetListAsync(Guid blogId) |
|||
{ |
|||
return BlogFeatureAdminAppService.GetListAsync(blogId); |
|||
} |
|||
|
|||
[HttpPut] |
|||
public Task SetAsync(Guid blogId, BlogFeatureInputDto dto) |
|||
{ |
|||
return BlogFeatureAdminAppService.SetAsync(blogId, dto); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureDto : EntityDto<Guid> |
|||
{ |
|||
public string FeatureName { get; set; } |
|||
public bool IsEnabled { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public interface IBlogFeatureAppService |
|||
{ |
|||
Task<BlogFeatureDto> GetOrDefaultAsync(Guid blogId, string featureName); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public interface IBlogFeatureCacheManager |
|||
{ |
|||
Task<BlogFeatureDto> AddOrGetAsync(Guid blogId, string featureName, Func<Task<BlogFeatureDto>> factory); |
|||
Task ClearAsync(Guid blogId, string featureName); |
|||
} |
|||
} |
|||
@ -1,18 +1,19 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\..\common.props" /> |
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\..\common.props" /> |
|||
<Import Project="..\..\..\..\configureawait.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" /> |
|||
<ProjectReference Include="..\Volo.CmsKit.Common.Application.Contracts\Volo.CmsKit.Common.Application.Contracts.csproj" /> |
|||
<ProjectReference Include="..\Volo.CmsKit.Domain\Volo.CmsKit.Domain.csproj" /> |
|||
</ItemGroup> |
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" /> |
|||
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Caching\Volo.Abp.Caching.csproj" /> |
|||
<ProjectReference Include="..\Volo.CmsKit.Common.Application.Contracts\Volo.CmsKit.Common.Application.Contracts.csproj" /> |
|||
<ProjectReference Include="..\Volo.CmsKit.Domain\Volo.CmsKit.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
|
|||
@ -0,0 +1,41 @@ |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureAppService : CmsKitAppServiceBase, IBlogFeatureAppService |
|||
{ |
|||
protected virtual IBlogFeatureRepository BlogFeatureRepository { get; } |
|||
|
|||
protected virtual IBlogFeatureCacheManager BlogFeatureCacheManager { get; } |
|||
|
|||
public BlogFeatureAppService( |
|||
IBlogFeatureRepository blogFeatureRepository, |
|||
IBlogFeatureCacheManager blogFeatureCacheManager) |
|||
{ |
|||
BlogFeatureRepository = blogFeatureRepository; |
|||
BlogFeatureCacheManager = blogFeatureCacheManager; |
|||
} |
|||
|
|||
public virtual Task<BlogFeatureDto> GetOrDefaultAsync(Guid blogId, string featureName) |
|||
{ |
|||
return BlogFeatureCacheManager |
|||
.AddOrGetAsync( |
|||
blogId, |
|||
featureName, |
|||
()=> GetOrDefaultFroRepositoryAsync(blogId, featureName) |
|||
); |
|||
} |
|||
|
|||
protected virtual async Task<BlogFeatureDto> GetOrDefaultFroRepositoryAsync(Guid blogId, string featureName) |
|||
{ |
|||
var feature = await BlogFeatureRepository.FindAsync(blogId, featureName); |
|||
var blogFeature = feature ?? new BlogFeature(blogId, featureName); |
|||
|
|||
return ObjectMapper.Map<BlogFeature, BlogFeatureDto>(blogFeature); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
using JetBrains.Annotations; |
|||
using Microsoft.Extensions.Caching.Distributed; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureCacheManager : IBlogFeatureCacheManager, ITransientDependency |
|||
{ |
|||
protected IDistributedCache<BlogFeatureDto> Cache { get; } |
|||
|
|||
public BlogFeatureCacheManager(IDistributedCache<BlogFeatureDto> cache) |
|||
{ |
|||
Cache = cache; |
|||
} |
|||
|
|||
public async Task<BlogFeatureDto> AddOrGetAsync(Guid blogId, string featureName, Func<Task<BlogFeatureDto>> factory) |
|||
{ |
|||
return await Cache.GetOrAddAsync( |
|||
GetCacheKey(blogId, featureName), |
|||
factory, |
|||
() => new DistributedCacheEntryOptions |
|||
{ |
|||
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1) |
|||
}); |
|||
} |
|||
|
|||
public Task ClearAsync(Guid blogId, string featureName) |
|||
{ |
|||
return Cache.RemoveAsync(GetCacheKey(blogId, featureName)); |
|||
} |
|||
|
|||
private string GetCacheKey(Guid blogId, [NotNull] string featureName) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(featureName, nameof(featureName)); |
|||
|
|||
return $"{blogId}_{featureName}"; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Caching; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureChangedHandler : IDistributedEventHandler<BlogFeatureChangedEto>, ITransientDependency |
|||
{ |
|||
protected IDistributedCache<BlogFeatureDto> Cache { get; } |
|||
|
|||
public BlogFeatureChangedHandler(IDistributedCache<BlogFeatureDto> cache) |
|||
{ |
|||
Cache = cache; |
|||
} |
|||
|
|||
public async Task HandleEventAsync(BlogFeatureChangedEto eventData) |
|||
{ |
|||
await Cache.RemoveAsync($"{eventData.BlogId}_{eventData.FeatureName}"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.GlobalFeatures; |
|||
using Volo.CmsKit.Blogs; |
|||
using Volo.CmsKit.GlobalFeatures; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
[RequiresGlobalFeature(typeof(BlogsFeature))] |
|||
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] |
|||
[Area("cms-kit")] |
|||
[Route("api/cms-kit/blogs/{blogId}/features")] |
|||
public class BlogFeatureController : CmsKitControllerBase, IBlogFeatureAppService |
|||
{ |
|||
protected IBlogFeatureAppService BlogFeatureAppService { get; } |
|||
|
|||
public BlogFeatureController(IBlogFeatureAppService blogFeatureAppService) |
|||
{ |
|||
BlogFeatureAppService = blogFeatureAppService; |
|||
} |
|||
|
|||
[HttpGet] |
|||
[Route("{featureName}")] |
|||
public Task<BlogFeatureDto> GetOrDefaultAsync(Guid blogId, string featureName) |
|||
{ |
|||
return BlogFeatureAppService.GetOrDefaultAsync(blogId, featureName); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.EventBus; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
[EventName("CmsKit.Blogs.BlogFeature.Changed")] |
|||
public class BlogFeatureChangedEto |
|||
{ |
|||
public Guid BlogId { get; set; } |
|||
public string FeatureName { get; set; } |
|||
public bool IsEnabled { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public static class BlogFeatureConsts |
|||
{ |
|||
public const int MaxFeatureNameLenth = 64; |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
using JetBrains.Annotations; |
|||
using System; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities.Auditing; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeature : FullAuditedAggregateRoot<Guid>, IEquatable<BlogFeature> |
|||
{ |
|||
public Guid BlogId { get; protected set; } |
|||
|
|||
public string FeatureName { get; protected set; } |
|||
|
|||
public bool IsEnabled { get; set; } = true; |
|||
|
|||
public BlogFeature(Guid blogId, [NotNull] string featureName, bool isEnabled = true) |
|||
{ |
|||
BlogId = blogId; |
|||
FeatureName = Check.NotNullOrWhiteSpace(featureName, nameof(featureName)); |
|||
IsEnabled = isEnabled; |
|||
} |
|||
|
|||
public bool Equals(BlogFeature other) |
|||
{ |
|||
return BlogId == other?.BlogId && FeatureName == other?.FeatureName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.Abp.EventBus.Distributed; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureManager : DomainService, IBlogFeatureManager |
|||
{ |
|||
protected IBlogFeatureRepository BlogFeatureRepository { get; } |
|||
|
|||
protected IDefaultBlogFeatureProvider DefaultBlogFeatureProvider { get; } |
|||
|
|||
protected IUnitOfWorkManager UnitOfWorkManager { get; } |
|||
|
|||
protected IDistributedEventBus EventBus { get; } |
|||
|
|||
public BlogFeatureManager( |
|||
IBlogFeatureRepository blogFeatureRepository, |
|||
IDefaultBlogFeatureProvider defaultBlogFeatureProvider, |
|||
IUnitOfWorkManager unitOfWorkManager, |
|||
IDistributedEventBus eventBus) |
|||
{ |
|||
BlogFeatureRepository = blogFeatureRepository; |
|||
DefaultBlogFeatureProvider = defaultBlogFeatureProvider; |
|||
UnitOfWorkManager = unitOfWorkManager; |
|||
EventBus = eventBus; |
|||
} |
|||
|
|||
public async Task<List<BlogFeature>> GetListAsync(Guid blogId) |
|||
{ |
|||
var blogFeatures = await BlogFeatureRepository.GetListAsync(blogId); |
|||
|
|||
var defaultFeatures = await DefaultBlogFeatureProvider.GetDefaultFeaturesAsync(blogId); |
|||
|
|||
defaultFeatures.ForEach(x => blogFeatures.AddIfNotContains(x)); |
|||
|
|||
return blogFeatures; |
|||
} |
|||
|
|||
public async Task SetAsync(Guid blogId, string featureName, bool isEnabled) |
|||
{ |
|||
var blogFeature = await BlogFeatureRepository.FindAsync(blogId, featureName); |
|||
if (blogFeature == null) |
|||
{ |
|||
var newBlogFeature = new BlogFeature(blogId, featureName, isEnabled); |
|||
await BlogFeatureRepository.InsertAsync(newBlogFeature); |
|||
} |
|||
else |
|||
{ |
|||
blogFeature.IsEnabled = isEnabled; |
|||
await BlogFeatureRepository.UpdateAsync(blogFeature); |
|||
} |
|||
|
|||
await UnitOfWorkManager.Current.SaveChangesAsync(); |
|||
|
|||
await EventBus.PublishAsync(new BlogFeatureChangedEto |
|||
{ |
|||
BlogId = blogId, |
|||
FeatureName = featureName, |
|||
IsEnabled = isEnabled |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class DefaultBlogFeatureProvider : IDefaultBlogFeatureProvider, ITransientDependency |
|||
{ |
|||
public virtual Task<List<BlogFeature>> GetDefaultFeaturesAsync(Guid blogId) |
|||
{ |
|||
return Task.FromResult(new List<BlogFeature> |
|||
{ |
|||
new BlogFeature(blogId, BlogPostConsts.CommentsFeatureName), |
|||
new BlogFeature(blogId, BlogPostConsts.ReactionsFeatureName), |
|||
new BlogFeature(blogId, BlogPostConsts.RatingsFeatureName), |
|||
new BlogFeature(blogId, BlogPostConsts.TagsFeatureName), |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Services; |
|||
using Volo.CmsKit.Blogs; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public interface IBlogFeatureManager : IDomainService |
|||
{ |
|||
Task<List<BlogFeature>> GetListAsync(Guid blogId); |
|||
|
|||
Task SetAsync(Guid blogId, string featureName, bool isEnabled); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public interface IBlogFeatureRepository : IBasicRepository<BlogFeature, Guid> |
|||
{ |
|||
Task<List<BlogFeature>> GetListAsync(Guid blogId); |
|||
|
|||
Task<List<BlogFeature>> GetListAsync(Guid blogId, List<string> featureNames); |
|||
|
|||
Task<BlogFeature> FindAsync(Guid blogId, string featureName); |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Blogs; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public interface IDefaultBlogFeatureProvider |
|||
{ |
|||
Task<List<BlogFeature>> GetDefaultFeaturesAsync(Guid blogId); |
|||
} |
|||
} |
|||
@ -0,0 +1,37 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.CmsKit.EntityFrameworkCore; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class EfCoreBlogFeatureRepository : EfCoreRepository<CmsKitDbContext, BlogFeature, Guid>, IBlogFeatureRepository |
|||
{ |
|||
public EfCoreBlogFeatureRepository(IDbContextProvider<CmsKitDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public Task<BlogFeature> FindAsync(Guid blogId, string featureName) |
|||
{ |
|||
return base.FindAsync(x => x.BlogId == blogId && x.FeatureName == featureName); |
|||
} |
|||
|
|||
public async Task<List<BlogFeature>> GetListAsync(Guid blogId) |
|||
{ |
|||
return await (await GetQueryableAsync()) |
|||
.Where(x => x.BlogId == blogId) |
|||
.ToListAsync(); |
|||
} |
|||
|
|||
public async Task<List<BlogFeature>> GetListAsync(Guid blogId, List<string> featureNames) |
|||
{ |
|||
return await (await GetQueryableAsync()) |
|||
.Where(x => x.BlogId == blogId && featureNames.Contains(x.FeatureName)) |
|||
.ToListAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using MongoDB.Driver.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Domain.Repositories.MongoDB; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.CmsKit.Blogs; |
|||
using MongoDB.Driver; |
|||
|
|||
namespace Volo.CmsKit.MongoDB.Blogs |
|||
{ |
|||
public class MongoBlogFeatureRepository : MongoDbRepository<ICmsKitMongoDbContext, BlogFeature, Guid> , IBlogFeatureRepository |
|||
{ |
|||
public MongoBlogFeatureRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) |
|||
{ |
|||
} |
|||
|
|||
public Task<BlogFeature> FindAsync(Guid blogId, string featureName) |
|||
{ |
|||
return base.FindAsync(x => x.BlogId == blogId && x.FeatureName == featureName); |
|||
} |
|||
|
|||
public async Task<List<BlogFeature>> GetListAsync(Guid blogId) |
|||
{ |
|||
return await (await GetMongoQueryableAsync()) |
|||
.Where(x => x.BlogId == blogId) |
|||
.ToListAsync(); |
|||
} |
|||
|
|||
public async Task<List<BlogFeature>> GetListAsync(Guid blogId, List<string> featureNames) |
|||
{ |
|||
return await (await GetMongoQueryableAsync()) |
|||
.Where(x => x.BlogId == blogId && featureNames.Contains(x.FeatureName)) |
|||
.ToListAsync(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.CmsKit.Public.Blogs |
|||
{ |
|||
public class GetBlogFeatureInput |
|||
{ |
|||
public List<string> FeatureNames { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
using Shouldly; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Admin.Blogs; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureAdminAppService_Test : CmsKitApplicationTestBase |
|||
{ |
|||
private readonly CmsKitTestData testData; |
|||
private readonly IBlogFeatureAdminAppService blogFeatureAdminAppService; |
|||
private readonly IBlogFeatureRepository blogFeatureRepository; |
|||
|
|||
public BlogFeatureAdminAppService_Test() |
|||
{ |
|||
testData = GetRequiredService<CmsKitTestData>(); |
|||
blogFeatureAdminAppService = GetRequiredService<IBlogFeatureAdminAppService>(); |
|||
blogFeatureRepository = GetRequiredService<IBlogFeatureRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetAsync_ShouldWorkProperly_WithNonExistingFeature() |
|||
{ |
|||
var dto = new BlogFeatureInputDto |
|||
{ |
|||
FeatureName = "My.Awesome.Feature", |
|||
IsEnabled = true |
|||
}; |
|||
|
|||
await blogFeatureAdminAppService.SetAsync(testData.Blog_Id, dto); |
|||
|
|||
var feature = await blogFeatureRepository.FindAsync(testData.Blog_Id, dto.FeatureName); |
|||
|
|||
feature.ShouldNotBeNull(); |
|||
feature.BlogId.ShouldBe(testData.Blog_Id); |
|||
feature.IsEnabled.ShouldBe(dto.IsEnabled); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetAsync_ShouldWorkProperly_WithExistingFeature() |
|||
{ |
|||
var dto = new BlogFeatureInputDto |
|||
{ |
|||
FeatureName = testData.BlogFeature_2_FeatureName, |
|||
IsEnabled = !testData.BlogFeature_2_Enabled |
|||
}; |
|||
|
|||
await blogFeatureAdminAppService.SetAsync(testData.Blog_Id, dto); |
|||
|
|||
var feature = await blogFeatureRepository.FindAsync(testData.Blog_Id, dto.FeatureName); |
|||
|
|||
feature.ShouldNotBeNull(); |
|||
feature.BlogId.ShouldBe(testData.Blog_Id); |
|||
feature.IsEnabled.ShouldBe(dto.IsEnabled); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync_ShouldWorkProperly_WithBlogId() |
|||
{ |
|||
var result = await blogFeatureAdminAppService.GetListAsync(testData.Blog_Id); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.ShouldNotBeEmpty(); |
|||
result.Count.ShouldBeGreaterThan(2); // 2 are seeded and there are built-in Features.
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Public.Blogs; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeaturePublicAppService_Test : CmsKitApplicationTestBase |
|||
{ |
|||
private readonly CmsKitTestData testData; |
|||
private readonly IBlogFeatureAppService blogFeatureAppService; |
|||
|
|||
public BlogFeaturePublicAppService_Test() |
|||
{ |
|||
testData = GetRequiredService<CmsKitTestData>(); |
|||
blogFeatureAppService = GetRequiredService<IBlogFeatureAppService>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetAsync_ShouldWorkProperly_WithExistingFeatureName() |
|||
{ |
|||
var result = await blogFeatureAppService.GetOrDefaultAsync(testData.Blog_Id, testData.BlogFeature_1_FeatureName); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.FeatureName.ShouldBe(testData.BlogFeature_1_FeatureName); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetAsync_ShouldReturnDefault_WithNonExistingFeatureName() |
|||
{ |
|||
var nonExistingFeatureName = "AnyOtherFeature"; |
|||
var result = await blogFeatureAppService.GetOrDefaultAsync(testData.Blog_Id, nonExistingFeatureName); |
|||
|
|||
var defaultFeature = new BlogFeature(Guid.Empty, nonExistingFeatureName); |
|||
result.ShouldNotBeNull(); |
|||
result.IsEnabled.ShouldBe(defaultFeature.IsEnabled); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Blogs; |
|||
|
|||
namespace Volo.CmsKit.EntityFrameworkCore.Blogs |
|||
{ |
|||
public class BlogFeatureRepository_Test : BlogFeatureRepository_Test<CmsKitEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Blogs; |
|||
|
|||
namespace Volo.CmsKit.MongoDB.Blogs |
|||
{ |
|||
public class BlogFeatureRepository_Test : BlogFeatureRepository_Test<CmsKitMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
using Shouldly; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public abstract class BlogFeatureRepository_Test<TStartupModule> : CmsKitTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly CmsKitTestData testData; |
|||
private readonly IBlogFeatureRepository blogFeatureRepository; |
|||
public BlogFeatureRepository_Test() |
|||
{ |
|||
testData = GetRequiredService<CmsKitTestData>(); |
|||
blogFeatureRepository = GetRequiredService<IBlogFeatureRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync_ShouldWorkProperly_WithBlogId() |
|||
{ |
|||
var result = await blogFeatureRepository.GetListAsync(testData.Blog_Id); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.ShouldNotBeEmpty(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync_ShouldWorkProperly_WithBlogIdWithFeatureNames() |
|||
{ |
|||
var result = await blogFeatureRepository.GetListAsync(testData.Blog_Id, new List<string> { testData.BlogFeature_1_FeatureName }); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.ShouldNotBeEmpty(); |
|||
result.Count.ShouldBe(1); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync_ShouldWorkProperly_WithExistingFeatureName() |
|||
{ |
|||
var result = await blogFeatureRepository.FindAsync(testData.Blog_Id, testData.BlogFeature_1_FeatureName); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.FeatureName.ShouldBe(testData.BlogFeature_1_FeatureName); |
|||
result.IsEnabled.ShouldBe(testData.BlogFeature_1_Enabled); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync_ShouldReturnNull_WithNonExistingFeatureName() |
|||
{ |
|||
var nonExistingFeatureName = "Some.Feature"; |
|||
var result = await blogFeatureRepository.FindAsync(testData.Blog_Id, nonExistingFeatureName); |
|||
|
|||
result.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindAsync_ShouldReturnNull_WithNonExistingBlogId() |
|||
{ |
|||
var nonExistingBlogId = Guid.NewGuid(); |
|||
var result = await blogFeatureRepository.FindAsync(nonExistingBlogId, testData.BlogFeature_1_FeatureName); |
|||
|
|||
result.ShouldBeNull(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue