Skip to content

fix: cqrs header mapping #222

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 30, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected IActionResult HandleCommandResponse<TResponse, TError>(CommandResponse
{
if (response.IsSuccess())
{
return Request.Headers.CqrsVersion() > 1 ? Ok(response) : Ok(response.Response);
return Request.Headers.CqrsVersion() > 1 ? new CqrsObjectResult(response) : Ok(response.Response);
}

return HandleCommandResponse((CommandResponse<TError>)response);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;

using Cnblogs.Architecture.Ddd.Cqrs.Abstractions;
using Cnblogs.Architecture.Ddd.Cqrs.DependencyInjection;
using MediatR;
Expand All @@ -22,6 +21,12 @@ public static CqrsInjector AddCqrs(this IServiceCollection services, params Asse
{
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
if (assemblies.Length == 0)
{
// mediator needs at least one assembly to inject from
assemblies = [typeof(CqrsInjector).Assembly];
}

services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblies(assemblies));
return new CqrsInjector(services);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public async Task MinimalApi_CqrsV2_CommandResponseAsync()
var content = await response.Content.ReadFromJsonAsync<CommandResponse<string, TestError>>();

// Assert
response.Headers.CqrsVersion().Should().BeGreaterThan(1);
content.Should().NotBeNull();
content!.Response.Should().NotBeNullOrEmpty();
}
Expand Down Expand Up @@ -89,7 +90,8 @@ public async Task Mvc_CurrentCqrsVersion_CommandResponseAsync()

// Assert
response.Should().BeSuccessful();
content!.Response.Should().NotBeNull();
response.Headers.CqrsVersion().Should().BeGreaterThan(1);
content!.Response.Should().NotBeNullOrEmpty();
}

[Theory]
Expand Down
4 changes: 2 additions & 2 deletions test/Cnblogs.Architecture.IntegrationTests/DaprTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async Task Dapr_SubscribeEndpoint_OkAsync(SubscribeType subscribeType)
{
// Arrange
var builder = WebApplication.CreateBuilder();
builder.Services.AddEventBus(o => o.UseDapr(nameof(DaprTests)));
builder.Services.AddCqrs(typeof(TestIntegrationEvent).Assembly).AddEventBus(o => o.UseDapr(nameof(DaprTests)));
builder.WebHost.UseTestServer();

await using var app = builder.Build();
Expand Down Expand Up @@ -53,7 +53,7 @@ public async Task Dapr_SubscribeWithoutAnyAssembly_OkAsync()
{
// Arrange
var builder = WebApplication.CreateBuilder();
builder.Services.AddEventBus(o => o.UseDapr(nameof(DaprTests)));
builder.Services.AddCqrs().AddEventBus(o => o.UseDapr(nameof(DaprTests)));
builder.WebHost.UseTestServer();

var app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Cnblogs.Architecture.TestIntegrationEvents;
using FluentAssertions;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Cnblogs.Architecture.UnitTests.EventBus;

Expand All @@ -13,7 +14,7 @@ public void SubscribeByAssemblyMeta_Success()
{
// Arrange
var builder = WebApplication.CreateBuilder();
builder.Services.AddEventBus(o => o.UseDapr(nameof(AssemblyAttributeTests)));
builder.Services.AddCqrs().AddEventBus(o => o.UseDapr(nameof(AssemblyAttributeTests)));
var app = builder.Build();

// Act
Expand Down