diff --git a/src/EventSourcingTests/Bugs/Bug_3665_compiling_with_private_members.cs b/src/EventSourcingTests/Bugs/Bug_3665_compiling_with_private_members.cs new file mode 100644 index 0000000000..de83ed7cb1 --- /dev/null +++ b/src/EventSourcingTests/Bugs/Bug_3665_compiling_with_private_members.cs @@ -0,0 +1,56 @@ +using System; +using System.Threading.Tasks; +using Marten.Events; +using Marten.Events.Projections; +using Marten.Testing.Harness; +using Shouldly; +using Xunit; + +namespace EventSourcingTests.Bugs; + +public class Bug_3665_compiling_with_private_members : BugIntegrationContext +{ + [Fact] + public async Task try_to_compile_self_aggregate() + { + StoreOptions(opts => + { + opts.Projections.Snapshot(SnapshotLifecycle.Inline); + opts.Events.StreamIdentity = StreamIdentity.AsString; + }); + + var id = Guid.NewGuid().ToString(); + theSession.Events.StartStream(id, new ProductCreated(id, "Shoes")); + await theSession.SaveChangesAsync(); + + var product = await theSession.LoadAsync(id); + product.Name.ShouldBe("Shoes"); + } +} + +public record ProductCreated(string Id, string Name); + +public record ProductNameChanged(string NewName); + +public record ProductRemoved; + + +public class Product +{ + public string Id { get; set; } + public string Name { get; set; } + + public Product() { } + + public Product(ProductCreated cr) + { + Id = cr.Id; + Name = cr.Name; + } + + private void Apply(ProductNameChanged ev) => Name = ev.NewName; + + private bool ShouldDelete(ProductRemoved ev) => true; +} + + diff --git a/src/Marten/Events/CodeGeneration/MethodCollection.cs b/src/Marten/Events/CodeGeneration/MethodCollection.cs index 3fda7737b0..631a600b9b 100644 --- a/src/Marten/Events/CodeGeneration/MethodCollection.cs +++ b/src/Marten/Events/CodeGeneration/MethodCollection.cs @@ -54,6 +54,7 @@ protected MethodCollection(string methodName, Type projectionType, Type aggregat protected MethodCollection(string[] methodNames, Type projectionType, Type aggregateType) { + LambdaName = methodNames.First(); _validArgumentTypes.Add(typeof(CancellationToken)); MethodNames.AddRange(methodNames); @@ -78,7 +79,6 @@ protected MethodCollection(string[] methodNames, Type projectionType, Type aggre IsAsync = Methods.Select(x => x.Method).OfType().Any(x => x.IsAsync()); - LambdaName = methodNames.First(); } public Type ProjectionType { get; } diff --git a/src/ValueTypeTests/ValueTypeTests.csproj b/src/ValueTypeTests/ValueTypeTests.csproj index 091c7c91b1..9c436481a3 100644 --- a/src/ValueTypeTests/ValueTypeTests.csproj +++ b/src/ValueTypeTests/ValueTypeTests.csproj @@ -10,7 +10,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive