|
| 1 | +using System.Net.Http.Headers; |
1 | 2 | using System.Net.Http.Json;
|
| 3 | +using Cnblogs.Architecture.Ddd.Cqrs.Abstractions; |
2 | 4 | using Cnblogs.Architecture.Ddd.Cqrs.AspNetCore;
|
3 | 5 | using Cnblogs.Architecture.IntegrationTestProject;
|
4 | 6 | using Cnblogs.Architecture.IntegrationTestProject.Application.Commands;
|
@@ -31,7 +33,7 @@ public async Task MinimalApi_HavingError_BadRequestAsync(bool needValidationErro
|
31 | 33 | // Act
|
32 | 34 | var response = await builder.CreateClient().PutAsJsonAsync(
|
33 | 35 | "/api/v1/strings/1",
|
34 |
| - new UpdatePayload(needValidationError, needExecutionError)); |
| 36 | + new UpdatePayload(needExecutionError, needValidationError)); |
35 | 37 | var content = await response.Content.ReadAsStringAsync();
|
36 | 38 |
|
37 | 39 | // Assert
|
@@ -63,14 +65,35 @@ public async Task MinimalApi_HavingError_ProblemDetailsAsync(bool needValidation
|
63 | 65 | // Act
|
64 | 66 | var response = await builder.CreateClient().PutAsJsonAsync(
|
65 | 67 | "/api/v1/strings/1",
|
66 |
| - new UpdatePayload(needValidationError, needExecutionError)); |
| 68 | + new UpdatePayload(needExecutionError, needValidationError)); |
67 | 69 | var content = await response.Content.ReadFromJsonAsync<ProblemDetails>();
|
68 | 70 |
|
69 | 71 | // Assert
|
70 | 72 | response.Should().HaveClientError();
|
71 | 73 | content.Should().NotBeNull();
|
72 | 74 | }
|
73 | 75 |
|
| 76 | + [Theory] |
| 77 | + [MemberData(nameof(ErrorPayloads))] |
| 78 | + public async Task MinimalApi_HavingError_CommandResponseAsync(bool needValidationError, bool needExecutionError) |
| 79 | + { |
| 80 | + // Arrange |
| 81 | + var builder = new WebApplicationFactory<Program>(); |
| 82 | + |
| 83 | + // Act |
| 84 | + var client = builder.CreateClient(); |
| 85 | + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/cqrs")); |
| 86 | + var response = await client.PutAsJsonAsync( |
| 87 | + "/api/v1/strings/1", |
| 88 | + new UpdatePayload(needExecutionError, needValidationError)); |
| 89 | + var commandResponse = await response.Content.ReadFromJsonAsync<CommandResponse>(); |
| 90 | + |
| 91 | + // Assert |
| 92 | + response.Should().HaveClientError(); |
| 93 | + commandResponse.Should().NotBeNull(); |
| 94 | + commandResponse!.IsSuccess().Should().BeFalse(); |
| 95 | + } |
| 96 | + |
74 | 97 | [Theory]
|
75 | 98 | [MemberData(nameof(ErrorPayloads))]
|
76 | 99 | public async Task MinimalApi_HavingError_CustomContentAsync(bool needValidationError, bool needExecutionError)
|
@@ -143,6 +166,27 @@ public async Task Mvc_HavingError_ProblemDetailAsync(bool needValidationError, b
|
143 | 166 | content.Should().NotBeNull();
|
144 | 167 | }
|
145 | 168 |
|
| 169 | + [Theory] |
| 170 | + [MemberData(nameof(ErrorPayloads))] |
| 171 | + public async Task Mvc_HavingError_CommandResponseAsync(bool needValidationError, bool needExecutionError) |
| 172 | + { |
| 173 | + // Arrange |
| 174 | + var builder = new WebApplicationFactory<Program>(); |
| 175 | + |
| 176 | + // Act |
| 177 | + var client = builder.CreateClient(); |
| 178 | + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/cqrs")); |
| 179 | + var response = await client.PutAsJsonAsync( |
| 180 | + "/api/v1/mvc/strings/1", |
| 181 | + new UpdatePayload(needValidationError, needExecutionError)); |
| 182 | + var content = await response.Content.ReadFromJsonAsync<CommandResponse>(); |
| 183 | + |
| 184 | + // Assert |
| 185 | + response.Should().HaveClientError(); |
| 186 | + content.Should().NotBeNull(); |
| 187 | + content!.IsSuccess().Should().BeFalse(); |
| 188 | + } |
| 189 | + |
146 | 190 | [Theory]
|
147 | 191 | [MemberData(nameof(ErrorPayloads))]
|
148 | 192 | public async Task Mvc_HavingError_CustomContentAsync(bool needValidationError, bool needExecutionError)
|
|
0 commit comments