File tree 4 files changed +54
-6
lines changed
src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore
Cnblogs.Architecture.IntegrationTestProject/Controllers
Cnblogs.Architecture.IntegrationTests
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>
60
60
61
61
return BadRequest ( response . ErrorCode ? . Name ?? response . ErrorMessage ) ;
62
62
}
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
+ }
63
73
}
Original file line number Diff line number Diff line change @@ -61,14 +61,14 @@ private static IResult HandleErrorCommandResponse(CommandResponse response)
61
61
{
62
62
if ( response . IsValidationError )
63
63
{
64
- return Results . BadRequest ( response . ValidationError ! . Message ) ;
64
+ return Results . Text ( response . ValidationError ! . Message , statusCode : 400 ) ;
65
65
}
66
66
67
67
if ( response is { IsConcurrentError : true , LockAcquired : false } )
68
68
{
69
69
return Results . StatusCode ( 429 ) ;
70
70
}
71
71
72
- return Results . BadRequest ( response . GetErrorMessage ( ) ) ;
72
+ return Results . Text ( response . GetErrorMessage ( ) , statusCode : 400 ) ;
73
73
}
74
74
}
Original file line number Diff line number Diff line change 1
1
using Asp . Versioning ;
2
-
2
+ using Cnblogs . Architecture . Ddd . Cqrs . AspNetCore ;
3
3
using Cnblogs . Architecture . Ddd . Infrastructure . Abstractions ;
4
4
5
5
using Microsoft . AspNetCore . Mvc ;
6
6
7
7
namespace Cnblogs . Architecture . IntegrationTestProject . Controllers ;
8
8
9
9
[ ApiVersion ( "1" ) ]
10
- [ ApiController ]
11
10
[ Route ( "/api/v{version:apiVersion}" ) ]
12
- public class TestController : ControllerBase
11
+ public class TestController : ApiControllerBase
13
12
{
14
13
[ HttpGet ( "paging" ) ]
15
14
public Task < PagingParams ? > PagingParamsAsync ( [ FromQuery ] PagingParams ? pagingParams )
16
15
{
17
16
return Task . FromResult ( pagingParams ) ;
18
17
}
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