added test page data and pagerepository tests

pull/6875/head
Ahmet 5 years ago
parent 37bff78ced
commit 2964ded7e8

@ -0,0 +1,9 @@
using Volo.CmsKit.Pages;
namespace Volo.CmsKit.EntityFrameworkCore.Pages
{
public class PageRepository_Test : PageRepository_Test<CmsKitEntityFrameworkCoreTestModule>
{
}
}

@ -0,0 +1,11 @@
using Volo.CmsKit.Pages;
using Xunit;
namespace Volo.CmsKit.MongoDB.Pages
{
[Collection(MongoTestCollection.Name)]
public class PageRepository_Test : PageRepository_Test<CmsKitMongoDbTestModule>
{
}
}

@ -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);
}
}
}

@ -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;
}
}

@ -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<TStartupModule> : CmsKitTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private readonly CmsKitTestData _cmsKitTestData;
private readonly IPageRepository _pageRepository;
protected PageRepository_Test()
{
_cmsKitTestData = GetRequiredService<CmsKitTestData>();
_pageRepository = GetRequiredService<IPageRepository>();
}
[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();
}
}
}
Loading…
Cancel
Save