Skip to content

Commit

Permalink
.Net: fix: expected empty response in rest APIs (#9999)
Browse files Browse the repository at this point in the history
fixes #9990

Signed-off-by: Vincent Biret <[email protected]>
  • Loading branch information
baywet authored Jan 6, 2025
1 parent 6200d81 commit d201b5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ private async Task<RestApiOperationResponse> SendAsync(
/// <returns>The operation response.</returns>
private async Task<RestApiOperationResponse> ReadContentAndCreateOperationResponseAsync(HttpRequestMessage requestMessage, HttpResponseMessage responseMessage, object? payload, CancellationToken cancellationToken)
{
if (responseMessage.StatusCode == HttpStatusCode.NoContent)
if (responseMessage.StatusCode == HttpStatusCode.NoContent ||
(string.IsNullOrEmpty(responseMessage.Content.Headers.ContentType?.MediaType) &&
(responseMessage.StatusCode is HttpStatusCode.Accepted or HttpStatusCode.Created)))
{
return new RestApiOperationResponse(null, null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,11 +1136,14 @@ public async Task ItShouldReturnRequestUriAndContentAsync()
Assert.Equal("{\"name\":\"fake-name-value\",\"attributes\":{\"enabled\":true}}", ((JsonObject)result.RequestPayload).ToJsonString());
}

[Fact]
public async Task ItShouldHandleNoContentAsync()
[InlineData(System.Net.HttpStatusCode.NoContent)]
[InlineData(System.Net.HttpStatusCode.Accepted)]
[InlineData(System.Net.HttpStatusCode.Created)]
[Theory]
public async Task ItShouldHandleNoContentAsync(System.Net.HttpStatusCode statusCode)
{
// Arrange
this._httpMessageHandlerStub!.ResponseToReturn = new HttpResponseMessage(System.Net.HttpStatusCode.NoContent);
this._httpMessageHandlerStub!.ResponseToReturn = new HttpResponseMessage(statusCode);

List<RestApiPayloadProperty> payloadProperties =
[
Expand Down

0 comments on commit d201b5e

Please sign in to comment.