diff --git a/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Pages/PageRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Pages/PageRepository_Test.cs new file mode 100644 index 0000000000..d78d10911c --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Pages/PageRepository_Test.cs @@ -0,0 +1,9 @@ +using Volo.CmsKit.Pages; + +namespace Volo.CmsKit.EntityFrameworkCore.Pages +{ + public class PageRepository_Test : PageRepository_Test + { + + } +} \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Pages/PageRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Pages/PageRepository_Test.cs new file mode 100644 index 0000000000..1a379f4e95 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Pages/PageRepository_Test.cs @@ -0,0 +1,11 @@ +using Volo.CmsKit.Pages; +using Xunit; + +namespace Volo.CmsKit.MongoDB.Pages +{ + [Collection(MongoTestCollection.Name)] + public class PageRepository_Test : PageRepository_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 8a1ab616d1..b0f820a4f2 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs @@ -7,6 +7,7 @@ using Volo.Abp.MultiTenancy; using Volo.Abp.Users; using Volo.CmsKit.Comments; using Volo.CmsKit.Contents; +using Volo.CmsKit.Pages; using Volo.CmsKit.Ratings; using Volo.CmsKit.Reactions; using Volo.CmsKit.Tags; @@ -26,7 +27,7 @@ namespace Volo.CmsKit private readonly IContentRepository _contentRepository; private readonly IEntityTagRepository _entityTagRepository; private readonly ITagManager _tagManager; - + private readonly IPageRepository _pageRepository; public CmsKitDataSeedContributor( IGuidGenerator guidGenerator, ICmsUserRepository cmsUserRepository, @@ -37,7 +38,8 @@ namespace Volo.CmsKit ICurrentTenant currentTenant, IContentRepository contentRepository, ITagManager tagManager, - IEntityTagRepository entityTagRepository) + IEntityTagRepository entityTagRepository, + IPageRepository pageRepository) { _guidGenerator = guidGenerator; _cmsUserRepository = cmsUserRepository; @@ -49,6 +51,7 @@ namespace Volo.CmsKit _contentRepository = contentRepository; _tagManager = tagManager; _entityTagRepository = entityTagRepository; + _pageRepository = pageRepository; } public async Task SeedAsync(DataSeedContext context) @@ -66,6 +69,8 @@ namespace Volo.CmsKit await SeedContentsAsync(); await SeedTagsAsync(); + + await SeedPagesAsync(); } } @@ -230,5 +235,20 @@ namespace Volo.CmsKit await _entityTagRepository.InsertAsync(new EntityTag(tagEntity.Id, _cmsKitTestData.Content_2_Id)); } } + + private async Task SeedPagesAsync() + { + 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); + + await _pageRepository.InsertAsync(page2); + await _contentRepository.InsertAsync(page2Content); + } } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs index 6589e79d9c..11aa185ddd 100644 --- a/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs @@ -20,20 +20,40 @@ namespace Volo.CmsKit public string EntityId2 { get; } = "2"; - public string Content_1_EntityType = "Lyrics"; + public string Content_1_EntityType { get; } = "Lyrics"; 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_Id { get; } = "1"; public string[] Content_1_Tags => new string[] {"Imagine Dragons", "Music"}; - public string Content_2_EntityType = "LyricsAlso"; + public string Content_2_EntityType { get; } = "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_Id { get; } = "2"; public string[] Content_2_Tags => new string[] {"Imagine Dragons", "Music", "Most Loved Part"}; + + public string Page_1_Title { get; } = "Imagine Dragons - Believer Lyrics"; + + public string Page_1_Url { get; } = "imagine-dragons-believer-lyrics"; + + public string Page_1_Description { get; } = "You can get the lyrics of the music."; + + public Guid Page_1_Id { get; } = Guid.NewGuid(); + + public string Page_1_Content => Content_1; + + public string Page_2_Title { get; } = "Imagine Dragons - Believer Lyrics (Page 2)"; + + public string Page_2_Url { get; } = "imagine-dragons-believer-lyrics-2"; + + public string Page_2_Description { get; } = "You can get the lyrics of the music."; + + public Guid Page_2_Id { get; } = Guid.NewGuid(); + + public string Page_2_Content => Content_2; } } diff --git a/modules/cms-kit/test/Volo.CmsKit.TestBase/Pages/PageRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.TestBase/Pages/PageRepository_Test.cs new file mode 100644 index 0000000000..68b91f72a9 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Pages/PageRepository_Test.cs @@ -0,0 +1,62 @@ +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Modularity; +using Xunit; + +namespace Volo.CmsKit.Pages +{ + public abstract class PageRepository_Test : CmsKitTestBase + where TStartupModule : IAbpModule + { + private readonly CmsKitTestData _cmsKitTestData; + private readonly IPageRepository _pageRepository; + + protected PageRepository_Test() + { + _cmsKitTestData = GetRequiredService(); + _pageRepository = GetRequiredService(); + } + + [Fact] + public async Task ShouldGetByUrlAsync() + { + var page = await _pageRepository.GetByUrlAsync(_cmsKitTestData.Page_1_Url); + + page.ShouldNotBeNull(); + page.Description.ShouldBe(_cmsKitTestData.Page_1_Description); + } + + [Fact] + public async Task ShouldFindByUrlAsync() + { + var page = await _pageRepository.FindByUrlAsync(_cmsKitTestData.Page_1_Url); + + page.ShouldNotBeNull(); + page.Description.ShouldBe(_cmsKitTestData.Page_1_Description); + } + + [Fact] + public async Task ShouldNotFindByUrlAsync() + { + var page = await _pageRepository.FindByUrlAsync("not-exist-lyrics"); + + page.ShouldBeNull(); + } + + [Fact] + public async Task ShouldBeExistAsync() + { + var page = await _pageRepository.DoesExistAsync(_cmsKitTestData.Page_1_Url); + + page.ShouldBeTrue(); + } + + [Fact] + public async Task ShouldNotBeExistAsync() + { + var page = await _pageRepository.DoesExistAsync("not-exist-lyrics"); + + page.ShouldBeFalse(); + } + } +} \ No newline at end of file