Browse Source

CmsKit - Add BlogFeature Admin Tests

pull/7745/head
enisn 6 years ago
parent
commit
16261a9d77
  1. 67
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Blogs/BlogFeatureAdminAppService.cs
  2. 14
      modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Blogs/BlogFeatureRepository_Test.cs
  3. 14
      modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Blogs/BlogFeatureRepository_Test.cs
  4. 58
      modules/cms-kit/test/Volo.CmsKit.TestBase/Blogs/BlogFeatureRepository_Test.cs
  5. 24
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs
  6. 12
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs

67
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Blogs/BlogFeatureAdminAppService.cs

@ -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);
}
}
}

14
modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Blogs/BlogFeatureRepository_Test.cs

@ -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>
{
}
}

14
modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Blogs/BlogFeatureRepository_Test.cs

@ -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>
{
}
}

58
modules/cms-kit/test/Volo.CmsKit.TestBase/Blogs/BlogFeatureRepository_Test.cs

@ -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();
}
}
}

24
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs

@ -39,6 +39,7 @@ namespace Volo.CmsKit
private readonly IEntityTagRepository _entityTagRepository;
private readonly IPageRepository _pageRepository;
private readonly IBlogRepository _blogRepository;
private readonly IBlogFeatureRepository _blogFeatureRepository;
private readonly IBlogPostRepository _blogPostRepository;
private readonly IOptions<CmsKitOptions> _options;
private readonly IOptions<CmsKitTagOptions> _tagOptions;
@ -59,6 +60,7 @@ namespace Volo.CmsKit
IPageRepository pageRepository,
IBlogRepository blogRepository,
IBlogPostRepository blogPostRepository,
IBlogFeatureRepository blogFeatureRepository,
IEntityTagManager entityTagManager,
IOptions<CmsKitOptions> options,
IOptions<CmsKitTagOptions> tagOptions,
@ -79,6 +81,7 @@ namespace Volo.CmsKit
_pageRepository = pageRepository;
_blogRepository = blogRepository;
_blogPostRepository = blogPostRepository;
_blogFeatureRepository = blogFeatureRepository;
_options = options;
_tagOptions = tagOptions;
_mediaDescriptorRepository = mediaDescriptorRepository;
@ -107,6 +110,8 @@ namespace Volo.CmsKit
await SeedBlogsAsync();
await SeedBlogFeaturesAsync();
await SeedMediaAsync();
}
}
@ -327,6 +332,25 @@ namespace Volo.CmsKit
await _blogPostRepository.InsertAsync(new BlogPost(_cmsKitTestData.BlogPost_2_Id, blog.Id, _cmsKitTestData.BlogPost_2_Title, _cmsKitTestData.BlogPost_2_Slug, "Short desc 2"));
}
private async Task SeedBlogFeaturesAsync()
{
var blogFeature1 = await _blogFeatureRepository.InsertAsync(
new BlogFeature(
_cmsKitTestData.Blog_Id,
_cmsKitTestData.BlogFeature_1_FeatureName,
_cmsKitTestData.BlogFeature_1_Enabled));
_cmsKitTestData.BlogFeature_1_Id = blogFeature1.Id;
var blogFeature2 = await _blogFeatureRepository.InsertAsync(
new BlogFeature(
_cmsKitTestData.Blog_Id,
_cmsKitTestData.BlogFeature_2_FeatureName,
_cmsKitTestData.BlogFeature_2_Enabled));
_cmsKitTestData.BlogFeature_2_Id = blogFeature2.Id;
}
private async Task SeedMediaAsync()
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(_cmsKitTestData.Media_1_Content)))

12
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs

@ -91,6 +91,18 @@ namespace Volo.CmsKit
public string BlogPost_2_Slug => "how-to-use-cms-kit";
public Guid BlogFeature_1_Id { get; internal set; } = Guid.NewGuid();
public string BlogFeature_1_FeatureName => "Tagging";
public bool BlogFeature_1_Enabled => true;
public Guid BlogFeature_2_Id { get; internal set; } = Guid.NewGuid();
public string BlogFeature_2_FeatureName => "Rating";
public bool BlogFeature_2_Enabled => false;
public Guid Media_1_Id { get; } = Guid.NewGuid();
public string Media_1_Content = "Hi, this is text file";

Loading…
Cancel
Save