Skip to content

Commit 8af8552

Browse files
committed
Merge diagnostics
1 parent c12e063 commit 8af8552

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed

src/NServiceBus.Core.Analyzer.Tests.Common/Sagas/SagaAnalyzerTests.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class Msg1 : ICommand
3535
public string CorrId { get; set; }
3636
}";
3737

38-
return Assert([DiagnosticIds.SagaMappingExpressionCanBeRewritten], source, mustCompile: false);
38+
return Assert([DiagnosticIds.SagaMappingExpressionCanBeSimplified], source, mustCompile: false);
3939
}
4040

4141
[Test]
@@ -143,6 +143,40 @@ public class Msg1 : ICommand;
143143
return Assert(source);
144144
}
145145

146+
[Test]
147+
public Task NoDiagnosticForConfigureNotFoundHandler()
148+
{
149+
var source =
150+
@"using System;
151+
using System.Threading.Tasks;
152+
using NServiceBus;
153+
public class MySaga : Saga<MyData>, IAmStartedByMessages<Msg1>
154+
{
155+
protected override void ConfigureHowToFindSaga(SagaPropertyMapper<MyData> mapper)
156+
{
157+
mapper.MapSaga(saga => saga.CorrId).ToMessage<Msg1>(msg => msg.CorrId);
158+
159+
mapper.ConfigureNotFoundHandler<MyNotFoundHandler>();
160+
}
161+
public Task Handle(Msg1 message, IMessageHandlerContext context) => throw new NotImplementedException();
162+
}
163+
public class MyData : ContainSagaData
164+
{
165+
public string CorrId { get; set; }
166+
public string OtherId { get; set; }
167+
}
168+
public class Msg1 : ICommand
169+
{
170+
public string CorrId { get; set; }
171+
}
172+
public class MyNotFoundHandler : ISagaNotFoundHandler
173+
{
174+
public Task Handle(object message, IMessageProcessingContext context) => Task.CompletedTask;
175+
}";
176+
177+
return Assert([], source, mustCompile: false);
178+
}
179+
146180
[Test]
147181
public Task SagaDataPropertyHasNonPublicSetter()
148182
{

src/NServiceBus.Core.Analyzer/DiagnosticIds.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class DiagnosticIds
2323
public const string SagaShouldNotImplementNotFoundHandler = "NSB0015";
2424
public const string CorrelationPropertyTypeMustMatchMessageMappingExpressions = "NSB0016";
2525
public const string ToSagaMappingMustBeToAProperty = "NSB0017";
26-
public const string SagaMappingExpressionCanBeRewritten = "NSB0018";
26+
public const string SagaMappingExpressionCanBeRewritten = "NSB0018"; // Unused, merged into NSB0004
2727
public const string DoNotEnableFeaturesInDefaults = "NSB0019";
2828
public const string HandlerInjectsMessageSession = "NSB0020";
2929
public const string AddHandlerOnSagaType = "NSB0021";

src/NServiceBus.Core.Analyzer/Sagas/SagaAnalyzer.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public class SagaAnalyzer : DiagnosticAnalyzer
2929
SagaDiagnostics.SagaShouldNotHaveIntermediateBaseClass,
3030
SagaDiagnostics.SagaShouldNotImplementNotFoundHandler,
3131
SagaDiagnostics.ToSagaMappingMustBeToAProperty,
32-
SagaDiagnostics.CorrelationPropertyTypeMustMatchMessageMappingExpressions,
33-
SagaDiagnostics.SagaMappingExpressionCanBeRewritten
32+
SagaDiagnostics.CorrelationPropertyTypeMustMatchMessageMappingExpressions
3433
];
3534

3635
public override void Initialize(AnalysisContext context)
@@ -153,25 +152,14 @@ static void AnalyzeSagaClass(SyntaxNodeAnalysisContext context, ClassDeclaration
153152
}
154153
}
155154
}
156-
else if (nonCustomFinderMapping.Select(m => m.ToSagaSyntax).Distinct().Count() > 1)
157-
{
158-
Diagnostic diagnostic = CreateMappingRewritingDiagnostic(
159-
fixerTitle: "Simplify saga mapping expression",
160-
descriptor: SagaDiagnostics.SagaMappingExpressionCanBeSimplified,
161-
location: saga.ConfigureHowToFindMethod.Identifier.GetLocation(),
162-
newMappingForLocation: null,
163-
correlationId: assumedCorrelationId,
164-
saga: saga);
165-
context.ReportDiagnostic(diagnostic);
166-
}
167155
else
168156
{
169157
var mappingMethodNames = nonCustomFinderMapping.Select(m => (m.MessageTypeSyntax?.Parent?.Parent as GenericNameSyntax)?.Identifier.ValueText);
170158
if (mappingMethodNames.Any(name => name is "ConfigureMapping" or "ConfigureHeaderMapping"))
171159
{
172160
Diagnostic diagnostic = CreateMappingRewritingDiagnostic(
173161
fixerTitle: "Rewrite saga mapping expression",
174-
descriptor: SagaDiagnostics.SagaMappingExpressionCanBeRewritten,
162+
descriptor: SagaDiagnostics.SagaMappingExpressionCanBeSimplified,
175163
location: saga.ConfigureHowToFindMethod.Identifier.GetLocation(),
176164
newMappingForLocation: null,
177165
correlationId: assumedCorrelationId,

src/NServiceBus.Core.Analyzer/Sagas/SagaDiagnostics.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,5 @@ static class SagaDiagnostics
129129
category: DiagnosticCategory,
130130
defaultSeverity: DiagnosticSeverity.Error,
131131
isEnabledByDefault: true);
132-
133-
public static readonly DiagnosticDescriptor SagaMappingExpressionCanBeRewritten = new(
134-
id: DiagnosticIds.SagaMappingExpressionCanBeRewritten,
135-
title: "Saga mapping expressions must be rewritten",
136-
messageFormat: "This saga mapping expression must be rewritten using mapper.MapSaga(…).ToMessage<T>(…) syntax. Use the code fix to transition to the new syntax.",
137-
category: DiagnosticCategory,
138-
defaultSeverity: DiagnosticSeverity.Error,
139-
isEnabledByDefault: true);
140132
}
141133
}

0 commit comments

Comments
 (0)