Skip to content

Commit

Permalink
Merge pull request #222 from cnblogs/fix-cqrs-header-appending
Browse files Browse the repository at this point in the history
fix: cqrs header mapping
  • Loading branch information
ikesnowy authored Mar 30, 2024
2 parents ed0cb7a + abbd497 commit 7c395e4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
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

0 comments on commit 7c395e4

Please sign in to comment.