Skip to content

Commit eeb0511

Browse files
committed
Comments from review
1 parent dcb96d5 commit eeb0511

6 files changed

Lines changed: 60 additions & 31 deletions

File tree

src/NServiceBus.AzureFunctions.Analyzer.Tests/AzureFunctionsConfigurationAnalyzerTests.cs renamed to src/NServiceBus.AzureFunctions.Analyzer.Tests/ConfigurationAnalyzerTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
namespace NServiceBus.AzureFunctions.Analyzer.Tests
22
{
3-
using System.Threading;
4-
using System;
53
using System.Threading.Tasks;
64
using NUnit.Framework;
75
using static AzureFunctionsDiagnostics;
86

97
[TestFixture]
10-
public class AzureFunctionsConfigurationAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
8+
public class ConfigurationAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
119
{
1210
[TestCase("DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)", DefineCriticalErrorActionNotAllowedId)]
1311
[TestCase("LimitMessageProcessingConcurrencyTo(5)", LimitMessageProcessingToNotAllowedId)]

src/NServiceBus.AzureFunctions.Analyzer.Tests/AzureFunctionsConfigurationAnalyzerTestsCSharp8.cs renamed to src/NServiceBus.AzureFunctions.Analyzer.Tests/ConfigurationAnalyzerTestsCSharp8.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using static AzureFunctionsDiagnostics;
77

88
[TestFixture]
9-
public class AzureFunctionsConfigurationAnalyzerTestsCSharp8 : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
9+
public class ConfigurationAnalyzerTestsCSharp8 : AnalyzerTestFixture<ConfigurationAnalyzer>
1010
{
1111
// HINT: In C# 7 this call is ambiguous with the LearningTransport version as the compiler cannot differentiate method calls via generic type constraints
1212
[TestCase("UseTransport<AzureServiceBusTransport>()", UseTransportNotAllowedId)]

src/NServiceBus.AzureFunctions.Analyzer.Tests/AzureFunctionsSendReplyOptionsAnalyzerTests.cs renamed to src/NServiceBus.AzureFunctions.Analyzer.Tests/OptionsAnalyzerTests.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ namespace NServiceBus.AzureFunctions.Analyzer.Tests
55
using static AzureFunctionsDiagnostics;
66

77
[TestFixture]
8-
public class AzureFunctionsSendReplyOptionsAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
8+
public class OptionsAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
99
{
10-
[TestCase("SendOptions", "RouteReplyToAnyInstance", RouteReplyToAnyInstanceNotAllowedId)]
1110
[TestCase("SendOptions", "RouteReplyToThisInstance", RouteReplyToThisInstanceNotAllowedId)]
1211
[TestCase("SendOptions", "RouteToThisInstance", RouteToThisInstanceNotAllowedId)]
13-
[TestCase("ReplyOptions", "RouteReplyToAnyInstance", RouteReplyToAnyInstanceNotAllowedId)]
1412
[TestCase("ReplyOptions", "RouteReplyToThisInstance", RouteReplyToThisInstanceNotAllowedId)]
1513
public Task DiagnosticIsReportedForOptions(string optionsType, string method, string diagnosticId)
1614
{
@@ -27,8 +25,6 @@ void Bar({optionsType} options)
2725
return Assert(diagnosticId, source);
2826
}
2927

30-
31-
[TestCase("SomeOtherClass", "RouteReplyToAnyInstance", RouteReplyToAnyInstanceNotAllowedId)]
3228
[TestCase("SomeOtherClass", "RouteReplyToThisInstance", RouteReplyToThisInstanceNotAllowedId)]
3329
[TestCase("SomeOtherClass", "RouteToThisInstance", RouteToThisInstanceNotAllowedId)]
3430
public Task DiagnosticIsNotReportedForOtherOptions(string optionsType, string method, string diagnosticId)

src/NServiceBus.AzureFunctions.Analyzer.Tests/AzureFunctionsTransportAnalyzerTests.cs renamed to src/NServiceBus.AzureFunctions.Analyzer.Tests/TransportConfigurationAnalyzerTests.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ namespace NServiceBus.AzureFunctions.Analyzer.Tests
55
using static AzureFunctionsDiagnostics;
66

77
[TestFixture]
8-
public class AzureFunctionsTransportAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
8+
public class TransportConfigurationAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
99
{
10+
[TestCase("TransportTransactionMode", "TransportTransactionMode.None", TransportTransactionModeNotAllowedId)]
11+
[TestCase("EnablePartitioning", "true", EnablePartitioningNotAllowedId)]
1012
[TestCase("EntityMaximumSize", "5", EntityMaximumSizeNotAllowedId)]
1113
[TestCase("MaxAutoLockRenewalDuration", "new System.TimeSpan(0, 0, 5, 0)", MaxAutoLockRenewalDurationNotAllowedId)]
1214
[TestCase("PrefetchCount", "5", PrefetchCountNotAllowedId)]
1315
[TestCase("PrefetchMultiplier", "5", PrefetchMultiplierNotAllowedId)]
1416
[TestCase("TimeToWaitBeforeTriggeringCircuitBreaker", "new System.TimeSpan(0, 0, 5, 0)", TimeToWaitBeforeTriggeringCircuitBreakerNotAllowedId)]
15-
public Task DiagnosticIsReportedTransportConfiguration(string configName, string configValue, string diagnosticId)
17+
public Task DiagnosticIsReportedTransportConfigurationDirect(string configName, string configValue, string diagnosticId)
1618
{
1719
var source =
1820
$@"using NServiceBus;
@@ -27,7 +29,26 @@ void Direct(ServiceBusTriggeredEndpointConfiguration endpointConfig)
2729
var transportConfig = endpointConfig.Transport;
2830
[|transportConfig.{configName}|] = {configValue};
2931
}}
32+
}}";
33+
34+
return Assert(diagnosticId, source);
35+
}
3036

37+
[TestCase("Transactions", "TransportTransactionMode.None", TransportTransactionModeNotAllowedId)]
38+
[TestCase("EnablePartitioning", "", EnablePartitioningNotAllowedId)]
39+
[TestCase("EntityMaximumSize", "5", EntityMaximumSizeNotAllowedId)]
40+
[TestCase("MaxAutoLockRenewalDuration", "new System.TimeSpan(0, 0, 5, 0)", MaxAutoLockRenewalDurationNotAllowedId)]
41+
[TestCase("PrefetchCount", "5", PrefetchCountNotAllowedId)]
42+
[TestCase("PrefetchMultiplier", "5", PrefetchMultiplierNotAllowedId)]
43+
[TestCase("TimeToWaitBeforeTriggeringCircuitBreaker", "new System.TimeSpan(0, 0, 5, 0)", TimeToWaitBeforeTriggeringCircuitBreakerNotAllowedId)]
44+
public Task DiagnosticIsReportedTransportConfigurationExtension(string configName, string configValue, string diagnosticId)
45+
{
46+
var source =
47+
$@"using NServiceBus;
48+
using System;
49+
using System.Threading.Tasks;
50+
class Foo
51+
{{
3152
void Extension(TransportExtensions<AzureServiceBusTransport> transportExtension)
3253
{{
3354
[|transportExtension.{configName}({configValue})|];
@@ -37,6 +58,7 @@ void Extension(TransportExtensions<AzureServiceBusTransport> transportExtension)
3758
return Assert(diagnosticId, source);
3859
}
3960

61+
[TestCase("EnablePartitioning", "true", EnablePartitioningNotAllowedId)]
4062
[TestCase("EntityMaximumSize", "5", EntityMaximumSizeNotAllowedId)]
4163
[TestCase("MaxAutoLockRenewalDuration", "new System.TimeSpan(0, 0, 5, 0)", MaxAutoLockRenewalDurationNotAllowedId)]
4264
[TestCase("PrefetchCount", "5", PrefetchCountNotAllowedId)]
@@ -52,6 +74,7 @@ public Task DiagnosticIsNotReportedForNonTransportConfiguration(string configNam
5274
class SomeOtherClass
5375
{{
5476
internal int EntityMaximumSize {{ get; set; }}
77+
internal bool EnablePartitioning {{ get; set; }}
5578
internal TimeSpan MaxAutoLockRenewalDuration {{ get; set; }}
5679
internal int PrefetchCount {{ get; set; }}
5780
internal int PrefetchMultiplier {{ get; set; }}

src/NServiceBus.AzureFunctions.Analyzer/AzureFunctionsDiagnostics.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ public static class AzureFunctionsDiagnostics
1313
public const string OverrideLocalAddressNotAllowedId = "NSBFUNC009";
1414
public const string RouteReplyToThisInstanceNotAllowedId = "NSBFUNC010";
1515
public const string RouteToThisInstanceNotAllowedId = "NSBFUNC011";
16-
public const string RouteReplyToAnyInstanceNotAllowedId = "NSBFUNC012";
17-
16+
public const string TransportTransactionModeNotAllowedId = "NSBFUNC012";
1817
public const string MaxAutoLockRenewalDurationNotAllowedId = "NSBFUNC013";
1918
public const string PrefetchCountNotAllowedId = "NSBFUNC014";
2019
public const string PrefetchMultiplierNotAllowedId = "NSBFUNC015";
2120
public const string TimeToWaitBeforeTriggeringCircuitBreakerNotAllowedId = "NSBFUNC016";
2221

2322
public const string EntityMaximumSizeNotAllowedId = "NSBFUNC017";
23+
public const string EnablePartitioningNotAllowedId = "NSBFUNC018";
2424

2525
const string DiagnosticCategory = "NServiceBus.AzureFunctions";
2626

2727
internal static readonly DiagnosticDescriptor PurgeOnStartupNotAllowed = new DiagnosticDescriptor(
2828
id: PurgeOnStartupNotAllowedId,
2929
title: "PurgeOnStartup is not supported in Azure Functions",
30-
messageFormat: "Azure Functions endpoints are started when the first message arrives. PurgeOnStartup may purge whenever a new instance is started.",
30+
messageFormat: "Azure Functions endpoints do not support PurgeOnStartup.",
3131
category: DiagnosticCategory,
3232
defaultSeverity: DiagnosticSeverity.Error,
3333
isEnabledByDefault: true
@@ -36,7 +36,7 @@ public static class AzureFunctionsDiagnostics
3636
internal static readonly DiagnosticDescriptor LimitMessageProcessingToNotAllowed = new DiagnosticDescriptor(
3737
id: LimitMessageProcessingToNotAllowedId,
3838
title: "LimitMessageProcessing is not supported in Azure Functions",
39-
messageFormat: "Azure Functions endpoints do not control the message receiver and cannot limit message processing concurrency.",
39+
messageFormat: "Concurrency-related settings are controlled via the Azure Function host.json configuration file.",
4040
category: DiagnosticCategory,
4141
defaultSeverity: DiagnosticSeverity.Error,
4242
isEnabledByDefault: true
@@ -81,7 +81,7 @@ public static class AzureFunctionsDiagnostics
8181
internal static readonly DiagnosticDescriptor OverrideLocalAddressNotAllowed = new DiagnosticDescriptor(
8282
id: OverrideLocalAddressNotAllowedId,
8383
title: "OverrideLocalAddress is not supported in Azure Functions",
84-
messageFormat: "Azure Functions endpoints do not control the message receiver and cannot decide the local address.",
84+
messageFormat: "The NServiceBus endpoint address in Azure Functions is determined by the ServiceBusTrigger attribute.",
8585
category: DiagnosticCategory,
8686
defaultSeverity: DiagnosticSeverity.Error,
8787
isEnabledByDefault: true
@@ -105,15 +105,6 @@ public static class AzureFunctionsDiagnostics
105105
isEnabledByDefault: true
106106
);
107107

108-
internal static readonly DiagnosticDescriptor RouteReplyToAnyInstanceNotAllowed = new DiagnosticDescriptor(
109-
id: RouteReplyToAnyInstanceNotAllowedId,
110-
title: "RouteReplyToAnyInstance is not supported in Azure Functions",
111-
messageFormat: "Azure Functions endpoints do not control the message receiver and by default route the replies to any instance.",
112-
category: DiagnosticCategory,
113-
defaultSeverity: DiagnosticSeverity.Warning,
114-
isEnabledByDefault: true
115-
);
116-
117108
internal static readonly DiagnosticDescriptor MaxAutoLockRenewalDurationNotAllowed = new DiagnosticDescriptor(
118109
id: MaxAutoLockRenewalDurationNotAllowedId,
119110
title: "MaxAutoLockRenewalDuration is not supported in Azure Functions",
@@ -158,5 +149,23 @@ public static class AzureFunctionsDiagnostics
158149
defaultSeverity: DiagnosticSeverity.Error,
159150
isEnabledByDefault: true
160151
);
152+
153+
internal static readonly DiagnosticDescriptor EnablePartitioningNotAllowed = new DiagnosticDescriptor(
154+
id: EnablePartitioningNotAllowedId,
155+
title: "EnablePartitioning is not supported in Azure Functions",
156+
messageFormat: "Azure Functions endpoints do not support automatic queue creation.",
157+
category: DiagnosticCategory,
158+
defaultSeverity: DiagnosticSeverity.Error,
159+
isEnabledByDefault: true
160+
);
161+
162+
internal static readonly DiagnosticDescriptor TransportTransactionModeNotAllowed = new DiagnosticDescriptor(
163+
id: TransportTransactionModeNotAllowedId,
164+
title: "TransportTransactionMode is not supported in Azure Functions",
165+
messageFormat: "Transport TransactionMode is controlled by the Azure Service Bus trigger and cannot be configured via the NServiceBus transport configuration API when using Azure Functions.",
166+
category: DiagnosticCategory,
167+
defaultSeverity: DiagnosticSeverity.Error,
168+
isEnabledByDefault: true
169+
);
161170
}
162171
}

src/NServiceBus.AzureFunctions.Analyzer/AzureFunctionsConfigurationAnalyzer.cs renamed to src/NServiceBus.AzureFunctions.Analyzer/ConfigurationAnalyzer.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NServiceBus.AzureFunctions.Analyzer
99
using NServiceBus.AzureFunctions.Analyzer.Extensions;
1010

1111
[DiagnosticAnalyzer(LanguageNames.CSharp)]
12-
public class AzureFunctionsConfigurationAnalyzer : DiagnosticAnalyzer
12+
public class ConfigurationAnalyzer : DiagnosticAnalyzer
1313
{
1414
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(
1515
AzureFunctionsDiagnostics.PurgeOnStartupNotAllowed,
@@ -21,12 +21,13 @@ public class AzureFunctionsConfigurationAnalyzer : DiagnosticAnalyzer
2121
AzureFunctionsDiagnostics.OverrideLocalAddressNotAllowed,
2222
AzureFunctionsDiagnostics.RouteReplyToThisInstanceNotAllowed,
2323
AzureFunctionsDiagnostics.RouteToThisInstanceNotAllowed,
24-
AzureFunctionsDiagnostics.RouteReplyToAnyInstanceNotAllowed,
2524
AzureFunctionsDiagnostics.MaxAutoLockRenewalDurationNotAllowed,
2625
AzureFunctionsDiagnostics.PrefetchCountNotAllowed,
2726
AzureFunctionsDiagnostics.PrefetchMultiplierNotAllowed,
2827
AzureFunctionsDiagnostics.TimeToWaitBeforeTriggeringCircuitBreakerNotAllowed,
29-
AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed
28+
AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed,
29+
AzureFunctionsDiagnostics.EnablePartitioningNotAllowed,
30+
AzureFunctionsDiagnostics.TransportTransactionModeNotAllowed
3031
);
3132

3233
static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedEndpointConfigurationMethods
@@ -46,7 +47,6 @@ static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedSendAndReplyO
4647
{
4748
["RouteReplyToThisInstance"] = AzureFunctionsDiagnostics.RouteReplyToThisInstanceNotAllowed,
4849
["RouteToThisInstance"] = AzureFunctionsDiagnostics.RouteToThisInstanceNotAllowed,
49-
["RouteReplyToAnyInstance"] = AzureFunctionsDiagnostics.RouteReplyToAnyInstanceNotAllowed
5050
};
5151

5252
static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedTransportSettings
@@ -56,7 +56,10 @@ static readonly Dictionary<string, DiagnosticDescriptor> NotAllowedTransportSett
5656
["PrefetchCount"] = AzureFunctionsDiagnostics.PrefetchCountNotAllowed,
5757
["PrefetchMultiplier"] = AzureFunctionsDiagnostics.PrefetchMultiplierNotAllowed,
5858
["TimeToWaitBeforeTriggeringCircuitBreaker"] = AzureFunctionsDiagnostics.TimeToWaitBeforeTriggeringCircuitBreakerNotAllowed,
59-
["EntityMaximumSize"] = AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed
59+
["EntityMaximumSize"] = AzureFunctionsDiagnostics.EntityMaximumSizeNotAllowed,
60+
["EnablePartitioning"] = AzureFunctionsDiagnostics.EnablePartitioningNotAllowed,
61+
["TransportTransactionMode"] = AzureFunctionsDiagnostics.TransportTransactionModeNotAllowed,
62+
["Transactions"] = AzureFunctionsDiagnostics.TransportTransactionModeNotAllowed
6063
};
6164

6265
public override void Initialize(AnalysisContext context)
@@ -106,7 +109,7 @@ static void AnalyzeTransport(SyntaxNodeAnalysisContext context)
106109
return;
107110
}
108111

109-
if (propertySymbol.ContainingType.ToString() == "NServiceBus.AzureServiceBusTransport")
112+
if (propertySymbol.ContainingType.ToString() == "NServiceBus.AzureServiceBusTransport" || propertySymbol.ContainingType.ToString() == "NServiceBus.Transport.TransportDefinition")
110113
{
111114
context.ReportDiagnostic(diagnosticDescriptor, memberAccess);
112115

0 commit comments

Comments
 (0)