Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d2f2c9

Browse files
committed
1.修改CrudService接口
2.添加ASP.NET CORE MVC单元测试
1 parent1f7ddfc commit2d2f2c9

File tree

20 files changed

+6003
-27
lines changed

20 files changed

+6003
-27
lines changed

‎Destiny.Core.Flow.sln‎

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 16
44
VisualStudioVersion =16.0.29911.84
55
MinimumVisualStudioVersion =10.0.40219.1
6-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.API","src\Destiny.Core.Flow.API\Destiny.Core.Flow.API.csproj","{FF447721-BFD6-40C6-AE23-D672EC225A00}"
7-
EndProject
86
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.IServices","src\Destiny.Core.Flow.IServices\Destiny.Core.Flow.IServices.csproj","{0FDF7DC0-77FE-4529-8E8C-D17FF03D84A0}"
97
EndProject
108
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.Services","src\Destiny.Core.Flow.Services\Destiny.Core.Flow.Services.csproj","{89D24E5C-7C65-4150-AB7B-656809CC6011}"
@@ -45,18 +43,22 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Destiny.Core.Flow.EntityFra
4543
EndProject
4644
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.Shared","src\Destiny.Core.Flow.Shared\Destiny.Core.Flow.Shared.csproj","{96659BA9-6B77-42ED-86B3-23354B321E50}"
4745
EndProject
48-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") ="Destiny.Core.Flow.Core","src\Destiny.Core.Flow.Core\Destiny.Core.Flow.Core.csproj","{EA0C5DAC-48E2-4637-BB89-DC75C06C5C7F}"
46+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.Core","src\Destiny.Core.Flow.Core\Destiny.Core.Flow.Core.csproj","{EA0C5DAC-48E2-4637-BB89-DC75C06C5C7F}"
47+
EndProject
48+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.AspNetCore","src\Destiny.Core.Flow.AspNetCore\Destiny.Core.Flow.AspNetCore.csproj","{3FE110EB-A8CB-4DF1-8BFF-9159351349CE}"
49+
EndProject
50+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.AspNetCore.TestBase","src\Destiny.Core.Flow.AspNetCore.TestBase\Destiny.Core.Flow.AspNetCore.TestBase.csproj","{8B484D44-3BFF-4644-962E-913A0F43C134}"
51+
EndProject
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.AspNetMvc.Test","test\Destiny.Core.AspNetMvc.Test\Destiny.Core.AspNetMvc.Test.csproj","{FE52DE20-B86E-46A2-8E21-98E9825C2530}"
53+
EndProject
54+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") ="Destiny.Core.Flow.API","src\Destiny.Core.Flow.API\Destiny.Core.Flow.API.csproj","{EF17885B-ED88-4997-AFB4-63FE0DF1E414}"
4955
EndProject
5056
Global
5157
GlobalSection(SolutionConfigurationPlatforms) =preSolution
5258
Debug|Any CPU=Debug|Any CPU
5359
Release|Any CPU=Release|Any CPU
5460
EndGlobalSection
5561
GlobalSection(ProjectConfigurationPlatforms) =postSolution
56-
{FF447721-BFD6-40C6-AE23-D672EC225A00}.Debug|Any CPU.ActiveCfg=Debug|Any CPU
57-
{FF447721-BFD6-40C6-AE23-D672EC225A00}.Debug|Any CPU.Build.0=Debug|Any CPU
58-
{FF447721-BFD6-40C6-AE23-D672EC225A00}.Release|Any CPU.ActiveCfg=Release|Any CPU
59-
{FF447721-BFD6-40C6-AE23-D672EC225A00}.Release|Any CPU.Build.0=Release|Any CPU
6062
{0FDF7DC0-77FE-4529-8E8C-D17FF03D84A0}.Debug|Any CPU.ActiveCfg=Debug|Any CPU
6163
{0FDF7DC0-77FE-4529-8E8C-D17FF03D84A0}.Debug|Any CPU.Build.0=Debug|Any CPU
6264
{0FDF7DC0-77FE-4529-8E8C-D17FF03D84A0}.Release|Any CPU.ActiveCfg=Release|Any CPU
@@ -117,12 +119,27 @@ Global
117119
{EA0C5DAC-48E2-4637-BB89-DC75C06C5C7F}.Debug|Any CPU.Build.0=Debug|Any CPU
118120
{EA0C5DAC-48E2-4637-BB89-DC75C06C5C7F}.Release|Any CPU.ActiveCfg=Release|Any CPU
119121
{EA0C5DAC-48E2-4637-BB89-DC75C06C5C7F}.Release|Any CPU.Build.0=Release|Any CPU
122+
{3FE110EB-A8CB-4DF1-8BFF-9159351349CE}.Debug|Any CPU.ActiveCfg=Debug|Any CPU
123+
{3FE110EB-A8CB-4DF1-8BFF-9159351349CE}.Debug|Any CPU.Build.0=Debug|Any CPU
124+
{3FE110EB-A8CB-4DF1-8BFF-9159351349CE}.Release|Any CPU.ActiveCfg=Release|Any CPU
125+
{3FE110EB-A8CB-4DF1-8BFF-9159351349CE}.Release|Any CPU.Build.0=Release|Any CPU
126+
{8B484D44-3BFF-4644-962E-913A0F43C134}.Debug|Any CPU.ActiveCfg=Debug|Any CPU
127+
{8B484D44-3BFF-4644-962E-913A0F43C134}.Debug|Any CPU.Build.0=Debug|Any CPU
128+
{8B484D44-3BFF-4644-962E-913A0F43C134}.Release|Any CPU.ActiveCfg=Release|Any CPU
129+
{8B484D44-3BFF-4644-962E-913A0F43C134}.Release|Any CPU.Build.0=Release|Any CPU
130+
{FE52DE20-B86E-46A2-8E21-98E9825C2530}.Debug|Any CPU.ActiveCfg=Debug|Any CPU
131+
{FE52DE20-B86E-46A2-8E21-98E9825C2530}.Debug|Any CPU.Build.0=Debug|Any CPU
132+
{FE52DE20-B86E-46A2-8E21-98E9825C2530}.Release|Any CPU.ActiveCfg=Release|Any CPU
133+
{FE52DE20-B86E-46A2-8E21-98E9825C2530}.Release|Any CPU.Build.0=Release|Any CPU
134+
{EF17885B-ED88-4997-AFB4-63FE0DF1E414}.Debug|Any CPU.ActiveCfg=Debug|Any CPU
135+
{EF17885B-ED88-4997-AFB4-63FE0DF1E414}.Debug|Any CPU.Build.0=Debug|Any CPU
136+
{EF17885B-ED88-4997-AFB4-63FE0DF1E414}.Release|Any CPU.ActiveCfg=Release|Any CPU
137+
{EF17885B-ED88-4997-AFB4-63FE0DF1E414}.Release|Any CPU.Build.0=Release|Any CPU
120138
EndGlobalSection
121139
GlobalSection(SolutionProperties) =preSolution
122140
HideSolutionNode =FALSE
123141
EndGlobalSection
124142
GlobalSection(NestedProjects) =preSolution
125-
{FF447721-BFD6-40C6-AE23-D672EC225A00} ={9A347066-1CEA-4FD6-BD7E-598A7FF21E6C}
126143
{0FDF7DC0-77FE-4529-8E8C-D17FF03D84A0} ={5D6E6ADE-8C66-4955-9DC6-C8610EDE9DE6}
127144
{89D24E5C-7C65-4150-AB7B-656809CC6011} ={5D6E6ADE-8C66-4955-9DC6-C8610EDE9DE6}
128145
{3350DDC6-02D0-4986-9F13-17B8B94B9456} ={5D6E6ADE-8C66-4955-9DC6-C8610EDE9DE6}
@@ -142,6 +159,10 @@ Global
142159
{A238B019-A658-4F10-980C-6EBBAE4FB596} ={968F74F4-4D0A-4832-A7EA-5CB2BA08AF8A}
143160
{96659BA9-6B77-42ED-86B3-23354B321E50} ={968F74F4-4D0A-4832-A7EA-5CB2BA08AF8A}
144161
{EA0C5DAC-48E2-4637-BB89-DC75C06C5C7F} ={968F74F4-4D0A-4832-A7EA-5CB2BA08AF8A}
162+
{3FE110EB-A8CB-4DF1-8BFF-9159351349CE} ={968F74F4-4D0A-4832-A7EA-5CB2BA08AF8A}
163+
{8B484D44-3BFF-4644-962E-913A0F43C134} ={968F74F4-4D0A-4832-A7EA-5CB2BA08AF8A}
164+
{FE52DE20-B86E-46A2-8E21-98E9825C2530} ={B74CBBDD-8574-4768-AA9D-2144A77D4875}
165+
{EF17885B-ED88-4997-AFB4-63FE0DF1E414} ={9A347066-1CEA-4FD6-BD7E-598A7FF21E6C}
145166
EndGlobalSection
146167
GlobalSection(ExtensibilityGlobals) =postSolution
147168
SolutionGuid ={468F450C-837F-4FCD-8E06-3E12690DDED6}

‎src/Destiny.Core.Flow.API/Startups/FunctionModule.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
usingSystem.IO;
1212
usingMicrosoft.Extensions.Options;
1313
usingSystem;
14-
usingDestiny.Core.Flow.IServices.Abstractions;
15-
usingDestiny.Core.Flow.Services.Application;
14+
1615
usingDestiny.Core.Flow.Core;
1716

1817

‎src/Destiny.Core.Flow.API/appsettings.Development.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
},
7777
"Migrations": {
7878
"IsAutoMigration":false,//是否自动迁移
79-
"IsAddSeedData":false//是否添加种子数据
79+
"IsAddSeedData":true//是否添加种子数据
8080
},
8181
"MongoDBs": {
8282
"MongoDBConnectionString":"DestinyCoreMongoDb.txt",//开发用数据库
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
usingDestiny.Core.Flow.TestBase;
2+
usingDestinyCore.Extensions;
3+
usingMicrosoft.AspNetCore.Hosting;
4+
usingMicrosoft.AspNetCore.Routing;
5+
usingMicrosoft.AspNetCore.TestHost;
6+
usingMicrosoft.Extensions.DependencyInjection;
7+
usingMicrosoft.Extensions.Hosting;
8+
usingSystem;
9+
usingSystem.Collections.Generic;
10+
usingSystem.Linq;
11+
usingSystem.Net.Http;
12+
usingSystem.Threading.Tasks;
13+
14+
namespaceDestiny.Core.Flow.AspNetCore.TestBase
15+
{
16+
publicclassAspNetCoreIntegratedTestBase<TStartup>:TestBaseWithServiceProvider
17+
whereTStartup:class
18+
{
19+
20+
protectedTestServerServer{get;}
21+
22+
protectedHttpClientClient{get;}
23+
24+
protectedoverrideIServiceProviderServiceProvider{get;}
25+
26+
protectedAspNetCoreIntegratedTestBase()
27+
{
28+
varbuilder=CreateHostBuilder();
29+
30+
varhost=builder.Build();
31+
host.Start();
32+
33+
Server=host.GetTestServer();
34+
Client=host.GetTestClient();
35+
36+
ServiceProvider=Server.Services;
37+
38+
ServiceProvider.GetRequiredService<ITestServerAccessor>().Server=Server;
39+
}
40+
41+
42+
protectedvirtualIHostBuilderCreateHostBuilder()
43+
{
44+
returnHost.CreateDefaultBuilder()
45+
.ConfigureWebHostDefaults(webBuilder=>
46+
{
47+
webBuilder.UseStartup<TStartup>();
48+
webBuilder.UseTestServer();
49+
})
50+
.ConfigureServices(ConfigureServices);
51+
}
52+
53+
protectedvirtualvoidConfigureServices(HostBuilderContextcontext,IServiceCollectionservices)
54+
{
55+
56+
}
57+
58+
59+
60+
61+
protectedvirtualstringGetUrl<TController>()
62+
{
63+
return$"/{typeof(TController).Name.RemovePostFix("Controller")}";
64+
}
65+
66+
protectedvirtualstringGetUrl<TController>(stringactionName)
67+
{
68+
returnGetUrl<TController>()+"/"+actionName;
69+
}
70+
71+
protectedvirtualstringGetUrl<TController>(stringactionName,objectqueryStringParamsAsAnonymousObject)
72+
{
73+
varurl=GetUrl<TController>(actionName);
74+
75+
vardictionary=newRouteValueDictionary(queryStringParamsAsAnonymousObject);
76+
if(dictionary.Any())
77+
{
78+
url+="?"+dictionary.Select(d=>$"{d.Key}={d.Value}").ToJoin("&");
79+
}
80+
81+
returnurl;
82+
}
83+
}
84+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
usingDestinyCore.Helpers;
2+
usingShouldly;
3+
usingSystem;
4+
usingSystem.Collections.Generic;
5+
usingSystem.Linq;
6+
usingSystem.Net;
7+
usingSystem.Net.Http;
8+
usingSystem.Threading.Tasks;
9+
10+
namespaceDestiny.Core.Flow.AspNetCore.TestBase
11+
{
12+
publicclassAspNetMvcTestBase<TStartup>:AspNetCoreIntegratedTestBase<TStartup>
13+
whereTStartup:class
14+
{
15+
16+
protectedvirtualasyncTask<T>GetResponseAsObjectAsync<T>(stringurl,HttpStatusCodeexpectedStatusCode=HttpStatusCode.OK)
17+
{
18+
varstrResponse=awaitGetResponseAsStringAsync(url,expectedStatusCode);
19+
returnstrResponse.FromJson<T>();
20+
}
21+
22+
protectedvirtualasyncTask<string>GetResponseAsStringAsync(stringurl,HttpStatusCodeexpectedStatusCode=HttpStatusCode.OK)
23+
{
24+
using(varresponse=awaitGetResponseAsync(url,expectedStatusCode))
25+
{
26+
returnawaitresponse.Content.ReadAsStringAsync();
27+
}
28+
}
29+
30+
protectedvirtualasyncTask<HttpResponseMessage>GetResponseAsync(stringurl,HttpStatusCodeexpectedStatusCode=HttpStatusCode.OK)
31+
{
32+
using(varrequestMessage=newHttpRequestMessage(HttpMethod.Get,url))
33+
{
34+
35+
varresponse=awaitClient.SendAsync(requestMessage);
36+
response.StatusCode.ShouldBe(expectedStatusCode);
37+
returnresponse;
38+
}
39+
}
40+
}
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<ProjectSdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<ApplicationIcon />
6+
<OutputType>Library</OutputType>
7+
<StartupObject />
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReferenceInclude="Microsoft.AspNetCore.TestHost"Version="5.0.7" />
12+
<PackageReferenceInclude="Shouldly"Version="4.0.3" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReferenceInclude="..\Destiny.Core.Flow.TestBase\Destiny.Core.Flow.TestBase.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
usingDestinyCore.Dependency;
2+
usingMicrosoft.AspNetCore.TestHost;
3+
usingSystem;
4+
usingSystem.Collections.Generic;
5+
usingSystem.Linq;
6+
usingSystem.Threading.Tasks;
7+
8+
namespaceDestiny.Core.Flow.AspNetCore.TestBase
9+
{
10+
publicinterfaceITestServerAccessor:ISingletonDependency
11+
{
12+
TestServerServer{get;set;}
13+
}
14+
15+
publicclassTestServerAccessor:ITestServerAccessor
16+
{
17+
publicTestServerServer{get;set;}
18+
}
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"iisSettings": {
3+
"windowsAuthentication":false,
4+
"anonymousAuthentication":true,
5+
"iisExpress": {
6+
"applicationUrl":"http://localhost:21507",
7+
"sslPort":0
8+
}
9+
},
10+
"profiles": {
11+
"IIS Express": {
12+
"commandName":"IISExpress",
13+
"launchBrowser":true,
14+
"environmentVariables": {
15+
"ASPNETCORE_ENVIRONMENT":"Development"
16+
}
17+
},
18+
"Destiny.Core.Flow.AspNetCore.TestBase": {
19+
"commandName":"Project",
20+
"dotnetRunMessages":"true",
21+
"launchBrowser":true,
22+
"applicationUrl":"http://localhost:21507",
23+
"environmentVariables": {
24+
"ASPNETCORE_ENVIRONMENT":"Development"
25+
}
26+
}
27+
}
28+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+

2+
usingDestiny.Core.Flow.Shared.Abstractions;
3+
usingDestinyCore.AspNetCore;
4+
usingDestinyCore.AspNetCore.Api;
5+
usingDestinyCore.Entity;
6+
usingDestinyCore.Filter;
7+
usingMicrosoft.AspNetCore.Authorization;
8+
usingMicrosoft.AspNetCore.Mvc;
9+
usingSystem;
10+
usingSystem.Collections.Generic;
11+
usingSystem.ComponentModel;
12+
usingSystem.Linq;
13+
usingSystem.Text;
14+
usingSystem.Threading.Tasks;
15+
16+
namespaceDestiny.Core.Flow.AspNetCore
17+
{
18+
19+
20+
[Route("api/[controller]/[action]")]
21+
[ApiController]
22+
publicabstractclassCrudApiControllerBase<TPrimaryKey,TEntity,IInputDto,IIOutputDto,IPagedListDto>:ApiControllerBase
23+
whereTEntity:EntityBase<TPrimaryKey>
24+
whereTPrimaryKey:IEquatable<TPrimaryKey>
25+
whereIInputDto:IInputDto<TPrimaryKey>
26+
whereIPagedListDto:IOutputDto<TPrimaryKey>
27+
whereIIOutputDto:IOutputDto<TPrimaryKey>
28+
{
29+
protectedICrudServiceAsync<TPrimaryKey,TEntity,IInputDto,IIOutputDto,IPagedListDto>CrudServiceAsync{get;set;}
30+
protectedCrudApiControllerBase(ICrudServiceAsync<TPrimaryKey,TEntity,IInputDto,IIOutputDto,IPagedListDto>crudServiceAsync)
31+
{
32+
33+
this.CrudServiceAsync=crudServiceAsync;
34+
}
35+
36+
37+
[Description("异步创建")]
38+
[HttpPost]
39+
publicvirtualasyncTask<AjaxResult>CreateAsync([FromBody]IInputDtodto)
40+
{
41+
42+
return(awaitCrudServiceAsync.CreateAsync(dto)).ToAjaxResult();
43+
}
44+
45+
[HttpGet]
46+
publicvirtualasyncTask<AjaxResult>LoadDataAsync(TPrimaryKeykey){
47+
48+
return(awaitCrudServiceAsync.LoadDataByKeyAsync(key)).ToAjaxResult();
49+
}
50+
51+
[Description("异步更新")]
52+
[HttpPost]
53+
publicvirtualasyncTask<AjaxResult>UpdateAsync([FromBody]IInputDtodto)
54+
{
55+
56+
return(awaitCrudServiceAsync.UpdateAsync(dto)).ToAjaxResult();
57+
}
58+
59+
[Description("异步删除")]
60+
[HttpDelete]
61+
publicvirtualasyncTask<AjaxResult>DeleteAsync(TPrimaryKeyid)
62+
{
63+
64+
return(awaitCrudServiceAsync.DeleteAsync(id)).ToAjaxResult();
65+
66+
}
67+
68+
[Description("异步得到分页")]
69+
[HttpPost]
70+
publicasyncTask<PageList<IPagedListDto>>GetPageAsync([FromBody]PageRequestrequest)
71+
{
72+
return(awaitCrudServiceAsync.GetPageAsync(request)).ToPageList();
73+
74+
}
75+
}
76+
77+
[Authorize]
78+
publicabstractclassCrudAdminControllerBase<TPrimaryKey,TEntity,IInputDto,IIOutputDto,IPagedListDto>:CrudApiControllerBase<TPrimaryKey,TEntity,IInputDto,IIOutputDto,IPagedListDto>
79+
whereTEntity:EntityBase<TPrimaryKey>
80+
whereTPrimaryKey:IEquatable<TPrimaryKey>
81+
whereIInputDto:IInputDto<TPrimaryKey>
82+
whereIPagedListDto:IOutputDto<TPrimaryKey>
83+
whereIIOutputDto:IOutputDto<TPrimaryKey>
84+
{
85+
86+
87+
88+
protectedCrudAdminControllerBase(ICrudServiceAsync<TPrimaryKey,TEntity,IInputDto,IIOutputDto,IPagedListDto>crudServiceAsync):base(crudServiceAsync)
89+
{
90+
91+
this.CrudServiceAsync=crudServiceAsync;
92+
}
93+
94+
}
95+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp