From c84aaf1e7b84eba75e25a34816551c4e3d7ec90e Mon Sep 17 00:00:00 2001 From: Ahmet Date: Mon, 28 Dec 2020 15:41:24 +0300 Subject: [PATCH] created tag test data and fix some bugs --- .../Volo/CmsKit/Contents/Content.cs | 2 +- .../Volo/CmsKit/Pages/Page.cs | 2 +- .../Volo/CmsKit/Tags/EntityTag.cs | 2 +- .../Volo/CmsKit/Tags/Tag.cs | 2 +- .../Tags/TagRepository_Test.cs | 9 ++++++ .../MongoDB/Tags/TagRepository_Test.cs | 11 +++++++ .../CmsKitDataSeedContributor.cs | 32 +++++++++++++++++-- .../Volo.CmsKit.TestBase/CmsKitTestData.cs | 5 +++ .../Contents/ContentRepository_Tests.cs | 3 +- .../Tags/TagRepository_Test.cs | 17 ++++++++++ 10 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Tags/TagRepository_Test.cs create mode 100644 modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Tags/TagRepository_Test.cs create mode 100644 modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/TagRepository_Test.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs index 354041b51b..6f4175daad 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs @@ -8,7 +8,7 @@ namespace Volo.CmsKit.Contents { public class Content : FullAuditedAggregateRoot, IMultiTenant { - public virtual Guid? TenantId { get; } + public virtual Guid? TenantId { get; set; } public virtual string EntityType { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs index c02617c8d3..16ec7df3a5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs @@ -8,7 +8,7 @@ namespace Volo.CmsKit.Pages { public class Page : FullAuditedAggregateRoot, IMultiTenant { - public Guid? TenantId { get; } + public Guid? TenantId { get; set; } public virtual string Title { get; set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/EntityTag.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/EntityTag.cs index e69dbf53aa..5d27e8b15f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/EntityTag.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/EntityTag.cs @@ -10,7 +10,7 @@ namespace Volo.CmsKit.Tags public virtual string EntityId { get; set; } - public virtual Guid? TenantId { get; } + public virtual Guid? TenantId { get; set; } protected EntityTag() { diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs index 09d9fe6c3c..fab09ed521 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs @@ -12,7 +12,7 @@ namespace Volo.CmsKit.Tags public string Name { get; protected set; } - public Guid? TenantId { get; } + public Guid? TenantId { get; set; } protected Tag() { diff --git a/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Tags/TagRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Tags/TagRepository_Test.cs new file mode 100644 index 0000000000..205379e2b3 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Tags/TagRepository_Test.cs @@ -0,0 +1,9 @@ +using Volo.CmsKit.Tags; + +namespace Volo.CmsKit.EntityFrameworkCore.Tags +{ + public class TagRepository_Test : TagRepository_Test + { + + } +} \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Tags/TagRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Tags/TagRepository_Test.cs new file mode 100644 index 0000000000..1c2f063989 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Tags/TagRepository_Test.cs @@ -0,0 +1,11 @@ +using Volo.CmsKit.Tags; +using Xunit; + +namespace Volo.CmsKit.MongoDB.Tags +{ + [Collection(MongoTestCollection.Name)] + public class TagRepository_Test : TagRepository_Test + { + + } +} \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs index 088056dc05..a33253406e 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Linq; +using System.Threading.Tasks; using Volo.Abp.Data; using Volo.Abp.DependencyInjection; using Volo.Abp.Guids; @@ -8,6 +9,7 @@ using Volo.CmsKit.Comments; using Volo.CmsKit.Contents; using Volo.CmsKit.Ratings; using Volo.CmsKit.Reactions; +using Volo.CmsKit.Tags; using Volo.CmsKit.Users; namespace Volo.CmsKit @@ -22,6 +24,8 @@ namespace Volo.CmsKit private readonly IRatingRepository _ratingRepository; private readonly ICurrentTenant _currentTenant; private readonly IContentRepository _contentRepository; + private readonly ITagRepository _tagRepository; + public CmsKitDataSeedContributor( IGuidGenerator guidGenerator, ICmsUserRepository cmsUserRepository, @@ -30,7 +34,8 @@ namespace Volo.CmsKit ReactionManager reactionManager, IRatingRepository ratingRepository, ICurrentTenant currentTenant, - IContentRepository contentRepository) + IContentRepository contentRepository, + ITagRepository tagRepository) { _guidGenerator = guidGenerator; _cmsUserRepository = cmsUserRepository; @@ -40,6 +45,7 @@ namespace Volo.CmsKit _ratingRepository = ratingRepository; _currentTenant = currentTenant; _contentRepository = contentRepository; + _tagRepository = tagRepository; } public async Task SeedAsync(DataSeedContext context) @@ -55,6 +61,8 @@ namespace Volo.CmsKit await SeedRatingsAsync(); await SeedContentsAsync(); + + await SeedTagsAsync(); } } @@ -202,5 +210,25 @@ namespace Volo.CmsKit await _contentRepository.InsertAsync(content1); await _contentRepository.InsertAsync(content2); } + + 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 content_1_tags) + { + await _tagRepository.InsertAsync(tag); + } + } } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs index 0477711cd3..6589e79d9c 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs @@ -1,4 +1,5 @@ using System; +using JetBrains.Annotations; using Volo.Abp.DependencyInjection; namespace Volo.CmsKit @@ -24,11 +25,15 @@ namespace Volo.CmsKit public string Content_1 { get; } = "First things first\nI'ma say all the words inside my head\nI'm fired up and tired of the way that things have been, oh-ooh\nThe way that things have been, oh-ooh"; public string Content_1_Id = "1"; + + public string[] Content_1_Tags => new string[] {"Imagine Dragons", "Music"}; public string Content_2_EntityType = "LyricsAlso"; public string Content_2 { get; } = "Second thing second\nDon't you tell me what you think that I could be\nI'm the one at the sail, I'm the master of my sea, oh-ooh\nThe master of my sea, oh-ooh"; public string Content_2_Id = "2"; + + public string[] Content_2_Tags => new string[] {"Imagine Dragons", "Music", "Most Loved Part"}; } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs index 6cec5786e2..c92383694e 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs @@ -3,7 +3,6 @@ using System.Threading.Tasks; using Shouldly; using Volo.Abp.Domain.Entities; using Volo.Abp.Modularity; -using Volo.Abp.Uow; using Xunit; namespace Volo.CmsKit.Contents @@ -14,7 +13,7 @@ namespace Volo.CmsKit.Contents private readonly CmsKitTestData _cmsKitTestData; private readonly IContentRepository _contentRepository; - public ContentRepository_Tests() + protected ContentRepository_Tests() { _cmsKitTestData = GetRequiredService(); _contentRepository = GetRequiredService(); diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/TagRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/TagRepository_Test.cs new file mode 100644 index 0000000000..2843c864ef --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Tags/TagRepository_Test.cs @@ -0,0 +1,17 @@ +using Volo.Abp.Modularity; + +namespace Volo.CmsKit.Tags +{ + public abstract class TagRepository_Test : CmsKitTestBase + where TStartupModule : IAbpModule + { + private readonly CmsKitTestData _cmsKitTestData; + private readonly ITagRepository _tagRepository; + + protected TagRepository_Test() + { + _cmsKitTestData = GetRequiredService(); + _tagRepository = GetRequiredService(); + } + } +} \ No newline at end of file