mirror of https://github.com/abpframework/abp.git
committed by
GitHub
29 changed files with 623 additions and 14 deletions
@ -0,0 +1,18 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.2</TargetFramework> |
|||
|
|||
<IsPackable>false</IsPackable> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Blogging.EntityFrameworkCore.Tests\Volo.Blogging.EntityFrameworkCore.Tests.csproj" /> |
|||
<ProjectReference Include="..\Volo.Blogging.TestBase\Volo.Blogging.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public abstract class BloggingDomainTestBase : BloggingTestBase<BloggingTestBaseModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
[DependsOn( |
|||
typeof(BloggingEntityFrameworkCoreTestModule), |
|||
typeof(BloggingTestBaseModule) |
|||
)] |
|||
public class BloggingDomainTestModule : AbpModule |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Shouldly; |
|||
using Volo.Blogging.Blogs; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class Blog_Tests |
|||
{ |
|||
[Theory] |
|||
[InlineData("aaa")] |
|||
[InlineData("bbb")] |
|||
public void SetName(string name) |
|||
{ |
|||
var blog = new Blog(Guid.NewGuid(), "test blog", "test"); |
|||
blog.SetName(name); |
|||
blog.Name.ShouldBe(name); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData("aaa")] |
|||
[InlineData("bbb")] |
|||
public void SetShortName(string name) |
|||
{ |
|||
var blog = new Blog(Guid.NewGuid(), "test blog", "test"); |
|||
blog.SetShortName(name); |
|||
blog.ShortName.ShouldBe(name); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Shouldly; |
|||
using Volo.Blogging.Comments; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class Comment_Tests |
|||
{ |
|||
[Theory] |
|||
[InlineData("aaa")] |
|||
[InlineData("bbb")] |
|||
public void SetText(string text) |
|||
{ |
|||
var comment = new Comment(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "good"); |
|||
comment.SetText(text); |
|||
comment.Text.ShouldBe(text); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,65 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Shouldly; |
|||
using Volo.Blogging.Comments; |
|||
using Volo.Blogging.Posts; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class Post_Tests |
|||
{ |
|||
[Fact] |
|||
public void IncreaseReadCount() |
|||
{ |
|||
var post = new Post(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "abp", "⊙o⊙", "abp.io"); |
|||
post.IncreaseReadCount(); |
|||
post.ReadCount.ShouldBe(1); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData("aaa")] |
|||
[InlineData("bbb")] |
|||
public void SetTitle(string title) |
|||
{ |
|||
var post = new Post(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "abp", "⊙o⊙", "abp.io"); |
|||
post.SetTitle(title); |
|||
post.Title.ShouldBe(title); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData("aaa")] |
|||
[InlineData("bbb")] |
|||
public void SetUrl(string url) |
|||
{ |
|||
var post = new Post(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "abp", "⊙o⊙", "abp.io"); |
|||
post.SetUrl(url); |
|||
post.Url.ShouldBe(url); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AddTag() |
|||
{ |
|||
var post = new Post(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "abp", "⊙o⊙", "abp.io"); |
|||
var tagId = Guid.NewGuid(); |
|||
post.AddTag(tagId); |
|||
post.Tags.ShouldContain(x => x.TagId == tagId); |
|||
} |
|||
|
|||
|
|||
[Fact] |
|||
public void RemoveTag() |
|||
{ |
|||
var post = new Post(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid(), "abp", "⊙o⊙", "abp.io"); |
|||
var tagId = Guid.NewGuid(); |
|||
post.AddTag(tagId); |
|||
|
|||
post.Tags.ShouldContain(x => x.TagId == tagId); |
|||
|
|||
post.RemoveTag(tagId); |
|||
post.Tags.ShouldNotContain(x => x.TagId == tagId); |
|||
} |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,64 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Shouldly; |
|||
using Volo.Blogging.Tagging; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class Tag_Tests |
|||
{ |
|||
[Theory] |
|||
[InlineData("aaa")] |
|||
[InlineData("bbb")] |
|||
public void SetName(string name) |
|||
{ |
|||
var tag = new Tag(Guid.NewGuid(), "abp", 0, "abp tag"); |
|||
tag.SetName(name); |
|||
tag.Name.ShouldBe(name); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(1)] |
|||
[InlineData(2)] |
|||
[InlineData(3)] |
|||
public void IncreaseUsageCount(int number) |
|||
{ |
|||
var tag = new Tag(Guid.NewGuid(), "abp", 0, "abp tag"); |
|||
tag.IncreaseUsageCount(number); |
|||
tag.UsageCount.ShouldBe(number); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData(1)] |
|||
[InlineData(2)] |
|||
[InlineData(3)] |
|||
public void DecreaseUsageCount(int number) |
|||
{ |
|||
var tag = new Tag(Guid.NewGuid(), "abp", 10, "abp tag"); |
|||
tag.DecreaseUsageCount(number); |
|||
tag.UsageCount.ShouldBe(10 - number); |
|||
} |
|||
|
|||
[Fact] |
|||
public void DecreaseUsageCount_Should_Greater_ThanOrEqual_Zero() |
|||
{ |
|||
var tag = new Tag(Guid.NewGuid(), "abp", 10, "abp tag"); |
|||
tag.DecreaseUsageCount(100); |
|||
tag.UsageCount.ShouldBe(0); |
|||
} |
|||
|
|||
[Theory] |
|||
[InlineData("aaa")] |
|||
[InlineData("bbb")] |
|||
public void SetDescription(string description) |
|||
{ |
|||
var tag = new Tag(Guid.NewGuid(), "abp", 0, "abp tag"); |
|||
tag.SetDescription(description); |
|||
tag.Description.ShouldBe(description); |
|||
} |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,71 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq.Expressions; |
|||
using System.Text; |
|||
using Shouldly; |
|||
using Volo.Abp.Users; |
|||
using Volo.Blogging.Users; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class BlogUser_Test |
|||
{ |
|||
[Fact] |
|||
public void Update() |
|||
{ |
|||
var userId = Guid.NewGuid(); |
|||
var tenantId = Guid.NewGuid(); |
|||
var blogUser = new BlogUser(new UserData(userId, "bob lee", "boblee@volosoft.com", "lee", "bob", true, |
|||
"123456", true, tenantId)); |
|||
var userData = new UserData(userId, "lee bob", "leebob@volosoft.com", "bob", "lee", false, |
|||
"654321", false, tenantId); |
|||
|
|||
blogUser.Update(userData); |
|||
|
|||
blogUser.Equals(new BlogUser(userData)).ShouldBeTrue(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_User_Id_Must_Equals() |
|||
{ |
|||
var userId = Guid.NewGuid(); |
|||
var tenantId = Guid.NewGuid(); |
|||
var blogUser = new BlogUser(new UserData(userId, "bob lee", "boblee@volosoft.com", "lee", "bob", true, |
|||
"123456", true, tenantId)); |
|||
|
|||
var userData = new UserData(Guid.NewGuid(), "lee bob", "leebob@volosoft.com", "bob", "lee", false, |
|||
"654321", false, tenantId); |
|||
|
|||
Assert.Throws<ArgumentException>(() => blogUser.Update(userData)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Update_Tenant_Id_Must_Equals() |
|||
{ |
|||
var userId = Guid.NewGuid(); |
|||
var tenantId = Guid.NewGuid(); |
|||
var blogUser = new BlogUser(new UserData(userId, "bob lee", "boblee@volosoft.com", "lee", "bob", true, |
|||
"123456", true, tenantId)); |
|||
|
|||
var userData = new UserData(userId, "lee bob", "leebob@volosoft.com", "bob", "lee", false, |
|||
"654321", false, Guid.NewGuid()); |
|||
|
|||
Assert.Throws<ArgumentException>(() => blogUser.Update(userData)); |
|||
} |
|||
|
|||
[Fact] |
|||
public void BlogUserEquals() |
|||
{ |
|||
var userId = Guid.NewGuid(); |
|||
var tenantId = Guid.NewGuid(); |
|||
var blogUser = new BlogUser(new UserData(userId, "bob lee", "john@volosoft.com", "lee", "bob", true, |
|||
"123456", true, tenantId)); |
|||
|
|||
var blogUser2= new BlogUser(new UserData(userId, "bob lee", "john@volosoft.com", "lee", "bob", true, |
|||
"123456", true, tenantId)); |
|||
|
|||
blogUser.Equals(blogUser2).ShouldBeTrue(); |
|||
} |
|||
} |
|||
} |
|||
@ -1,9 +1,8 @@ |
|||
using Volo.Blogging.EntityFrameworkCore; |
|||
using Volo.Blogging.Blogs; |
|||
|
|||
namespace Volo.Blogging.Blogs |
|||
namespace Volo.Blogging |
|||
{ |
|||
public class BlogRepository_Tests : BlogRepository_Tests<BloggingEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Blogging.Comments; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class CommentRepository_Tests : CommentRepository_Tests<BloggingEntityFrameworkCoreTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Blogging.Posts; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class PostRepository_Tests : PostRepository_Tests<BloggingEntityFrameworkCoreTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Blogging.Tagging; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class TagRepository_Tests : TagRepository_Tests<BloggingEntityFrameworkCoreTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.2</TargetFramework> |
|||
|
|||
<IsPackable>false</IsPackable> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> |
|||
<PackageReference Include="Mongo2Go" Version="2.2.8" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Blogging.MongoDB\Volo.Blogging.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\Volo.Blogging.TestBase\Volo.Blogging.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Blogging.Blogs; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class BlogRepository_Tests : BlogRepository_Tests<BloggingMongoDBTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Blogging.Comments; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class CommentRepository_Tests : CommentRepository_Tests<BloggingMongoDBTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using Mongo2Go; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Blogging.MongoDB; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
[DependsOn( |
|||
typeof(BloggingTestBaseModule), |
|||
typeof(BloggingMongoDbModule) |
|||
)] |
|||
public class BloggingMongoDBTestModule : AbpModule |
|||
{ |
|||
private MongoDbRunner _mongoDbRunner; |
|||
|
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
_mongoDbRunner = MongoDbRunner.Start(); |
|||
|
|||
Configure<DbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = _mongoDbRunner.ConnectionString; |
|||
}); |
|||
} |
|||
|
|||
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|||
{ |
|||
_mongoDbRunner.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Blogging.Posts; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class PostRepository_Tests : PostRepository_Tests<BloggingMongoDBTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Volo.Blogging.Tagging; |
|||
|
|||
namespace Volo.Blogging |
|||
{ |
|||
public class TagRepository_Tests : TagRepository_Tests<BloggingMongoDBTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,54 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging.Comments |
|||
{ |
|||
public abstract class CommentRepository_Tests<TStartupModule> : BloggingTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected ICommentRepository CommentRepository { get; } |
|||
protected BloggingTestData BloggingTestData { get; } |
|||
|
|||
protected CommentRepository_Tests() |
|||
{ |
|||
CommentRepository = GetRequiredService<ICommentRepository>(); |
|||
BloggingTestData = GetRequiredService<BloggingTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListOfPostAsync() |
|||
{ |
|||
var comments = await CommentRepository.GetListOfPostAsync(BloggingTestData.Blog1Post1Id); |
|||
comments.ShouldNotBeNull(); |
|||
comments.Count.ShouldBe(2); |
|||
comments.ShouldAllBe(x => x.PostId == BloggingTestData.Blog1Post1Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetCommentCountOfPostAsync() |
|||
{ |
|||
var count = await CommentRepository.GetCommentCountOfPostAsync(BloggingTestData.Blog1Post1Id); |
|||
count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetRepliesOfComment() |
|||
{ |
|||
var comment = await CommentRepository.GetRepliesOfComment(BloggingTestData.Blog1Post1Comment1Id); |
|||
comment.ShouldNotBeNull(); |
|||
comment.ShouldContain(x => x.Id == BloggingTestData.Blog1Post1Comment2Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteOfPost() |
|||
{ |
|||
await CommentRepository.DeleteOfPost(BloggingTestData.Blog1Post1Id); |
|||
(await CommentRepository.GetListAsync()).ShouldBeEmpty(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging.Posts |
|||
{ |
|||
public abstract class PostRepository_Tests<TStartupModule> : BloggingTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected IPostRepository PostRepository { get; } |
|||
protected BloggingTestData BloggingTestData { get; } |
|||
|
|||
protected PostRepository_Tests() |
|||
{ |
|||
PostRepository = GetRequiredService<IPostRepository>(); |
|||
BloggingTestData = GetRequiredService<BloggingTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListOfPostAsync() |
|||
{ |
|||
var posts = await PostRepository.GetPostsByBlogId(BloggingTestData.Blog1Id); |
|||
posts.ShouldNotBeNull(); |
|||
posts.Count.ShouldBe(2); |
|||
posts.ShouldContain(x => x.Id == BloggingTestData.Blog1Post1Id); |
|||
posts.ShouldContain(x => x.Id == BloggingTestData.Blog1Post2Id); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetPostByUrl() |
|||
{ |
|||
var post = await PostRepository.GetPostByUrl(BloggingTestData.Blog1Id, "url"); |
|||
post.ShouldNotBeNull(); |
|||
post.Url.ShouldBe("url"); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,73 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Blogging.Tagging |
|||
{ |
|||
public abstract class TagRepository_Tests<TStartupModule> : BloggingTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected ITagRepository TagRepository { get; } |
|||
protected BloggingTestData BloggingTestData { get; } |
|||
|
|||
protected TagRepository_Tests() |
|||
{ |
|||
TagRepository = GetRequiredService<ITagRepository>(); |
|||
BloggingTestData = GetRequiredService<BloggingTestData>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync() |
|||
{ |
|||
var tags = await TagRepository.GetListAsync(BloggingTestData.Blog1Id); |
|||
tags.ShouldNotBeNull(); |
|||
tags.Count.ShouldBe(2); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetByNameAsync() |
|||
{ |
|||
var tag = await TagRepository.GetByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name); |
|||
tag.ShouldNotBeNull(); |
|||
tag.Name.ShouldBe(BloggingTestData.Tag1Name); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task FindByNameAsync() |
|||
{ |
|||
var tag = await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name); |
|||
tag.ShouldNotBeNull(); |
|||
tag.Name.ShouldBe(BloggingTestData.Tag1Name); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetListAsync2() |
|||
{ |
|||
var tagIds = (await TagRepository.GetListAsync()).Select(x => x.Id).ToList(); |
|||
var tags = await TagRepository.GetListAsync(tagIds); |
|||
tags.ShouldNotBeNull(); |
|||
tags.Count.ShouldBe(tagIds.Count); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DecreaseUsageCountOfTags() |
|||
{ |
|||
var tag = await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name); |
|||
var usageCount = tag.UsageCount; |
|||
|
|||
TagRepository.DecreaseUsageCountOfTags(new List<Guid>() |
|||
{ |
|||
tag.Id |
|||
}); |
|||
|
|||
await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name); |
|||
(await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name)).UsageCount |
|||
.ShouldBe(usageCount - 1); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Blogging.Users |
|||
{ |
|||
public abstract class BlogUserRepository_Tests<TStartupModule> : BloggingTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue