Browse Source

Add blog entity unit tests.

pull/967/head
maliming 7 years ago
parent
commit
a6c744cd67
  1. 9
      modules/blogging/Volo.Blogging.sln
  2. 7
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/Tag.cs
  3. 2
      modules/blogging/test/Volo.Blogging.Application.Tests/Volo.Blogging.Application.Tests.csproj
  4. 18
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo.Blogging.Domain.Tests.csproj
  5. 11
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/BloggingDomainTestBase.cs
  6. 12
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/BloggingDomainTestModule.cs
  7. 32
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Blogs/Blog_Tests.cs
  8. 22
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Comments/Comment_Tests.cs
  9. 65
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Posts/Post_Tests.cs
  10. 64
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Tagging/Tag_Tests.cs
  11. 71
      modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Users/BlogUser_Test.cs
  12. 7
      modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Blogs/BlogRepository_Tests.cs
  13. 10
      modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Comments/CommentRepository_Tests.cs
  14. 6
      modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs
  15. 10
      modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Posts/PostRepository_Tests.cs
  16. 10
      modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Tagging/TagRepository_Tests.cs
  17. 2
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj
  18. 10
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Blogs/BlogRepository_Tests.cs
  19. 10
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Comments/CommentRepository_Tests.cs
  20. 10
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/BloggingMongoDBTestModule.cs
  21. 10
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Posts/PostRepository_Tests.cs
  22. 10
      modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Tagging/TagRepository_Tests.cs
  23. 2
      modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/Tagging/TagRepository_Tests.cs

9
modules/blogging/Volo.Blogging.sln

@ -39,7 +39,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Blogging.MongoDB", "sr
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.BloggingTestApp.MongoDb", "app\Volo.BloggingTestApp.MongoDb\Volo.BloggingTestApp.MongoDb.csproj", "{4C818374-2DE8-422F-8585-975E8366DB26}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Blogging.MongoDB.Tests", "test\Volo.Blogging.MongoDB.Tests\Volo.Blogging.MongoDB.Tests.csproj", "{0A29F64C-11F1-40B6-8E6D-91E86823775E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Blogging.MongoDB.Tests", "test\Volo.Blogging.MongoDB.Tests\Volo.Blogging.MongoDB.Tests.csproj", "{0A29F64C-11F1-40B6-8E6D-91E86823775E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Blogging.Domain.Tests", "test\Volo.Blogging.Domain.Tests\Volo.Blogging.Domain.Tests.csproj", "{B6D7EF20-9921-490A-AA95-47E3E174DC9B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -111,6 +113,10 @@ Global
{0A29F64C-11F1-40B6-8E6D-91E86823775E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0A29F64C-11F1-40B6-8E6D-91E86823775E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A29F64C-11F1-40B6-8E6D-91E86823775E}.Release|Any CPU.Build.0 = Release|Any CPU
{B6D7EF20-9921-490A-AA95-47E3E174DC9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6D7EF20-9921-490A-AA95-47E3E174DC9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6D7EF20-9921-490A-AA95-47E3E174DC9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6D7EF20-9921-490A-AA95-47E3E174DC9B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -132,6 +138,7 @@ Global
{98C2D36A-F874-405D-8565-9CE59438E879} = {42BF26EF-B8C7-42DC-9FFB-3653109B7776}
{4C818374-2DE8-422F-8585-975E8366DB26} = {EB4FB44A-FE39-4245-9DAD-D6437BCE3870}
{0A29F64C-11F1-40B6-8E6D-91E86823775E} = {25B3A516-5C0D-42E3-9294-E8A9346CEE4B}
{B6D7EF20-9921-490A-AA95-47E3E174DC9B} = {25B3A516-5C0D-42E3-9294-E8A9346CEE4B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F2BAE819-78D4-407A-9201-22473B2850B0}

7
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/Tag.cs

@ -44,6 +44,13 @@ namespace Volo.Blogging.Tagging
{
return;
}
if (UsageCount - number <= 0)
{
UsageCount = 0;
return;
}
UsageCount -= number;
}

2
modules/blogging/test/Volo.Blogging.Application.Tests/Volo.Blogging.Application.Tests.csproj

@ -13,7 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Blogging.Application\Volo.Blogging.Application.csproj" />
<ProjectReference Include="..\Volo.Blogging.EntityFrameworkCore.Tests\Volo.Blogging.EntityFrameworkCore.Tests.csproj" />
<ProjectReference Include="..\Volo.Blogging.Domain.Tests\Volo.Blogging.Domain.Tests.csproj" />
</ItemGroup>
</Project>

18
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo.Blogging.Domain.Tests.csproj

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

11
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/BloggingDomainTestBase.cs

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Blogging
{
public abstract class BloggingDomainTestBase : BloggingTestBase<BloggingTestBaseModule>
{
}
}

12
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/BloggingDomainTestModule.cs

@ -0,0 +1,12 @@
using Volo.Abp.Modularity;
namespace Volo.Blogging
{
[DependsOn(
typeof(BloggingEntityFrameworkCoreTestModule),
typeof(BloggingTestBaseModule)
)]
public class BloggingDomainTestModule : AbpModule
{
}
}

32
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Blogs/Blog_Tests.cs

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

22
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Comments/Comment_Tests.cs

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

65
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Posts/Post_Tests.cs

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

64
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Tagging/Tag_Tests.cs

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

71
modules/blogging/test/Volo.Blogging.Domain.Tests/Volo/Abp/Blogging/Users/BlogUser_Test.cs

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

7
modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Blogs/BlogRepository_Tests.cs

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

10
modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Comments/CommentRepository_Tests.cs

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Blogging.EntityFrameworkCore;
using Volo.Blogging.Comments;
namespace Volo.Blogging.Comments
namespace Volo.Blogging
{
public class CommentRepository_Tests : CommentRepository_Tests<BloggingEntityFrameworkCoreTestModule>
{
}
}
}

6
modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs

@ -2,12 +2,12 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Modularity;
using Volo.Blogging.EntityFrameworkCore;
namespace Volo.Blogging.EntityFrameworkCore
namespace Volo.Blogging
{
[DependsOn(
typeof(BloggingEntityFrameworkCoreModule),
@ -49,4 +49,4 @@ namespace Volo.Blogging.EntityFrameworkCore
_sqliteConnection.Dispose();
}
}
}
}

10
modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Posts/PostRepository_Tests.cs

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Blogging.EntityFrameworkCore;
using Volo.Blogging.Posts;
namespace Volo.Blogging.Posts
namespace Volo.Blogging
{
public class PostRepository_Tests : PostRepository_Tests<BloggingEntityFrameworkCoreTestModule>
{
}
}
}

10
modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/Tagging/TagRepository_Tests.cs

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Blogging.EntityFrameworkCore;
using Volo.Blogging.Tagging;
namespace Volo.Blogging.Tagging
namespace Volo.Blogging
{
public class TagRepository_Tests : TagRepository_Tests<BloggingEntityFrameworkCoreTestModule>
{
}
}
}

2
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo.Blogging.MongoDB.Tests.csproj

@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Mongo2Go" Version="2.2.8" />
</ItemGroup>

10
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Blogs/BlogRepository_Tests.cs

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Blogging.Blogs;
using Volo.Blogging.Blogs;
namespace Volo.Blogging.MongoDB
namespace Volo.Blogging
{
public class BlogRepository_Tests : BlogRepository_Tests<BloggingMongoDBTestModule>
{
}
}
}

10
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Comments/CommentRepository_Tests.cs

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Blogging.Comments;
using Volo.Blogging.Comments;
namespace Volo.Blogging.MongoDB
namespace Volo.Blogging
{
public class CommentRepository_Tests : CommentRepository_Tests<BloggingMongoDBTestModule>
{
}
}
}

10
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/MongoDB/BloggingMongoDBTestModule.cs

@ -1,12 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
using Mongo2Go;
using Mongo2Go;
using Volo.Abp;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
using Volo.Blogging.MongoDB;
namespace Volo.Blogging.MongoDB
namespace Volo.Blogging
{
[DependsOn(
typeof(BloggingTestBaseModule),
@ -31,4 +29,4 @@ namespace Volo.Blogging.MongoDB
_mongoDbRunner.Dispose();
}
}
}
}

10
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Posts/PostRepository_Tests.cs

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Blogging.Posts;
using Volo.Blogging.Posts;
namespace Volo.Blogging.MongoDB.Tests.Volo.Blogging.Posts
namespace Volo.Blogging
{
public class PostRepository_Tests : PostRepository_Tests<BloggingMongoDBTestModule>
{
}
}
}

10
modules/blogging/test/Volo.Blogging.MongoDB.Tests/Volo/Blogging/Tagging/TagRepository_Tests.cs

@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Blogging.Tagging;
using Volo.Blogging.Tagging;
namespace Volo.Blogging.MongoDB
namespace Volo.Blogging
{
public class TagRepository_Tests : TagRepository_Tests<BloggingMongoDBTestModule>
{
}
}
}

2
modules/blogging/test/Volo.Blogging.TestBase/Volo/Blogging/Tagging/TagRepository_Tests.cs

@ -65,7 +65,7 @@ namespace Volo.Blogging.Tagging
tag.Id
});
var qq = await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name);
await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name);
(await TagRepository.FindByNameAsync(BloggingTestData.Blog1Id, BloggingTestData.Tag1Name)).UsageCount
.ShouldBe(usageCount - 1);
}

Loading…
Cancel
Save