From 935c18e90cee21b6527ddba2fee428a3b7847af4 Mon Sep 17 00:00:00 2001 From: Anne Erdtsieck Date: Sat, 9 Dec 2023 11:25:14 +0100 Subject: [PATCH] #649 reproduction compilation failures on cascading aggregate handler --- ...Bug_649_cascading_handlers_on_aggregate.cs | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/Http/Wolverine.Http.Tests/Bugs/Bug_649_cascading_handlers_on_aggregate.cs diff --git a/src/Http/Wolverine.Http.Tests/Bugs/Bug_649_cascading_handlers_on_aggregate.cs b/src/Http/Wolverine.Http.Tests/Bugs/Bug_649_cascading_handlers_on_aggregate.cs new file mode 100644 index 000000000..14cdc364f --- /dev/null +++ b/src/Http/Wolverine.Http.Tests/Bugs/Bug_649_cascading_handlers_on_aggregate.cs @@ -0,0 +1,96 @@ +using Alba; +using IntegrationTests; +using Marten; +using Marten.Events; +using Microsoft.AspNetCore.Builder; +using Wolverine.Marten; +using Wolverine.Tracking; + +namespace Wolverine.Http.Tests.Bugs; + +public class Bug_649_cascading_handlers_on_aggregate +{ + /// + /// Note that when this bug was discovered, it sometimes succeeded and sometimes failed + /// + [Fact] + public async Task compiles_every_run() + { + var builder = WebApplication.CreateBuilder(Array.Empty()); + + builder.Services.AddMarten(opts => + { + opts.Connection(Servers.PostgresConnectionString); + opts.Events.StreamIdentity = StreamIdentity.AsString; + opts.Projections.LiveStreamAggregation(); + }) + .IntegrateWithWolverine(); + + builder.Host.UseWolverine(); + + await using var host = await AlbaHost.For(builder, app => + { + app.MapWolverineEndpoints(); + }); + + await host.ExecuteAndWaitAsync(async () => + { + await host.Scenario(x => + { + x.Post.Json(new StartConsultation(Guid.NewGuid().ToString(), new() + { + "user1", + "user2", + "user3", + }, Guid.NewGuid())).ToUrl("/api/v1/consultatie/start"); + x.StatusCodeShouldBe(204); + }); + }); + } +} + +public record ConsultationStarted(string ConsultationId, List Members, Guid PatientId); +public record Consultation(string Id, List Members, Guid PatientId) +{ + public static Consultation Create(ConsultationStarted @event) => new(@event.ConsultationId, @event.Members, @event.PatientId); +} + +public record StartConsultation(string ConsultationId, List Members, Guid PatientId); +public sealed class StartEndpoint +{ + [WolverinePost("api/v1/consultatie/start")] + public static (IStartStream, OutgoingMessages) HandleAsync(StartConsultation command) + { + var startStream = MartenOps.StartStream(command.ConsultationId, + new ConsultationStarted(command.ConsultationId, command.Members, command.PatientId)); + var messages = new OutgoingMessages + { + new GrantMembersAccessToPatientOfConsultation(command.ConsultationId, command.Members) + }; + + return (startStream, messages); + } +} + +public sealed record GrantMembersAccessToPatientOfConsultation(string ConsultationId, List Members); +public static class GrantMembersAccessToPatientOfConsultationHandler +{ + public static OutgoingMessages HandleAsync(GrantMembersAccessToPatientOfConsultation command) + { + var messages = new OutgoingMessages(); + messages.AddRange(command.Members.Select(memberId => + new GrantMemberAccessToPatientOfConsultation(command.ConsultationId, memberId))); + return messages; + } +} + +public sealed record GrantMemberAccessToPatientOfConsultation(string ConsultationId, string MemberId); + +public static class GrantMemberAccessToPatientOfConsultationHandler +{ + [AggregateHandler] + public static OutgoingMessages HandleAsync(GrantMemberAccessToPatientOfConsultation command, Consultation consultation) + { + return new(); + } +} \ No newline at end of file