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

namespace Wolverine.Http.Marten;

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

public static bool TryGetAggregateIdVariable(this IChain chain, [MaybeNullWhen(false)] out Variable variable)
{
variable = chain.GetAggregateIdVariable();
return variable != null;
}

public static Type? GetAggregateType(this IChain chain)
=> chain.Tags.TryGetValue(nameof(AggregateHandling), out var obj) && obj is AggregateHandling aggregateHandling
? aggregateHandling.AggregateType
: null;

public static bool TryGetAggregateType(this IChain chain, [MaybeNullWhen(false)] out Type type)
{
type = chain.GetAggregateType();
return type != null;
}
}
19 changes: 0 additions & 19 deletions src/Http/Wolverine.Http.Marten/HttpChainExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public async Task return_updated_aggregate_in_tuple()
}

[Fact]
public async Task aggregate_id_variable_is_fetchable_from_http_chain_for_handler_marked_with_AggregateHandler()
public async Task aggregate_id_variable_is_fetchable_from_chain_for_handler_marked_with_AggregateHandler()
{
// Guaranteeing that it's warmed up
var result1 = await Scenario(x =>
Expand All @@ -379,4 +379,28 @@ await Scenario(x =>
aggregateIdVariable.Usage.ShouldBe("order_Id");
}

[Fact]
public async Task aggregate_type_is_fetchable_from_chain_for_handler_marked_with_AggregateHandler()
{
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 aggregateType = chain.GetAggregateType();
aggregateType.ShouldNotBeNull();

aggregateType.FullName.ShouldBe(typeof(Order).FullName);
}

}
Loading