File tree Expand file tree Collapse file tree 4 files changed +54
-6
lines changed
src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore
Cnblogs.Architecture.IntegrationTestProject/Controllers
Cnblogs.Architecture.IntegrationTests Expand file tree Collapse file tree 4 files changed +54
-6
lines changed Original file line number Diff line number Diff line change @@ -60,4 +60,14 @@ private IActionResult HandleErrorCommandResponse<TError>(CommandResponse<TError>
6060
6161 return BadRequest ( response . ErrorCode ? . Name ?? response . ErrorMessage ) ;
6262 }
63+
64+ private static IActionResult BadRequest ( string text )
65+ {
66+ return new ContentResult
67+ {
68+ Content = text ,
69+ ContentType = "text/plain" ,
70+ StatusCode = 400
71+ } ;
72+ }
6373}
Original file line number Diff line number Diff line change @@ -61,14 +61,14 @@ private static IResult HandleErrorCommandResponse(CommandResponse response)
6161 {
6262 if ( response . IsValidationError )
6363 {
64- return Results . BadRequest ( response . ValidationError ! . Message ) ;
64+ return Results . Text ( response . ValidationError ! . Message , statusCode : 400 ) ;
6565 }
6666
6767 if ( response is { IsConcurrentError : true , LockAcquired : false } )
6868 {
6969 return Results . StatusCode ( 429 ) ;
7070 }
7171
72- return Results . BadRequest ( response . GetErrorMessage ( ) ) ;
72+ return Results . Text ( response . GetErrorMessage ( ) , statusCode : 400 ) ;
7373 }
7474}
Original file line number Diff line number Diff line change 11using Asp . Versioning ;
2-
2+ using Cnblogs . Architecture . Ddd . Cqrs . AspNetCore ;
33using Cnblogs . Architecture . Ddd . Infrastructure . Abstractions ;
44
55using Microsoft . AspNetCore . Mvc ;
66
77namespace Cnblogs . Architecture . IntegrationTestProject . Controllers ;
88
99[ ApiVersion ( "1" ) ]
10- [ ApiController ]
1110[ Route ( "/api/v{version:apiVersion}" ) ]
12- public class TestController : ControllerBase
11+ public class TestController : ApiControllerBase
1312{
1413 [ HttpGet ( "paging" ) ]
1514 public Task < PagingParams ? > PagingParamsAsync ( [ FromQuery ] PagingParams ? pagingParams )
1615 {
1716 return Task . FromResult ( pagingParams ) ;
1817 }
19- }
18+ }
Original file line number Diff line number Diff line change 1+ using System . Net . Http . Json ;
2+ using Cnblogs . Architecture . IntegrationTestProject ;
3+ using Cnblogs . Architecture . IntegrationTestProject . Application . Errors ;
4+ using Cnblogs . Architecture . IntegrationTestProject . Payloads ;
5+ using FluentAssertions ;
6+ using Microsoft . AspNetCore . Mvc . Testing ;
7+
8+ namespace Cnblogs . Architecture . IntegrationTests ;
9+
10+ public class CommandResponseHandlerTests
11+ {
12+ [ Fact ]
13+ public async Task HandleCommandResponse_HavingError_BadRequestAsync ( )
14+ {
15+ // Arrange
16+ var builder = new WebApplicationFactory < Program > ( ) ;
17+
18+ // Act
19+ var response = await builder . CreateClient ( ) . PutAsJsonAsync ( "/api/v1/strings/1" , new UpdatePayload ( true ) ) ;
20+ var content = await response . Content . ReadAsStringAsync ( ) ;
21+
22+ // Assert
23+ response . Should ( ) . HaveClientError ( ) ;
24+ content . Should ( ) . Be ( TestError . Default . Name ) ;
25+ }
26+
27+ [ Fact ]
28+ public async Task HandleCommandResponse_Success_OkAsync ( )
29+ {
30+ // Arrange
31+ var builder = new WebApplicationFactory < Program > ( ) ;
32+
33+ // Act
34+ var response = await builder . CreateClient ( ) . PutAsJsonAsync ( "/api/v1/strings/1" , new UpdatePayload ( false ) ) ;
35+
36+ // Assert
37+ response . Should ( ) . BeSuccessful ( ) ;
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments