Browse Source

Added Tag tests

pull/6858/head
Ahmet 6 years ago
parent
commit
6cc5cd4bd9
  1. 36
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs
  2. 103
      modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/TagRepository_Test.cs

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

@ -24,8 +24,9 @@ namespace Volo.CmsKit
private readonly IRatingRepository _ratingRepository; private readonly IRatingRepository _ratingRepository;
private readonly ICurrentTenant _currentTenant; private readonly ICurrentTenant _currentTenant;
private readonly IContentRepository _contentRepository; private readonly IContentRepository _contentRepository;
private readonly ITagRepository _tagRepository; private readonly IEntityTagRepository _entityTagRepository;
private readonly ITagManager _tagManager;
public CmsKitDataSeedContributor( public CmsKitDataSeedContributor(
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
ICmsUserRepository cmsUserRepository, ICmsUserRepository cmsUserRepository,
@ -34,8 +35,9 @@ namespace Volo.CmsKit
ReactionManager reactionManager, ReactionManager reactionManager,
IRatingRepository ratingRepository, IRatingRepository ratingRepository,
ICurrentTenant currentTenant, ICurrentTenant currentTenant,
IContentRepository contentRepository, IContentRepository contentRepository,
ITagRepository tagRepository) ITagManager tagManager,
IEntityTagRepository entityTagRepository)
{ {
_guidGenerator = guidGenerator; _guidGenerator = guidGenerator;
_cmsUserRepository = cmsUserRepository; _cmsUserRepository = cmsUserRepository;
@ -45,7 +47,8 @@ namespace Volo.CmsKit
_ratingRepository = ratingRepository; _ratingRepository = ratingRepository;
_currentTenant = currentTenant; _currentTenant = currentTenant;
_contentRepository = contentRepository; _contentRepository = contentRepository;
_tagRepository = tagRepository; _tagManager = tagManager;
_entityTagRepository = entityTagRepository;
} }
public async Task SeedAsync(DataSeedContext context) public async Task SeedAsync(DataSeedContext context)
@ -213,21 +216,18 @@ namespace Volo.CmsKit
private async Task SeedTagsAsync() private async Task SeedTagsAsync()
{ {
var content_1_tags = foreach (var tag in _cmsKitTestData.Content_1_Tags)
_cmsKitTestData.Content_1_Tags {
.Select(x => var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_1_EntityType, tag);
new Tag(_guidGenerator.Create(), _cmsKitTestData.Content_1_EntityType, x)).ToList();
var content_2_tags =
_cmsKitTestData.Content_2_Tags
.Select(x =>
new Tag(_guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, x)).ToList();
content_1_tags.AddRange(content_2_tags);
foreach (var tag in content_1_tags) await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_Id));
}
foreach (var tag in _cmsKitTestData.Content_2_Tags)
{ {
await _tagRepository.InsertAsync(tag); var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, tag);
await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_Id));
} }
} }
} }

103
modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/TagRepository_Test.cs

@ -1,4 +1,10 @@
using Volo.Abp.Modularity; using System;
using System.Linq;
using System.Threading.Tasks;
using Shouldly;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Modularity;
using Xunit;
namespace Volo.CmsKit.Tags namespace Volo.CmsKit.Tags
{ {
@ -7,11 +13,104 @@ namespace Volo.CmsKit.Tags
{ {
private readonly CmsKitTestData _cmsKitTestData; private readonly CmsKitTestData _cmsKitTestData;
private readonly ITagRepository _tagRepository; private readonly ITagRepository _tagRepository;
protected TagRepository_Test() protected TagRepository_Test()
{ {
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); _cmsKitTestData = GetRequiredService<CmsKitTestData>();
_tagRepository = GetRequiredService<ITagRepository>(); _tagRepository = GetRequiredService<ITagRepository>();
} }
[Theory]
[InlineData("Lyrics", "Imagine Dragons")]
[InlineData("Lyrics", "Music")]
[InlineData("LyricsAlso", "Imagine Dragons")]
[InlineData("LyricsAlso", "Music")]
[InlineData("LyricsAlso", "Most Loved Part")]
public async Task ShouldGetAsync(string entityType, string name)
{
var tag = await _tagRepository.GetAsync(entityType, name);
tag.ShouldNotBeNull();
}
[Fact]
public async Task ShouldNotGetAsync()
{
Should.Throw<EntityNotFoundException>(
async () => await _tagRepository.GetAsync("not_exist_entity", Guid.NewGuid().ToString())
);
}
[Theory]
[InlineData("Lyrics", "Imagine Dragons")]
[InlineData("Lyrics", "Music")]
[InlineData("LyricsAlso", "Imagine Dragons")]
[InlineData("LyricsAlso", "Music")]
[InlineData("LyricsAlso", "Most Loved Part")]
public async Task ShouldExistAsync(string entityType, string name)
{
var tag = await _tagRepository.AnyAsync(entityType, name);
tag.ShouldBeTrue();
}
[Fact]
public async Task ShouldNotExistAsync()
{
var tag = await _tagRepository.AnyAsync("not_exist_entity", Guid.NewGuid().ToString());
tag.ShouldBeFalse();
}
[Theory]
[InlineData("Lyrics", "Imagine Dragons")]
[InlineData("Lyrics", "Music")]
[InlineData("LyricsAlso", "Imagine Dragons")]
[InlineData("LyricsAlso", "Music")]
[InlineData("LyricsAlso", "Most Loved Part")]
public async Task ShouldFindAsync(string entityType, string name)
{
var tag = await _tagRepository.FindAsync(entityType, name);
tag.ShouldNotBeNull();
}
[Fact]
public async Task ShouldNotFindAsync()
{
var tag = await _tagRepository.FindAsync("not_exist_entity", Guid.NewGuid().ToString());
tag.ShouldBeNull();
}
[Fact]
public async Task Should_Get_Related_Tags()
{
var content_1_tags = await _tagRepository.GetAllRelatedTagsAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityType);
content_1_tags.Count.ShouldBe(_cmsKitTestData.Content_1_Tags.Length);
foreach (var tag in content_1_tags)
{
_cmsKitTestData.Content_1_Tags.Contains(tag.Name).ShouldBeTrue();
}
var content_2_tags = await _tagRepository.GetAllRelatedTagsAsync(_cmsKitTestData.Content_2_EntityType, _cmsKitTestData.Content_2_EntityType);
content_2_tags.Count.ShouldBe(_cmsKitTestData.Content_2_Tags.Length);
foreach (var tag in content_2_tags)
{
_cmsKitTestData.Content_2_Tags.Contains(tag.Name).ShouldBeTrue();
}
}
[Fact]
public async Task Should_Not_Get_Related_Tags()
{
var tags = await _tagRepository.GetAllRelatedTagsAsync("not_exist_entity", Guid.NewGuid().ToString());
tags.Count.ShouldBe(0);
}
} }
} }
Loading…
Cancel
Save