From 055a7a91c863213250f6d6d5ab4988105002196f Mon Sep 17 00:00:00 2001 From: Ahmet Date: Mon, 28 Dec 2020 15:12:29 +0300 Subject: [PATCH] Added content repository tests --- .../Contents/ContentRepository_Test.cs | 9 +++ .../Contents/ContentRepository_Test.cs | 11 ++++ .../Contents/ContentRepository_Tests.cs | 64 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Contents/ContentRepository_Test.cs create mode 100644 modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Contents/ContentRepository_Test.cs create mode 100644 modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs diff --git a/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Contents/ContentRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Contents/ContentRepository_Test.cs new file mode 100644 index 0000000000..72f0b47485 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/Contents/ContentRepository_Test.cs @@ -0,0 +1,9 @@ +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.EntityFrameworkCore.Contents +{ + public class ContentRepository_Test : ContentRepository_Tests + { + + } +} \ No newline at end of file diff --git a/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Contents/ContentRepository_Test.cs b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Contents/ContentRepository_Test.cs new file mode 100644 index 0000000000..bb467a4844 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.MongoDB.Tests/MongoDB/Contents/ContentRepository_Test.cs @@ -0,0 +1,11 @@ +using Volo.CmsKit.Contents; +using Xunit; + +namespace Volo.CmsKit.MongoDB.Contents +{ + [Collection(MongoTestCollection.Name)] + public class ContentRepository_Test : ContentRepository_Tests + { + + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..6cec5786e2 --- /dev/null +++ b/modules/cms-kit/test/Volo.CmsKit.TestBase/Contents/ContentRepository_Tests.cs @@ -0,0 +1,64 @@ +using System; +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 +{ + public abstract class ContentRepository_Tests : CmsKitTestBase + where TStartupModule : IAbpModule + { + private readonly CmsKitTestData _cmsKitTestData; + private readonly IContentRepository _contentRepository; + + public ContentRepository_Tests() + { + _cmsKitTestData = GetRequiredService(); + _contentRepository = GetRequiredService(); + } + + [Theory] + [InlineData("Lyrics", "1", "First things first")] + [InlineData("LyricsAlso", "2", "Second thing second")] + public async Task ShouldGetAsync(string entityType, string entityId, string contentStartsWith = null) + { + var content = await _contentRepository.GetAsync(entityType, entityId); + + content.ShouldNotBeNull(); + + if (contentStartsWith != null) + { + content.Value.ShouldStartWith(contentStartsWith); + } + } + + [Fact] + public async Task ShouldNotGetAsync() + { + Should.Throw( + async () + => + await _contentRepository.GetAsync("not_exist_entity", Guid.NewGuid().ToString())); + } + + [Fact] + public async Task ShouldFindAsync() + { + var content = + await _contentRepository.FindAsync(_cmsKitTestData.Content_1_EntityType, _cmsKitTestData.Content_1_Id); + + content.ShouldNotBeNull(); + } + + [Fact] + public async Task ShouldNotFindAsync() + { + var content = await _contentRepository.FindAsync("not_exist_entity", Guid.NewGuid().ToString()); + + content.ShouldBeNull(); + } + } +} \ No newline at end of file