mirror of https://github.com/abpframework/abp.git
13 changed files with 293 additions and 92 deletions
@ -0,0 +1,101 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using NSubstitute; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.Users; |
||||
|
using Volo.CmsKit.Public.Comments; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.CmsKit.Comments |
||||
|
{ |
||||
|
public class CommentPublicAppService_Tests : CmsKitApplicationTestBase |
||||
|
{ |
||||
|
private readonly ICommentPublicAppService _commentAppService; |
||||
|
private ICurrentUser _currentUser; |
||||
|
private readonly CmsKitTestData _cmsKitTestData; |
||||
|
|
||||
|
public CommentPublicAppService_Tests() |
||||
|
{ |
||||
|
_commentAppService = GetRequiredService<ICommentPublicAppService>(); |
||||
|
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); |
||||
|
} |
||||
|
|
||||
|
protected override void AfterAddApplication(IServiceCollection services) |
||||
|
{ |
||||
|
_currentUser = Substitute.For<ICurrentUser>(); |
||||
|
services.AddSingleton(_currentUser); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetAllForEntityAsync() |
||||
|
{ |
||||
|
var list = await _commentAppService.GetAllForEntityAsync(_cmsKitTestData.EntityType1, _cmsKitTestData.EntityId1); |
||||
|
|
||||
|
list.Items.Count.ShouldBe(2); |
||||
|
list.Items.First().Replies.Count.ShouldBe(2); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task CreateAsync() |
||||
|
{ |
||||
|
_currentUser.Id.Returns(_cmsKitTestData.User2Id); |
||||
|
|
||||
|
var newComment = await _commentAppService.CreateAsync(new CreateCommentInput |
||||
|
{ |
||||
|
EntityId = _cmsKitTestData.EntityId1, |
||||
|
EntityType = _cmsKitTestData.EntityType1, |
||||
|
RepliedCommentId = null, |
||||
|
Text = "newComment" |
||||
|
}); |
||||
|
|
||||
|
UsingDbContext(context => |
||||
|
{ |
||||
|
var comments = context.Comments.Where(x => |
||||
|
x.EntityId == _cmsKitTestData.EntityId1 && x.EntityType == _cmsKitTestData.EntityType1).ToList(); |
||||
|
|
||||
|
comments |
||||
|
.Any(c=>c.Id == newComment.Id && c.CreatorId == newComment.CreatorId && c.Text == "newComment") |
||||
|
.ShouldBeTrue(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task UpdateAsync() |
||||
|
{ |
||||
|
_currentUser.Id.Returns(_cmsKitTestData.User1Id); |
||||
|
|
||||
|
await _commentAppService.UpdateAsync(_cmsKitTestData.CommentWithChildId, new UpdateCommentInput |
||||
|
{ |
||||
|
Text = "I'm Updated" |
||||
|
}); |
||||
|
|
||||
|
UsingDbContext(context => |
||||
|
{ |
||||
|
var comment = context.Comments.Single(x => |
||||
|
x.Id == _cmsKitTestData.CommentWithChildId); |
||||
|
|
||||
|
comment.Text.ShouldBe("I'm Updated"); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task DeleteAsync() |
||||
|
{ |
||||
|
_currentUser.Id.Returns(_cmsKitTestData.User1Id); |
||||
|
|
||||
|
await _commentAppService.DeleteAsync(_cmsKitTestData.CommentWithChildId); |
||||
|
|
||||
|
UsingDbContext(context => |
||||
|
{ |
||||
|
var comment = context.Comments.FirstOrDefault(x => |
||||
|
x.Id == _cmsKitTestData.CommentWithChildId); |
||||
|
|
||||
|
comment.ShouldBeNull(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,21 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Volo.CmsKit.Samples |
|
||||
{ |
|
||||
public class SampleManager_Tests : CmsKitDomainTestBase |
|
||||
{ |
|
||||
//private readonly SampleManager _sampleManager;
|
|
||||
|
|
||||
public SampleManager_Tests() |
|
||||
{ |
|
||||
//_sampleManager = GetRequiredService<SampleManager>();
|
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task Method1Async() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.CmsKit.Comments; |
||||
|
|
||||
|
namespace Volo.CmsKit.EntityFrameworkCore.Comments |
||||
|
{ |
||||
|
public class CommentRepository_Tests : CommentRepository_Tests<CmsKitEntityFrameworkCoreTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -1,12 +0,0 @@ |
|||||
using Volo.CmsKit.Samples; |
|
||||
|
|
||||
namespace Volo.CmsKit.EntityFrameworkCore.Samples |
|
||||
{ |
|
||||
public class SampleRepository_Tests : SampleRepository_Tests<CmsKitEntityFrameworkCoreTestModule> |
|
||||
{ |
|
||||
/* Don't write custom repository tests here, instead write to |
|
||||
* the base class. |
|
||||
* One exception can be some specific tests related to EF core. |
|
||||
*/ |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.CmsKit.Comments; |
||||
|
|
||||
|
namespace Volo.CmsKit.MongoDB.Comments |
||||
|
{ |
||||
|
public class CommentRepository_Tests : CommentRepository_Tests<CmsKitMongoDbTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -1,14 +0,0 @@ |
|||||
using Volo.CmsKit.Samples; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Volo.CmsKit.MongoDB.Samples |
|
||||
{ |
|
||||
[Collection(MongoTestCollection.Name)] |
|
||||
public class SampleRepository_Tests : SampleRepository_Tests<CmsKitMongoDbTestModule> |
|
||||
{ |
|
||||
/* Don't write custom repository tests here, instead write to |
|
||||
* the base class. |
|
||||
* One exception can be some specific tests related to MongoDB. |
|
||||
*/ |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.CmsKit |
||||
|
{ |
||||
|
public class CmsKitTestData : ISingletonDependency |
||||
|
{ |
||||
|
public Guid User1Id { get; } = Guid.NewGuid(); |
||||
|
|
||||
|
public Guid User2Id { get; } = Guid.NewGuid(); |
||||
|
|
||||
|
public Guid CommentWithChildId { get; } = Guid.NewGuid(); |
||||
|
|
||||
|
public string EntityType1 { get; } = "EntityName1"; |
||||
|
|
||||
|
public string EntityType2 { get; } = "EntityName2"; |
||||
|
|
||||
|
public string EntityId1 { get; } = "1"; |
||||
|
|
||||
|
public string EntityId2 { get; } = "2"; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,44 @@ |
|||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.CmsKit.Comments |
||||
|
{ |
||||
|
public abstract class CommentRepository_Tests<TStartupModule> : CmsKitTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
private readonly CmsKitTestData _cmsKitTestData; |
||||
|
private readonly ICommentRepository _commentRepository; |
||||
|
|
||||
|
public CommentRepository_Tests() |
||||
|
{ |
||||
|
_cmsKitTestData = GetRequiredService<CmsKitTestData>(); |
||||
|
_commentRepository = GetRequiredService<ICommentRepository>(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task GetListWithAuthorsAsync() |
||||
|
{ |
||||
|
var list = await _commentRepository.GetListWithAuthorsAsync(_cmsKitTestData.EntityType1, |
||||
|
_cmsKitTestData.EntityId1); |
||||
|
|
||||
|
list.Count.ShouldBe(4); |
||||
|
list.Any(x=>x.Comment == null).ShouldBeFalse(); |
||||
|
list.Any(x=>x.Author == null).ShouldBeFalse(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task DeleteAsync() |
||||
|
{ |
||||
|
await _commentRepository.DeleteAsync(_cmsKitTestData.CommentWithChildId); |
||||
|
|
||||
|
var list = await _commentRepository.GetListAsync(); |
||||
|
|
||||
|
list.Any(x=> |
||||
|
x.Id == _cmsKitTestData.CommentWithChildId || x.RepliedCommentId == _cmsKitTestData.CommentWithChildId) |
||||
|
.ShouldBeFalse(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,27 +0,0 @@ |
|||||
using System.Threading.Tasks; |
|
||||
using Volo.Abp.Modularity; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Volo.CmsKit.Samples |
|
||||
{ |
|
||||
/* Write your custom repository tests like that, in this project, as abstract classes. |
|
||||
* Then inherit these abstract classes from EF Core & MongoDB test projects. |
|
||||
* In this way, both database providers are tests with the same set tests. |
|
||||
*/ |
|
||||
public abstract class SampleRepository_Tests<TStartupModule> : CmsKitTestBase<TStartupModule> |
|
||||
where TStartupModule : IAbpModule |
|
||||
{ |
|
||||
//private readonly ISampleRepository _sampleRepository;
|
|
||||
|
|
||||
protected SampleRepository_Tests() |
|
||||
{ |
|
||||
//_sampleRepository = GetRequiredService<ISampleRepository>();
|
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task Method1Async() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue