Skip to content
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
19 changes: 19 additions & 0 deletions src/Http/Wolverine.Http.Marten/HttpChainExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Diagnostics.CodeAnalysis;
using JasperFx.CodeGeneration.Model;
using Wolverine.Marten;

namespace Wolverine.Http.Marten;

public static class HttpChainExtensions
{
public static Variable? GetAggregateIdVariable(this HttpChain chain)
=> chain.Tags.TryGetValue(nameof(AggregateHandling), out var obj) && obj is AggregateHandling aggregateHandling
? aggregateHandling.AggregateId
: null;

public static bool TryGetAggregateIdVariable(this HttpChain chain, [MaybeNullWhen(false)] out Variable variable)
{
variable = chain.GetAggregateIdVariable();
return variable != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Wolverine.Http.Marten;
using Wolverine.Marten;
using WolverineWebApi.Marten;

Expand Down Expand Up @@ -351,5 +352,31 @@ public async Task return_updated_aggregate_in_tuple()
stream.Select(x => x.Data).OfType<UpdatedAggregate>().Any().ShouldBeFalse();

}

[Fact]
public async Task aggregate_id_variable_is_fetchable_from_http_chain_for_handler_marked_with_AggregateHandler()
{
// Guaranteeing that it's warmed up
var result1 = await Scenario(x =>
{
x.Post.Json(new StartOrder(["Socks", "Shoes", "Shirt"])).ToUrl("/orders/create");
});

var status1 = result1.ReadAsJson<OrderStatus>();

await Scenario(x =>
{
x.Post.Json(new MarkItemReady(status1.OrderId, "Socks", 1)).ToUrl("/orders/itemready");
});

var chain = Host.Services.GetRequiredService<WolverineHttpOptions>().Endpoints!.ChainFor("POST", "/orders/itemready");
chain.ShouldNotBeNull();

var aggregateIdVariable = chain.GetAggregateIdVariable();
aggregateIdVariable.ShouldNotBeNull();

aggregateIdVariable.VariableType.FullName.ShouldBe(typeof(Guid).FullName);
aggregateIdVariable.Usage.ShouldBe("order_Id");
}

}
Loading