Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
netcoreplus
Commits
71223cfd
Commit
71223cfd
authored
May 29, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
todo : mongodb test
parent
ff43234c
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
350 additions
and
11 deletions
+350
-11
BlogMongoDbDatabaseProvider .cs
Plus.MongoDb.Test/BlogMongoDbDatabaseProvider .cs
+79
-0
BlogMongoDbModule.cs
Plus.MongoDb.Test/BlogMongoDbModule.cs
+19
-0
BlogMongoDbRepositoryBase.cs
Plus.MongoDb.Test/BlogMongoDbRepositoryBase.cs
+45
-0
DbConsts.cs
Plus.MongoDb.Test/DbConsts.cs
+10
-0
Plus.MongoDb.Test.csproj
Plus.MongoDb.Test/Plus.MongoDb.Test.csproj
+20
-0
ArticleRepository.cs
Plus.MongoDb.Test/Repositories/ArticleRepository.cs
+12
-0
Plus.sln
Plus.sln
+12
-5
AppSettings.cs
test/Plus.Core.Tests/Configuration/AppSettings.cs
+2
-2
Article.cs
test/Plus.Core.Tests/Domain/Article.cs
+58
-0
Plus.Core.Tests.csproj
test/Plus.Core.Tests/Plus.Core.Tests.csproj
+4
-0
IArticleRepository.cs
test/Plus.Core.Tests/Repositories/IArticleRepository.cs
+10
-0
ArticleDto.cs
test/Plus.Services.Dto.Test/ArticleDto.cs
+47
-0
IBlogService.Post.cs
test/Plus.Services.Test/Blog/IBlogService.Post.cs
+2
-0
BlogService.Post.cs
test/Plus.Services.Test/Blog/Impl/BlogService.Post.cs
+11
-1
PostController.cs
test/Plus.Web.Tests/Controllers/PostController.cs
+11
-0
Plus.Web.Tests.csproj
test/Plus.Web.Tests/Plus.Web.Tests.csproj
+3
-0
Startup.cs
test/Plus.Web.Tests/Startup.cs
+3
-1
appsettings.json
test/Plus.Web.Tests/appsettings.json
+2
-2
No files found.
Plus.MongoDb.Test/BlogMongoDbDatabaseProvider .cs
0 → 100644
View file @
71223cfd
using
MongoDB.Driver
;
using
Plus.Core.Tests.Configuration
;
using
System.Collections.Generic
;
namespace
Plus.MongoDb.Test
{
public
class
BlogMongoDbDatabaseProvider
:
IMongoDatabaseProvider
{
public
IMongoClient
Client
{
get
;
}
public
IMongoDatabase
Database
{
get
;
}
MongoDatabase
IMongoDatabaseProvider
.
Database
{
get
{
return
null
;
}
}
//public MongoDatabase Database
//{
// get
// {
// var servers = new List<MongoServerAddress>();
// AppSettings.MongoDb.Servers.ForEach(x =>
// {
// servers.Add(new MongoServerAddress(x.Host, x.Port));
// });
// var settings = new MongoClientSettings();
// settings.Servers = servers;
// if (AppSettings.MongoDb.Username.IsNotNullOrEmpty())
// {
// settings.Credential = MongoCredential.CreateCredential("admin", AppSettings.MongoDb.Username, AppSettings.MongoDb.Password);
// }
// if (AppSettings.MongoDb.ConnectionMode.ToLower() == "replicaset")
// {
// settings.ConnectionMode = ConnectionMode.ReplicaSet;
// settings.ReadPreference = new ReadPreference(ReadPreferenceMode.SecondaryPreferred);
// }
// var client = new MongoClient(settings);
// var database = client.GetDatabase(AppSettings.MongoDb.DatabaseName);
// return Database;
// }
//}
public
BlogMongoDbDatabaseProvider
()
{
var
servers
=
new
List
<
MongoServerAddress
>();
AppSettings
.
MongoDb
.
Servers
.
ForEach
(
x
=>
{
servers
.
Add
(
new
MongoServerAddress
(
x
.
Host
,
x
.
Port
));
});
var
settings
=
new
MongoClientSettings
();
settings
.
Servers
=
servers
;
if
(
AppSettings
.
MongoDb
.
Username
.
IsNotNullOrEmpty
())
{
settings
.
Credential
=
MongoCredential
.
CreateCredential
(
"admin"
,
AppSettings
.
MongoDb
.
Username
,
AppSettings
.
MongoDb
.
Password
);
}
if
(
AppSettings
.
MongoDb
.
ConnectionMode
.
ToLower
()
==
"replicaset"
)
{
settings
.
ConnectionMode
=
ConnectionMode
.
ReplicaSet
;
settings
.
ReadPreference
=
new
ReadPreference
(
ReadPreferenceMode
.
SecondaryPreferred
);
}
Client
=
new
MongoClient
(
settings
);
Database
=
Client
.
GetDatabase
(
AppSettings
.
MongoDb
.
DatabaseName
);
}
}
}
\ No newline at end of file
Plus.MongoDb.Test/BlogMongoDbModule.cs
0 → 100644
View file @
71223cfd
using
Plus.Modules
;
using
System.Reflection
;
namespace
Plus.MongoDb.Test
{
[
DependsOn
(
typeof
(
PlusMongoDbModule
))]
public
class
BlogMongoDbModule
:
PlusModule
{
public
override
void
PreInitialize
()
{
IocManager
.
Register
<
BlogMongoDbDatabaseProvider
>();
}
public
override
void
Initialize
()
{
IocManager
.
RegisterAssembly
(
Assembly
.
GetExecutingAssembly
());
}
}
}
\ No newline at end of file
Plus.MongoDb.Test/BlogMongoDbRepositoryBase.cs
0 → 100644
View file @
71223cfd
using
MongoDB.Bson
;
using
MongoDB.Driver
;
using
Plus.Domain.Entities
;
using
Plus.MongoDb.Repositories
;
using
System.Linq
;
namespace
Plus.MongoDb.Test
{
public
abstract
class
BlogMongoDbRepositoryBase
{
private
readonly
BlogMongoDbDatabaseProvider
_blogMongoDbDatabaseProvider
;
public
BlogMongoDbRepositoryBase
(
BlogMongoDbDatabaseProvider
blogMongoDbDatabaseProvider
)
{
_blogMongoDbDatabaseProvider
=
blogMongoDbDatabaseProvider
;
}
public
IMongoDatabase
Database
=>
_blogMongoDbDatabaseProvider
.
Database
;
}
public
abstract
class
BlogMongoDbTakeAutoIncRepositoryBase
<
TEntity
>
:
BlogMongoDbRepositoryBase
<
TEntity
,
ObjectId
>
where
TEntity
:
class
,
IEntity
<
ObjectId
>
{
public
BlogMongoDbTakeAutoIncRepositoryBase
(
BlogMongoDbDatabaseProvider
databaseProvider
)
:
base
(
databaseProvider
)
{
}
public
override
IQueryable
<
TEntity
>
GetAll
()
{
return
base
.
GetAll
();
}
}
public
abstract
class
BlogMongoDbRepositoryBase
<
TEntity
>
:
BlogMongoDbRepositoryBase
<
TEntity
,
ObjectId
>
where
TEntity
:
class
,
IEntity
<
ObjectId
>
{
public
BlogMongoDbRepositoryBase
(
BlogMongoDbDatabaseProvider
databaseProvider
)
:
base
(
databaseProvider
)
{
}
}
public
abstract
class
BlogMongoDbRepositoryBase
<
TEntity
,
TPrimaryKey
>
:
MongoDbRepositoryBase
<
TEntity
,
TPrimaryKey
>
where
TEntity
:
class
,
IEntity
<
TPrimaryKey
>
{
public
BlogMongoDbRepositoryBase
(
BlogMongoDbDatabaseProvider
databaseProvider
)
:
base
(
databaseProvider
)
{
}
}
}
\ No newline at end of file
Plus.MongoDb.Test/DbConsts.cs
0 → 100644
View file @
71223cfd
namespace
Plus.MongoDb.Test
{
public
class
DbConsts
{
public
class
DbTableName
{
public
const
string
Posts
=
"posts"
;
}
}
}
\ No newline at end of file
Plus.MongoDb.Test/Plus.MongoDb.Test.csproj
0 → 100644
View file @
71223cfd
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Plus.MongoDb" Version="1.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Plus\Plus.csproj" />
<ProjectReference Include="..\test\Plus.Core.Tests\Plus.Core.Tests.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Mappers\" />
</ItemGroup>
</Project>
Plus.MongoDb.Test/Repositories/ArticleRepository.cs
0 → 100644
View file @
71223cfd
using
Plus.Core.Tests.Domain
;
using
Plus.Core.Tests.Repositories
;
namespace
Plus.MongoDb.Test.Repositories
{
public
class
ArticleRepository
:
BlogMongoDbTakeAutoIncRepositoryBase
<
Article
>,
IArticleRepository
{
public
ArticleRepository
(
BlogMongoDbDatabaseProvider
databaseProvider
)
:
base
(
databaseProvider
)
{
}
}
}
\ No newline at end of file
Plus.sln
View file @
71223cfd
...
...
@@ -31,15 +31,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plus.RedisCache", "src\Plus
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plus.Extensions.Serialization", "src\Plus.Extensions.Serialization\Plus.Extensions.Serialization.csproj", "{209BF4EB-311F-45AD-AED6-F314A49D83C7}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.Web.Tests", "test\Plus.Web.Tests\Plus.Web.Tests.csproj", "{879A21A2-38A9-45C9-89C1-6BB7709C4F0B}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.Web.Tests", "test\Plus.Web.Tests\Plus.Web.Tests.csproj", "{879A21A2-38A9-45C9-89C1-6BB7709C4F0B}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.Core.Tests", "test\Plus.Core.Tests\Plus.Core.Tests.csproj", "{1017D21C-DE53-4791-8624-7727FFD73FD0}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.Core.Tests", "test\Plus.Core.Tests\Plus.Core.Tests.csproj", "{1017D21C-DE53-4791-8624-7727FFD73FD0}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.EFCore.Test", "test\Plus.EFCore.Test\Plus.EFCore.Test.csproj", "{4CF853EC-99EC-4441-B086-9EA2C761DB03}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.EFCore.Test", "test\Plus.EFCore.Test\Plus.EFCore.Test.csproj", "{4CF853EC-99EC-4441-B086-9EA2C761DB03}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "Plus.Services.Test", "test\Plus.Services.Test\Plus.Services.Test.csproj", "{D27671BF-7E67-4559-9DA6-E4AD418C3E7C}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "Plus.Services.Test", "test\Plus.Services.Test\Plus.Services.Test.csproj", "{D27671BF-7E67-4559-9DA6-E4AD418C3E7C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plus.Services.Dto.Test", "test\Plus.Services.Dto.Test\Plus.Services.Dto.Test.csproj", "{0F6DE8F7-14C0-4205-B14D-10DA2FEEB9D6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Plus.Services.Dto.Test", "test\Plus.Services.Dto.Test\Plus.Services.Dto.Test.csproj", "{0F6DE8F7-14C0-4205-B14D-10DA2FEEB9D6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plus.MongoDb.Test", "Plus.MongoDb.Test\Plus.MongoDb.Test.csproj", "{D6796121-03B4-419D-B75E-560B29EFD06C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
...
@@ -99,6 +101,10 @@ Global
{0F6DE8F7-14C0-4205-B14D-10DA2FEEB9D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F6DE8F7-14C0-4205-B14D-10DA2FEEB9D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F6DE8F7-14C0-4205-B14D-10DA2FEEB9D6}.Release|Any CPU.Build.0 = Release|Any CPU
{D6796121-03B4-419D-B75E-560B29EFD06C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D6796121-03B4-419D-B75E-560B29EFD06C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D6796121-03B4-419D-B75E-560B29EFD06C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D6796121-03B4-419D-B75E-560B29EFD06C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -117,6 +123,7 @@ Global
{4CF853EC-99EC-4441-B086-9EA2C761DB03} = {AD27338E-5F7F-4C1A-9E6F-9BFED17EF75A}
{D27671BF-7E67-4559-9DA6-E4AD418C3E7C} = {AD27338E-5F7F-4C1A-9E6F-9BFED17EF75A}
{0F6DE8F7-14C0-4205-B14D-10DA2FEEB9D6} = {AD27338E-5F7F-4C1A-9E6F-9BFED17EF75A}
{D6796121-03B4-419D-B75E-560B29EFD06C} = {AD27338E-5F7F-4C1A-9E6F-9BFED17EF75A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {44529F52-F5EE-4330-BB68-E09EB8B967E3}
...
...
test/Plus.Core.Tests/Configuration/AppSettings.cs
View file @
71223cfd
...
...
@@ -23,9 +23,9 @@ namespace Plus.Core.Tests.Configuration
public
static
class
MongoDb
{
private
static
IConfigurationSection
MongoDbSection
=>
_config
.
GetSection
(
"MongoDb"
);
private
static
IConfigurationSection
MongoDbSection
=>
ConnectionStrings
.
GetSection
(
"MongoDb"
);
public
static
string
ConnectionMode
=>
MongoDbSection
[
"ConnectionMode"
];
public
static
string
ConnectionMode
=>
MongoDbSection
[
"ConnectionMode"
]
??
""
;
public
static
string
DatabaseName
=>
MongoDbSection
[
"DatabaseName"
];
...
...
test/Plus.Core.Tests/Domain/Article.cs
0 → 100644
View file @
71223cfd
using
MongoDB.Bson
;
using
Plus.Domain.Entities
;
using
System
;
namespace
Plus.Core.Tests.Domain
{
public
class
Article
:
IEntity
<
ObjectId
>
{
public
ObjectId
Id
{
get
;
set
;
}
public
int
NumId
{
get
;
set
;
}
/// <summary>
/// 标题
/// </summary>
public
string
Title
{
get
;
set
;
}
/// <summary>
/// 作者
/// </summary>
public
string
Author
{
get
;
set
;
}
/// <summary>
/// 来源
/// </summary>
public
string
Source
{
get
;
set
;
}
/// <summary>
/// 链接
/// </summary>
public
string
Url
{
get
;
set
;
}
/// <summary>
/// 摘要
/// </summary>
public
string
Abstract
{
get
;
set
;
}
/// <summary>
/// 内容
/// </summary>
public
string
Content
{
get
;
set
;
}
/// <summary>
/// 点击量
/// </summary>
public
int
Hits
{
get
;
set
;
}
/// <summary>
/// 创建时间
/// </summary>
public
DateTime
?
CreationTime
{
get
;
set
;
}
public
bool
IsTransient
()
{
return
Id
==
ObjectId
.
Empty
;
}
}
}
\ No newline at end of file
test/Plus.Core.Tests/Plus.Core.Tests.csproj
View file @
71223cfd
...
...
@@ -4,6 +4,10 @@
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.8.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Plus\Plus.csproj" />
</ItemGroup>
...
...
test/Plus.Core.Tests/Repositories/IArticleRepository.cs
0 → 100644
View file @
71223cfd
using
MongoDB.Bson
;
using
Plus.Core.Tests.Domain
;
using
Plus.Domain.Repositories
;
namespace
Plus.Core.Tests.Repositories
{
public
interface
IArticleRepository
:
IRepository
<
Article
,
ObjectId
>
{
}
}
\ No newline at end of file
test/Plus.Services.Dto.Test/ArticleDto.cs
0 → 100644
View file @
71223cfd
using
System
;
namespace
Plus.Services.Dto.Test
{
public
class
ArticleDto
{
/// <summary>
/// 标题
/// </summary>
public
string
Title
{
get
;
set
;
}
/// <summary>
/// 作者
/// </summary>
public
string
Author
{
get
;
set
;
}
/// <summary>
/// 来源
/// </summary>
public
string
Source
{
get
;
set
;
}
/// <summary>
/// 链接
/// </summary>
public
string
Url
{
get
;
set
;
}
/// <summary>
/// 摘要
/// </summary>
public
string
Abstract
{
get
;
set
;
}
/// <summary>
/// 内容
/// </summary>
public
string
Content
{
get
;
set
;
}
/// <summary>
/// 点击量
/// </summary>
public
int
Hits
{
get
;
set
;
}
/// <summary>
/// 创建时间
/// </summary>
public
DateTime
?
CreationTime
{
get
;
set
;
}
}
}
\ No newline at end of file
test/Plus.Services.Test/Blog/IBlogService.Post.cs
View file @
71223cfd
...
...
@@ -6,5 +6,7 @@ namespace Plus.Services.Test.Blog
public
partial
interface
IBlogService
{
Task
<
PostDto
>
Get
(
int
id
);
Task
<
ArticleDto
>
GetArticle
(
int
id
);
}
}
\ No newline at end of file
test/Plus.Services.Test/Blog/Impl/BlogService.Post.cs
View file @
71223cfd
...
...
@@ -9,9 +9,13 @@ namespace Plus.Services.Test.Blog.Impl
{
private
readonly
IPostRepository
_postRepository
;
public
BlogService
(
IPostRepository
postRepository
)
private
readonly
IArticleRepository
_articleRepository
;
public
BlogService
(
IPostRepository
postRepository
,
IArticleRepository
articleRepository
)
{
_postRepository
=
postRepository
;
_articleRepository
=
articleRepository
;
}
public
async
Task
<
PostDto
>
Get
(
int
id
)
...
...
@@ -19,5 +23,11 @@ namespace Plus.Services.Test.Blog.Impl
var
entity
=
await
_postRepository
.
GetAsync
(
id
);
return
entity
.
MapTo
<
PostDto
>();
}
public
async
Task
<
ArticleDto
>
GetArticle
(
int
id
)
{
var
entity
=
await
_articleRepository
.
FirstOrDefaultAsync
(
x
=>
x
.
NumId
==
id
);
return
entity
.
MapTo
<
ArticleDto
>();
}
}
}
\ No newline at end of file
test/Plus.Web.Tests/Controllers/PostController.cs
View file @
71223cfd
...
...
@@ -32,5 +32,16 @@ namespace Plus.Web.Tests.Controllers
};
return
response
;
}
[
HttpGet
]
[
Route
(
"GetArticle"
)]
public
async
Task
<
Response
<
ArticleDto
>>
GetArticle
(
int
id
)
{
var
response
=
new
Response
<
ArticleDto
>
{
Result
=
await
_blogService
.
GetArticle
(
id
)
};
return
response
;
}
}
}
\ No newline at end of file
test/Plus.Web.Tests/Plus.Web.Tests.csproj
View file @
71223cfd
...
...
@@ -12,6 +12,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Plus.MongoDb.Test\Plus.MongoDb.Test.csproj" />
<ProjectReference Include="..\..\src\Plus.Extensions\Plus.Extensions.csproj" />
<ProjectReference Include="..\..\src\Plus.Log4Net\Plus.Log4Net.csproj" />
<ProjectReference Include="..\Plus.Core.Tests\Plus.Core.Tests.csproj" />
...
...
@@ -19,4 +20,6 @@
<ProjectReference Include="..\Plus.Services.Test\Plus.Services.Test.csproj" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>
test/Plus.Web.Tests/Startup.cs
View file @
71223cfd
...
...
@@ -9,6 +9,7 @@ using Plus.Dependency;
using
Plus.EFCore.Test
;
using
Plus.Log4Net
;
using
Plus.Modules
;
using
Plus.MongoDb.Test
;
using
Plus.Services.Dto.Test
;
using
Plus.Services.Test
;
using
System.Reflection
;
...
...
@@ -60,7 +61,8 @@ namespace Plus.Web.Tests
typeof
(
BlogCoreModule
),
typeof
(
BlogServicesModule
),
typeof
(
BlogServicesDtoModule
),
typeof
(
BlogEntityFrameworkCoreModule
)
typeof
(
BlogEntityFrameworkCoreModule
),
typeof
(
BlogMongoDbModule
)
)]
internal
class
BlogWebModule
:
PlusModule
{
...
...
test/Plus.Web.Tests/appsettings.json
View file @
71223cfd
...
...
@@ -9,9 +9,9 @@
"ConnectionStrings"
:
{
"MySql"
:
"Server=localhost;User Id=root;Password=123456;Database=meowv_blog"
,
"MongoDb"
:
{
"Servers"
:
[
"localhost:2701
9
"
],
"Servers"
:
[
"localhost:2701
7
"
],
"ConnectionMode"
:
""
,
"DatabaseName"
:
""
,
"DatabaseName"
:
"
MeowvBlog
"
,
"Username"
:
""
,
"Password"
:
""
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment