Browse Source

CmsKit - Update Tests according to EntityTag domain logic

pull/7103/head
enisn 6 years ago
parent
commit
dce59dadb7
  1. 4
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs
  2. 27
      modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/EntityTagManager_Tests.cs
  3. 20
      modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/TagManager_Tests.cs
  4. 34
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs

4
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Tags/TagAdminAppService_Tests.cs

@ -32,8 +32,8 @@ namespace Volo.CmsKit.Tags
{
var list = await _tagAdminAppService.CreateAsync(new TagCreateDto
{
EntityType = "any_new_type",
Name = "1",
EntityType = _cmsKitTestData.EntityType1,
Name = "My First Tag",
});
list.Id.ShouldNotBe(Guid.Empty);

27
modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/EntityTagManager_Tests.cs

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Volo.CmsKit.Tags
{
public class EntityTagManager_Tests : CmsKitDomainTestBase
{
private readonly CmsKitTestData _cmsKitTestData;
private readonly IEntityTagManager _entityTagManager;
private readonly IEntityTagManager _entityTagManager;
public EntityTagManager_Tests()
{
_cmsKitTestData = GetRequiredService<CmsKitTestData>();
_entityTagManager = GetRequiredService<IEntityTagManager>();
}
public async Task AddTagToEntityAsync_ShouldAdd_WhenEverythingCorrect()
{
var tag = await
await _entityTagManager.AddTagToEntityAsync(_cmsKitTestData.tag)
}
}
}

20
modules/cms-kit/test/Volo.CmsKit.Domain.Tests/Tags/TagManager_Tests.cs

@ -22,7 +22,7 @@ namespace Volo.CmsKit.Tags
[Fact]
public async Task ShouldAddWhenGettingAsync()
{
var newTagEntityType = "testEntity";
var newTagEntityType = _cmsKitTestData.EntityType1;
var newTagName = "test_tag_2123";
var doesExist = await _tagRepository.AnyAsync(newTagEntityType, newTagName);
@ -53,16 +53,28 @@ namespace Volo.CmsKit.Tags
}
[Fact]
public async Task ShouldInsert()
public async Task ShouldInsertAsync()
{
var tag = await _tagManager.InsertAsync(Guid.NewGuid(), "test", "test");
var tagName = "Freshly Created New Tag";
var tag = await _tagManager.InsertAsync(Guid.NewGuid(), _cmsKitTestData.EntityType1, tagName);
tag.ShouldNotBeNull();
var doesExist = await _tagRepository.AnyAsync("test", "test");
var doesExist = await _tagRepository.AnyAsync(_cmsKitTestData.EntityType1, tagName);
doesExist.ShouldBeTrue();
}
[Fact]
public async Task ShouldntInsertWithUnconfiguredEntityTypeAsync()
{
var notConfiguredEntityType = "My.Namespace.SomeEntity";
var exception = await Should.ThrowAsync<EntityNotTaggableException>(async () =>
await _tagManager.InsertAsync(Guid.NewGuid(), notConfiguredEntityType, "test"));
exception.ShouldNotBeNull();
exception.Data[nameof(Tag.EntityType)].ShouldBe(notConfiguredEntityType);
}
[Fact]
public async Task ShouldNotInsert()

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

@ -27,7 +27,7 @@ namespace Volo.CmsKit
private readonly IRatingRepository _ratingRepository;
private readonly ICurrentTenant _currentTenant;
private readonly IContentRepository _contentRepository;
private readonly IEntityTagRepository _entityTagRepository;
private readonly IEntityTagManager _entityTagManager;
private readonly ITagManager _tagManager;
private readonly IPageRepository _pageRepository;
private readonly IOptions<CmsKitOptions> _options;
@ -39,10 +39,10 @@ namespace Volo.CmsKit
ICommentRepository commentRepository,
ReactionManager reactionManager,
IRatingRepository ratingRepository,
ICurrentTenant currentTenant,
ICurrentTenant currentTenant,
IContentRepository contentRepository,
ITagManager tagManager,
IEntityTagRepository entityTagRepository,
ITagManager tagManager,
IEntityTagManager entityTagManager,
IPageRepository pageRepository,
IOptions<CmsKitOptions> options)
{
@ -55,7 +55,7 @@ namespace Volo.CmsKit
_currentTenant = currentTenant;
_contentRepository = contentRepository;
_tagManager = tagManager;
_entityTagRepository = entityTagRepository;
_entityTagManager = entityTagManager;
_pageRepository = pageRepository;
_options = options;
}
@ -64,6 +64,8 @@ namespace Volo.CmsKit
{
using (_currentTenant.Change(context?.TenantId))
{
await ConfigureCmsKitOptionsAsync();
await SeedUsersAsync();
await SeedCommentsAsync();
@ -77,13 +79,15 @@ namespace Volo.CmsKit
await SeedTagsAsync();
await SeedPagesAsync();
await ConfigureCmsKitOptionsAsync();
}
}
private Task ConfigureCmsKitOptionsAsync()
{
_options.Value.Tags.AddOrReplace(_cmsKitTestData.EntityType1);
_options.Value.Tags.AddOrReplace(_cmsKitTestData.EntityType2);
_options.Value.Tags.AddOrReplace(_cmsKitTestData.Content_1_EntityType);
_options.Value.Tags.AddOrReplace(_cmsKitTestData.Content_2_EntityType);
_options.Value.Tags.AddOrReplace(_cmsKitTestData.TagDefinition_1_EntityType);
return Task.CompletedTask;
@ -222,14 +226,14 @@ namespace Volo.CmsKit
_cmsKitTestData.Content_1_EntityId,
_cmsKitTestData.Content_1
);
var content2 = new Content(
_cmsKitTestData.Content_2_Id,
_cmsKitTestData.Content_2_EntityType,
_cmsKitTestData.Content_2_EntityId,
_cmsKitTestData.Content_2
);
var content3 = new Content(
Guid.NewGuid(),
"deleted_entity_type",
@ -251,14 +255,14 @@ namespace Volo.CmsKit
{
var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_1_EntityType, tag);
await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_1_EntityId));
await _entityTagManager.AddTagToEntityAsync(tagEntity.Id, _cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_EntityId);
}
foreach (var tag in _cmsKitTestData.Content_2_Tags)
{
var tagEntity = await _tagManager.InsertAsync(_guidGenerator.Create(), _cmsKitTestData.Content_2_EntityType, tag);
await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_EntityId));
await _entityTagManager.AddTagToEntityAsync(tagEntity.Id, _cmsKitTestData.Content_2_EntityType, _cmsKitTestData.Content_2_EntityId);
}
}
@ -266,10 +270,10 @@ namespace Volo.CmsKit
{
var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Url, _cmsKitTestData.Page_1_Description);
var page1Content = new Content(_guidGenerator.Create(), nameof(Page), page1.Id.ToString(), _cmsKitTestData.Page_1_Content);
await _pageRepository.InsertAsync(page1);
await _contentRepository.InsertAsync(page1Content);
var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Url, _cmsKitTestData.Page_2_Description);
var page2Content = new Content(_guidGenerator.Create(), nameof(Page), page2.Id.ToString(), _cmsKitTestData.Page_2_Content);

Loading…
Cancel
Save