mirror of https://github.com/abpframework/abp.git
6 changed files with 189 additions and 0 deletions
@ -0,0 +1,67 @@ |
|||
using Shouldly; |
|||
using System.Threading.Tasks; |
|||
using Volo.CmsKit.Admin.Blogs; |
|||
using Xunit; |
|||
|
|||
namespace Volo.CmsKit.Blogs |
|||
{ |
|||
public class BlogFeatureAdminAppService : CmsKitApplicationTestBase |
|||
{ |
|||
private readonly CmsKitTestData testData; |
|||
private readonly IBlogFeatureAdminAppService blogFeatureAdminAppService; |
|||
private readonly IBlogFeatureRepository blogFeatureRepository; |
|||
|
|||
public BlogFeatureAdminAppService() |
|||
{ |
|||
testData = GetRequiredService<CmsKitTestData>(); |
|||
blogFeatureAdminAppService = GetRequiredService<IBlogFeatureAdminAppService>(); |
|||
blogFeatureRepository = GetRequiredService<IBlogFeatureRepository>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetAsync_ShouldWorkProperly_WithNonExistingFeature() |
|||
{ |
|||
var dto = new BlogFeatureDto |
|||
{ |
|||
FeatureName = "My.Awesome.Feature", |
|||
Enabled = 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.Enabled.ShouldBe(dto.Enabled); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task SetAsync_ShouldWorkProperly_WithExistingFeature() |
|||
{ |
|||
var dto = new BlogFeatureDto |
|||
{ |
|||
FeatureName = testData.BlogFeature_2_FeatureName, |
|||
Enabled = !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.Enabled.ShouldBe(dto.Enabled); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync_ShouldWorkProperly_WithBlogId() |
|||
{ |
|||
var result = await blogFeatureAdminAppService.GetListAsync(testData.Blog_Id); |
|||
|
|||
result.ShouldNotBeNull(); |
|||
result.ShouldNotBeEmpty(); |
|||
result.Count.ShouldBe(2); |
|||
} |
|||
} |
|||
} |
|||
@ -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,58 @@ |
|||
using Shouldly; |
|||
using System; |
|||
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 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.Enabled.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