Added Tag tests

pull/6858/head
Ahmet 5 years ago
parent 7dc1bdbe13
commit 6cc5cd4bd9

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

@ -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
{
@ -7,11 +13,104 @@ namespace Volo.CmsKit.Tags
{
private readonly CmsKitTestData _cmsKitTestData;
private readonly ITagRepository _tagRepository;
protected TagRepository_Test()
{
_cmsKitTestData = GetRequiredService<CmsKitTestData>();
_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