|
| 1 | +namespace NServiceBus.AcceptanceTests.Core.Conventions; |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using AcceptanceTesting; |
| 6 | +using EndpointTemplates; |
| 7 | +using NServiceBus.AcceptanceTesting.Customization; |
| 8 | +using NUnit.Framework; |
| 9 | + |
| 10 | +public class When_scanning_an_assembly_containing_a_ref_struct_and_sagas_enabled : NServiceBusAcceptanceTest |
| 11 | +{ |
| 12 | + [Test] |
| 13 | + public void It_should_not_throw_an_exception() |
| 14 | + => Assert.DoesNotThrowAsync( |
| 15 | + () => Scenario.Define<ScenarioContext>() |
| 16 | + .WithEndpoint<EndpointWithASaga>() |
| 17 | + .Run() |
| 18 | + ); |
| 19 | + |
| 20 | + // HINT: This will get picked up by the AssemblyRouteSource created by the routing call below |
| 21 | + // Even though it is not a message type, it is still checked by passing it to conventions. |
| 22 | + // The conventions added by Sagas were throwing an exception when passed a ref struct. |
| 23 | + // See https://github.com/Particular/NServiceBus/issues/7179 for details. |
| 24 | + ref struct RefStruct { } |
| 25 | + |
| 26 | + class EndpointWithASaga : EndpointConfigurationBuilder |
| 27 | + { |
| 28 | + public EndpointWithASaga() => EndpointSetup<DefaultServer>(cfg => cfg |
| 29 | + .ConfigureRouting() |
| 30 | + .RouteToEndpoint( |
| 31 | + typeof(RefStruct).Assembly, |
| 32 | + Conventions.EndpointNamingConvention(typeof(EndpointWithASaga)) |
| 33 | + ) |
| 34 | + ); |
| 35 | + |
| 36 | + class RealSagaToSetUpConventions : Saga<RealSagaToSetUpConventions.RealSagaToSetUpConventionsSagaData>, IAmStartedByMessages<SomeMessage> |
| 37 | + { |
| 38 | + public Task Handle(SomeMessage message, IMessageHandlerContext context) => Task.CompletedTask; |
| 39 | + protected override void ConfigureHowToFindSaga(SagaPropertyMapper<RealSagaToSetUpConventionsSagaData> mapper) |
| 40 | + => mapper.MapSaga(saga => saga.BusinessId).ToMessage<SomeMessage>(msg => msg.BusinessId); |
| 41 | + |
| 42 | + public class RealSagaToSetUpConventionsSagaData : ContainSagaData |
| 43 | + { |
| 44 | + public virtual Guid BusinessId { get; set; } |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + public class SomeMessage : IMessage |
| 50 | + { |
| 51 | + public Guid BusinessId { get; set; } |
| 52 | + } |
| 53 | +} |
0 commit comments