Skip to content

Commit c28a3c4

Browse files
Harden saga correlation property parsing (#7637)
* Add more gnarly test cases to tighten up the saga correlation property retrieval * Sort diagnostics in test outputs and generator by location and details --------- Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com>
1 parent af0ea5b commit c28a3c4

File tree

26 files changed

+4465
-32
lines changed

26 files changed

+4465
-32
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
// == NServiceBus.Core.Analyzer/NServiceBus.Core.Analyzer.Sagas.AddSagaGenerator/HandlerRegistrations.Sagas.g.cs =======
2+
// <auto-generated/>
3+
4+
#nullable enable annotations
5+
#nullable disable warnings
6+
7+
// Suppress warnings about [Obsolete] member usage in generated code.
8+
#pragma warning disable CS0612, CS0618
9+
10+
namespace NServiceBus
11+
{
12+
public static partial class CastSyntaxWrappersHandlerRegistryExtensions
13+
{
14+
public sealed partial class CastSyntaxWrappersRootRegistry
15+
{
16+
partial void AddAllSagasCore()
17+
{
18+
AddOrderShippingPolicy();
19+
}
20+
21+
/// <summary>
22+
/// Registers the <see cref="global::OrderShippingPolicy"/> saga with the endpoint configuration.
23+
/// </summary>
24+
public void AddOrderShippingPolicy()
25+
{
26+
var sagaMetadataCollection = NServiceBus.Configuration.AdvancedExtensibility.AdvancedExtensibilityExtensions.GetSettings(_configuration)
27+
.GetOrCreate<NServiceBus.Sagas.SagaMetadataCollection>();
28+
var associatedMessages = new NServiceBus.Sagas.SagaMessage[]
29+
{
30+
new NServiceBus.Sagas.SagaMessage(typeof(global::OrderPlaced), true, false),
31+
};
32+
NServiceBus.Sagas.MessagePropertyAccessor[] propertyAccessors = [
33+
OrderPlacedOrderIdAccessor_5f69124e5a7de2e1.Instance,
34+
];
35+
var metadata = NServiceBus.Sagas.SagaMetadata.Create<global::OrderShippingPolicy, global::OrderShippingPolicyData>(associatedMessages, OrderIdAsStringAccessor_4a76700cf8410b3a.Instance, propertyAccessors);
36+
sagaMetadataCollection.Add(metadata);
37+
38+
var settings = NServiceBus.Configuration.AdvancedExtensibility.AdvancedExtensibilityExtensions.GetSettings(_configuration);
39+
var messageHandlerRegistry = settings.GetOrCreate<NServiceBus.Unicast.MessageHandlerRegistry>();
40+
var messageMetadataRegistry = settings.GetOrCreate<NServiceBus.Unicast.Messages.MessageMetadataRegistry>();
41+
messageHandlerRegistry.AddMessageHandlerForMessage<global::OrderShippingPolicy, global::OrderPlaced>();
42+
messageMetadataRegistry.RegisterMessageTypeWithHierarchy(typeof(global::OrderPlaced), []);
43+
}
44+
}
45+
}
46+
47+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("NService.Core.Analyzer.Tests", "1.0.0")]
48+
file sealed class OrderPlacedOrderIdAccessor_5f69124e5a7de2e1 : NServiceBus.Sagas.MessagePropertyAccessor<global::OrderPlaced>
49+
{
50+
OrderPlacedOrderIdAccessor_5f69124e5a7de2e1() { }
51+
52+
protected override object? AccessFrom(global::OrderPlaced message) => AccessFrom_Property(message);
53+
54+
[global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "get_OrderId")]
55+
static extern string AccessFrom_Property(global::OrderPlaced message);
56+
57+
public static readonly NServiceBus.Sagas.MessagePropertyAccessor Instance = new OrderPlacedOrderIdAccessor_5f69124e5a7de2e1();
58+
}
59+
60+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("NService.Core.Analyzer.Tests", "1.0.0")]
61+
file sealed class OrderIdAsStringAccessor_4a76700cf8410b3a : NServiceBus.Sagas.CorrelationPropertyAccessor
62+
{
63+
OrderIdAsStringAccessor_4a76700cf8410b3a() { }
64+
65+
public override object? AccessFrom(NServiceBus.IContainSagaData sagaData) => AccessFrom_Property(sagaData);
66+
67+
[global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "get_OrderId")]
68+
static extern string AccessFrom_Property(NServiceBus.IContainSagaData sagaData);
69+
70+
public override void WriteTo(NServiceBus.IContainSagaData sagaData, object value) => WriteTo_Property(sagaData, ((string)value));
71+
72+
[global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "set_OrderId")]
73+
static extern string WriteTo_Property(NServiceBus.IContainSagaData sagaData, string value);
74+
75+
public static readonly NServiceBus.Sagas.CorrelationPropertyAccessor Instance = new OrderIdAsStringAccessor_4a76700cf8410b3a();
76+
}
77+
}
78+
79+
// == NServiceBus.Core.Analyzer/NServiceBus.Core.Analyzer.AddHandlerAndSagasRegistrationGenerator/HandlerRegistrations.g.cs ==
80+
// <auto-generated/>
81+
82+
#nullable enable annotations
83+
#nullable disable warnings
84+
85+
// Suppress warnings about [Obsolete] member usage in generated code.
86+
#pragma warning disable CS0612, CS0618
87+
88+
namespace NServiceBus
89+
{
90+
/// <summary>
91+
/// Provides access to handler and saga registries discovered in the <i>CastSyntaxWrappers</i> assembly.
92+
/// </summary>
93+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("NService.Core.Analyzer.Tests", "1.0.0")]
94+
public static partial class CastSyntaxWrappersHandlerRegistryExtensions
95+
{
96+
extension (global::NServiceBus.HandlerRegistry registry)
97+
{
98+
/// <summary>
99+
/// Gets the root registry for handler and saga types in the <i>CastSyntaxWrappers</i> assembly.
100+
/// </summary>
101+
/// <remarks>
102+
/// Use the returned registry to access namespace-specific registries and add-all methods for this assembly.
103+
/// </remarks>
104+
public CastSyntaxWrappersRootRegistry CastSyntaxWrappersAssembly => new(registry.Configuration);
105+
}
106+
107+
/// <summary>
108+
/// Root registry to add handlers and sagas for the entire assembly.
109+
/// </summary>
110+
public sealed partial class CastSyntaxWrappersRootRegistry(global::NServiceBus.EndpointConfiguration configuration)
111+
{
112+
readonly global::NServiceBus.EndpointConfiguration _configuration = configuration ?? throw new System.ArgumentNullException(nameof(configuration));
113+
114+
/// <summary>
115+
/// Registers all handlers and sagas for this namespace segment and its child namespaces.
116+
/// </summary>
117+
/// <remarks>
118+
/// Includes sagas in this namespace: <see cref="AddOrderShippingPolicy"/>.
119+
/// </remarks>
120+
public void AddAll()
121+
{
122+
AddAllHandlers();
123+
AddAllSagas();
124+
}
125+
126+
/// <summary>
127+
/// Registers all handlers for this namespace segment and its child namespaces.
128+
/// </summary>
129+
public void AddAllHandlers()
130+
{
131+
AddAllHandlersCore();
132+
}
133+
134+
/// <summary>
135+
/// Registers all sagas for this namespace segment and its child namespaces.
136+
/// </summary>
137+
/// <remarks>
138+
/// Includes sagas in this namespace: <see cref="AddOrderShippingPolicy"/>.
139+
/// </remarks>
140+
public void AddAllSagas()
141+
{
142+
AddAllSagasCore();
143+
}
144+
145+
partial void AddAllHandlersCore();
146+
partial void AddAllSagasCore();
147+
}
148+
}
149+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// == Compilation Diagnostics ==========================================================================================
2+
test.cs(18,50): error CS0229: Ambiguity between 'OrderPlaced.OrderId' and 'OrderPlaced.OrderId'
3+
test.cs(36,19): error CS0102: The type 'OrderPlaced' already contains a definition for 'OrderId'
4+
5+
// == NServiceBus.Core.Analyzer/NServiceBus.Core.Analyzer.Sagas.AddSagaGenerator/HandlerRegistrations.Sagas.g.cs =======
6+
// <auto-generated/>
7+
8+
#nullable enable annotations
9+
#nullable disable warnings
10+
11+
// Suppress warnings about [Obsolete] member usage in generated code.
12+
#pragma warning disable CS0612, CS0618
13+
14+
namespace NServiceBus
15+
{
16+
public static partial class DuplicatePropertyDefinitionsWithCompilationErrorsHandlerRegistryExtensions
17+
{
18+
public sealed partial class DuplicatePropertyDefinitionsWithCompilationErrorsRootRegistry
19+
{
20+
partial void AddAllSagasCore()
21+
{
22+
AddOrderShippingPolicy();
23+
}
24+
25+
/// <summary>
26+
/// Registers the <see cref="global::OrderShippingPolicy"/> saga with the endpoint configuration.
27+
/// </summary>
28+
public void AddOrderShippingPolicy()
29+
{
30+
var sagaMetadataCollection = NServiceBus.Configuration.AdvancedExtensibility.AdvancedExtensibilityExtensions.GetSettings(_configuration)
31+
.GetOrCreate<NServiceBus.Sagas.SagaMetadataCollection>();
32+
var associatedMessages = new NServiceBus.Sagas.SagaMessage[]
33+
{
34+
new NServiceBus.Sagas.SagaMessage(typeof(global::OrderPlaced), true, false),
35+
};
36+
NServiceBus.Sagas.MessagePropertyAccessor[] propertyAccessors = [
37+
OrderPlacedOrderIdAccessor_5f69124e5a7de2e1.Instance,
38+
];
39+
var metadata = NServiceBus.Sagas.SagaMetadata.Create<global::OrderShippingPolicy, global::OrderShippingPolicyData>(associatedMessages, OrderIdAsStringAccessor_4a76700cf8410b3a.Instance, propertyAccessors);
40+
sagaMetadataCollection.Add(metadata);
41+
42+
var settings = NServiceBus.Configuration.AdvancedExtensibility.AdvancedExtensibilityExtensions.GetSettings(_configuration);
43+
var messageHandlerRegistry = settings.GetOrCreate<NServiceBus.Unicast.MessageHandlerRegistry>();
44+
var messageMetadataRegistry = settings.GetOrCreate<NServiceBus.Unicast.Messages.MessageMetadataRegistry>();
45+
messageHandlerRegistry.AddMessageHandlerForMessage<global::OrderShippingPolicy, global::OrderPlaced>();
46+
messageMetadataRegistry.RegisterMessageTypeWithHierarchy(typeof(global::OrderPlaced), []);
47+
}
48+
}
49+
}
50+
51+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("NService.Core.Analyzer.Tests", "1.0.0")]
52+
file sealed class OrderPlacedOrderIdAccessor_5f69124e5a7de2e1 : NServiceBus.Sagas.MessagePropertyAccessor<global::OrderPlaced>
53+
{
54+
OrderPlacedOrderIdAccessor_5f69124e5a7de2e1() { }
55+
56+
protected override object? AccessFrom(global::OrderPlaced message) => AccessFrom_Property(message);
57+
58+
[global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "get_OrderId")]
59+
static extern string AccessFrom_Property(global::OrderPlaced message);
60+
61+
public static readonly NServiceBus.Sagas.MessagePropertyAccessor Instance = new OrderPlacedOrderIdAccessor_5f69124e5a7de2e1();
62+
}
63+
64+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("NService.Core.Analyzer.Tests", "1.0.0")]
65+
file sealed class OrderIdAsStringAccessor_4a76700cf8410b3a : NServiceBus.Sagas.CorrelationPropertyAccessor
66+
{
67+
OrderIdAsStringAccessor_4a76700cf8410b3a() { }
68+
69+
public override object? AccessFrom(NServiceBus.IContainSagaData sagaData) => AccessFrom_Property(sagaData);
70+
71+
[global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "get_OrderId")]
72+
static extern string AccessFrom_Property(NServiceBus.IContainSagaData sagaData);
73+
74+
public override void WriteTo(NServiceBus.IContainSagaData sagaData, object value) => WriteTo_Property(sagaData, ((string)value));
75+
76+
[global::System.Runtime.CompilerServices.UnsafeAccessor(global::System.Runtime.CompilerServices.UnsafeAccessorKind.Method, Name = "set_OrderId")]
77+
static extern string WriteTo_Property(NServiceBus.IContainSagaData sagaData, string value);
78+
79+
public static readonly NServiceBus.Sagas.CorrelationPropertyAccessor Instance = new OrderIdAsStringAccessor_4a76700cf8410b3a();
80+
}
81+
}
82+
83+
// == NServiceBus.Core.Analyzer/NServiceBus.Core.Analyzer.AddHandlerAndSagasRegistrationGenerator/HandlerRegistrations.g.cs ==
84+
// <auto-generated/>
85+
86+
#nullable enable annotations
87+
#nullable disable warnings
88+
89+
// Suppress warnings about [Obsolete] member usage in generated code.
90+
#pragma warning disable CS0612, CS0618
91+
92+
namespace NServiceBus
93+
{
94+
/// <summary>
95+
/// Provides access to handler and saga registries discovered in the <i>DuplicatePropertyDefinitionsWithCompilationErrors</i> assembly.
96+
/// </summary>
97+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("NService.Core.Analyzer.Tests", "1.0.0")]
98+
public static partial class DuplicatePropertyDefinitionsWithCompilationErrorsHandlerRegistryExtensions
99+
{
100+
extension (global::NServiceBus.HandlerRegistry registry)
101+
{
102+
/// <summary>
103+
/// Gets the root registry for handler and saga types in the <i>DuplicatePropertyDefinitionsWithCompilationErrors</i> assembly.
104+
/// </summary>
105+
/// <remarks>
106+
/// Use the returned registry to access namespace-specific registries and add-all methods for this assembly.
107+
/// </remarks>
108+
public DuplicatePropertyDefinitionsWithCompilationErrorsRootRegistry DuplicatePropertyDefinitionsWithCompilationErrorsAssembly => new(registry.Configuration);
109+
}
110+
111+
/// <summary>
112+
/// Root registry to add handlers and sagas for the entire assembly.
113+
/// </summary>
114+
public sealed partial class DuplicatePropertyDefinitionsWithCompilationErrorsRootRegistry(global::NServiceBus.EndpointConfiguration configuration)
115+
{
116+
readonly global::NServiceBus.EndpointConfiguration _configuration = configuration ?? throw new System.ArgumentNullException(nameof(configuration));
117+
118+
/// <summary>
119+
/// Registers all handlers and sagas for this namespace segment and its child namespaces.
120+
/// </summary>
121+
/// <remarks>
122+
/// Includes sagas in this namespace: <see cref="AddOrderShippingPolicy"/>.
123+
/// </remarks>
124+
public void AddAll()
125+
{
126+
AddAllHandlers();
127+
AddAllSagas();
128+
}
129+
130+
/// <summary>
131+
/// Registers all handlers for this namespace segment and its child namespaces.
132+
/// </summary>
133+
public void AddAllHandlers()
134+
{
135+
AddAllHandlersCore();
136+
}
137+
138+
/// <summary>
139+
/// Registers all sagas for this namespace segment and its child namespaces.
140+
/// </summary>
141+
/// <remarks>
142+
/// Includes sagas in this namespace: <see cref="AddOrderShippingPolicy"/>.
143+
/// </remarks>
144+
public void AddAllSagas()
145+
{
146+
AddAllSagasCore();
147+
}
148+
149+
partial void AddAllHandlersCore();
150+
partial void AddAllSagasCore();
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)