Skip to content

fix: remove redundant double quote when command fails #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/ApiControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ private IActionResult HandleErrorCommandResponse<TError>(CommandResponse<TError>

return BadRequest(response.ErrorCode?.Name ?? response.ErrorMessage);
}

private static IActionResult BadRequest(string text)
{
return new ContentResult
{
Content = text,
ContentType = "text/plain",
StatusCode = 400
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ private static IResult HandleErrorCommandResponse(CommandResponse response)
{
if (response.IsValidationError)
{
return Results.BadRequest(response.ValidationError!.Message);
return Results.Text(response.ValidationError!.Message, statusCode: 400);
}

if (response is { IsConcurrentError: true, LockAcquired: false })
{
return Results.StatusCode(429);
}

return Results.BadRequest(response.GetErrorMessage());
return Results.Text(response.GetErrorMessage(), statusCode: 400);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using Asp.Versioning;

using Cnblogs.Architecture.Ddd.Cqrs.AspNetCore;
using Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;

using Microsoft.AspNetCore.Mvc;

namespace Cnblogs.Architecture.IntegrationTestProject.Controllers;

[ApiVersion("1")]
[ApiController]
[Route("/api/v{version:apiVersion}")]
public class TestController : ControllerBase
public class TestController : ApiControllerBase
{
[HttpGet("paging")]
public Task<PagingParams?> PagingParamsAsync([FromQuery] PagingParams? pagingParams)
{
return Task.FromResult(pagingParams);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Net.Http.Json;
using Cnblogs.Architecture.IntegrationTestProject;
using Cnblogs.Architecture.IntegrationTestProject.Application.Errors;
using Cnblogs.Architecture.IntegrationTestProject.Payloads;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc.Testing;

namespace Cnblogs.Architecture.IntegrationTests;

public class CommandResponseHandlerTests
{
[Fact]
public async Task HandleCommandResponse_HavingError_BadRequestAsync()
{
// Arrange
var builder = new WebApplicationFactory<Program>();

// Act
var response = await builder.CreateClient().PutAsJsonAsync("/api/v1/strings/1", new UpdatePayload(true));
var content = await response.Content.ReadAsStringAsync();

// Assert
response.Should().HaveClientError();
content.Should().Be(TestError.Default.Name);
}

[Fact]
public async Task HandleCommandResponse_Success_OkAsync()
{
// Arrange
var builder = new WebApplicationFactory<Program>();

// Act
var response = await builder.CreateClient().PutAsJsonAsync("/api/v1/strings/1", new UpdatePayload(false));

// Assert
response.Should().BeSuccessful();
}
}