Skip to content

Commit 3bb143a

Browse files
committed
Simplify tests
1 parent 20b341b commit 3bb143a

3 files changed

Lines changed: 32 additions & 379 deletions

File tree

Lines changed: 17 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,25 @@
11
namespace NServiceBus.AzureFunctions.Analyzer.Tests
22
{
33
using System.Threading.Tasks;
4+
using Microsoft.CodeAnalysis.CSharp;
45
using NUnit.Framework;
56

67
[TestFixture]
78
public class AzureFunctionsConfigurationAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
89
{
9-
[Test]
10-
public Task DiagnosticIsReportedForPurgeOnStartup()
10+
[TestCase("DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)", AzureFunctionsDiagnostics.DefineCriticalErrorActionNotAllowedId, LanguageVersion.CSharp7)]
11+
[TestCase("LimitMessageProcessingConcurrencyTo(5)", AzureFunctionsDiagnostics.LimitMessageProcessingToNotAllowedId, LanguageVersion.CSharp7)]
12+
[TestCase("MakeInstanceUniquelyAddressable(null)", AzureFunctionsDiagnostics.MakeInstanceUniquelyAddressableNotAllowedId, LanguageVersion.CSharp7)]
13+
[TestCase("OverrideLocalAddress(null)", AzureFunctionsDiagnostics.OverrideLocalAddressNotAllowedId, LanguageVersion.CSharp7)]
14+
[TestCase("PurgeOnStartup(true)", AzureFunctionsDiagnostics.PurgeOnStartupNotAllowedId, LanguageVersion.CSharp7)]
15+
[TestCase("SetDiagnosticsPath(null)", AzureFunctionsDiagnostics.SetDiagnosticsPathNotAllowedId, LanguageVersion.CSharp7)]
16+
// HINT: In C# 7 this call is ambiguous with the LearningTransport version as the compiler cannot differentiate method calls via generic type constraints
17+
[TestCase("UseTransport<AzureServiceBusTransport>()", AzureFunctionsDiagnostics.UseTransportNotAllowedId, LanguageVersion.CSharp8)]
18+
[TestCase("UseTransport(new AzureServiceBusTransport(null))", AzureFunctionsDiagnostics.UseTransportNotAllowedId, LanguageVersion.CSharp7)]
19+
public Task DiagnosticIsReportedForEndpointConfiguration(string configuration, string diagnosticId, LanguageVersion minimumLangVersion)
1120
{
12-
var source =
13-
$@"using NServiceBus;
14-
using System;
15-
using System.Threading.Tasks;
16-
class Foo
17-
{{
18-
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
19-
{{
20-
[|endpointConfig.AdvancedConfiguration.PurgeOnStartup(true)|];
21-
22-
var advancedConfig = endpointConfig.AdvancedConfiguration;
23-
[|advancedConfig.PurgeOnStartup(true)|];
24-
}}
25-
}}";
26-
27-
return Assert(AzureFunctionsDiagnostics.PurgeOnStartupNotAllowedId, source);
28-
}
29-
30-
[Test]
31-
public Task DiagnosticIsReportedForLimitMessageProcessingConcurrencyTo()
32-
{
33-
var source =
34-
$@"using NServiceBus;
35-
using System;
36-
using System.Threading.Tasks;
37-
class Foo
38-
{{
39-
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
40-
{{
41-
[|endpointConfig.AdvancedConfiguration.LimitMessageProcessingConcurrencyTo(5)|];
42-
43-
var advancedConfig = endpointConfig.AdvancedConfiguration;
44-
[|advancedConfig.LimitMessageProcessingConcurrencyTo(5)|];
45-
}}
46-
}}";
47-
48-
return Assert(AzureFunctionsDiagnostics.LimitMessageProcessingToNotAllowedId, source);
49-
}
50-
51-
[Test]
52-
public Task DiagnosticIsReportedForDefineCriticalErrorAction()
53-
{
54-
var source =
55-
$@"using NServiceBus;
56-
using System;
57-
using System.Threading.Tasks;
58-
class Foo
59-
{{
60-
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
61-
{{
62-
[|endpointConfig.AdvancedConfiguration.DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)|];
63-
64-
var advancedConfig = endpointConfig.AdvancedConfiguration;
65-
[|advancedConfig.DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)|];
66-
}}
67-
}}";
68-
69-
return Assert(AzureFunctionsDiagnostics.DefineCriticalErrorActionNotAllowedId, source);
70-
}
71-
72-
[Test]
73-
public Task DiagnosticIsReportedForSetDiagnosticsPath()
74-
{
75-
var source =
76-
$@"using NServiceBus;
77-
using System;
78-
using System.Threading.Tasks;
79-
class Foo
80-
{{
81-
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
82-
{{
83-
[|endpointConfig.AdvancedConfiguration.SetDiagnosticsPath(null)|];
84-
85-
var advancedConfig = endpointConfig.AdvancedConfiguration;
86-
[|advancedConfig.SetDiagnosticsPath(null)|];
87-
}}
88-
}}";
89-
90-
return Assert(AzureFunctionsDiagnostics.SetDiagnosticsPathNotAllowedId, source);
91-
}
21+
testSpecificLangVersion = minimumLangVersion;
9222

93-
[Test]
94-
public Task DiagnosticIsReportedForMakeInstanceUniquelyAddressable()
95-
{
9623
var source =
9724
$@"using NServiceBus;
9825
using System;
@@ -101,57 +28,17 @@ class Foo
10128
{{
10229
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
10330
{{
104-
[|endpointConfig.AdvancedConfiguration.MakeInstanceUniquelyAddressable(null)|];
31+
[|endpointConfig.AdvancedConfiguration.{configuration}|];
10532
10633
var advancedConfig = endpointConfig.AdvancedConfiguration;
107-
[|advancedConfig.MakeInstanceUniquelyAddressable(null)|];
34+
[|advancedConfig.{configuration}|];
10835
}}
10936
}}";
11037

111-
return Assert(AzureFunctionsDiagnostics.MakeInstanceUniquelyAddressableNotAllowedId, source);
38+
return Assert(diagnosticId, source);
11239
}
11340

114-
// TODO: Figue out how to test UseTransport<T> extensions
115-
[Test]
116-
public Task DiagnosticIsReportedForUseTransport()
117-
{
118-
var source =
119-
$@"using NServiceBus;
120-
using System;
121-
using System.Threading.Tasks;
122-
class Foo
123-
{{
124-
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
125-
{{
126-
[|endpointConfig.AdvancedConfiguration.UseTransport(new AzureServiceBusTransport(null))|];
127-
128-
var advancedConfig = endpointConfig.AdvancedConfiguration;
129-
[|advancedConfig.UseTransport(new AzureServiceBusTransport(null))|];
130-
}}
131-
}}";
132-
133-
return Assert(AzureFunctionsDiagnostics.UseTransportNotAllowedId, source);
134-
}
135-
136-
[Test]
137-
public Task DiagnosticIsReportedForOverrideLocalAddress()
138-
{
139-
var source =
140-
$@"using NServiceBus;
141-
using System;
142-
using System.Threading.Tasks;
143-
class Foo
144-
{{
145-
void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
146-
{{
147-
[|endpointConfig.AdvancedConfiguration.OverrideLocalAddress(null)|];
148-
149-
var advancedConfig = endpointConfig.AdvancedConfiguration;
150-
[|advancedConfig.OverrideLocalAddress(null)|];
151-
}}
152-
}}";
153-
154-
return Assert(AzureFunctionsDiagnostics.OverrideLocalAddressNotAllowedId, source);
155-
}
41+
LanguageVersion testSpecificLangVersion;
42+
protected override LanguageVersion AnalyzerLanguageVersion => testSpecificLangVersion;
15643
}
15744
}

src/NServiceBus.AzureFunctions.Analyzer.Tests/AzureFunctionsSendReplyOptionsAnalyzerTests.cs

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,67 +6,24 @@ namespace NServiceBus.AzureFunctions.Analyzer.Tests
66
[TestFixture]
77
public class AzureFunctionsSendReplyOptionsAnalyzerTests : AnalyzerTestFixture<AzureFunctionsConfigurationAnalyzer>
88
{
9-
[Test]
10-
public Task DiagnosticIsReportedForRouteReplyToThisInstance()
9+
[TestCase("SendOptions", "RouteReplyToAnyInstance", AzureFunctionsDiagnostics.RouteReplyToAnyInstanceNotAllowedId)]
10+
[TestCase("SendOptions", "RouteReplyToThisInstance", AzureFunctionsDiagnostics.RouteReplyToThisInstanceNotAllowedId)]
11+
[TestCase("SendOptions", "RouteToThisInstance", AzureFunctionsDiagnostics.RouteToThisInstanceNotAllowedId)]
12+
[TestCase("ReplyOptions", "RouteReplyToAnyInstance", AzureFunctionsDiagnostics.RouteReplyToAnyInstanceNotAllowedId)]
13+
[TestCase("ReplyOptions", "RouteReplyToThisInstance", AzureFunctionsDiagnostics.RouteReplyToThisInstanceNotAllowedId)]
14+
public Task DiagnosticIsReportedForOptions(string optionsType, string method, string diagnosticId)
1115
{
1216
var source =
1317
$@"using NServiceBus;
14-
using System;
15-
using System.Threading.Tasks;
1618
class Foo
1719
{{
18-
void Bar()
20+
void Bar({optionsType} options)
1921
{{
20-
var replyOptions = new ReplyOptions();
21-
[|replyOptions.RouteReplyToThisInstance()|];
22-
23-
var sendOptions = new SendOptions();
24-
[|sendOptions.RouteReplyToThisInstance()|];
25-
}}
26-
}}";
27-
28-
return Assert(AzureFunctionsDiagnostics.RouteReplyToThisInstanceNotAllowedId, source);
29-
}
30-
31-
[Test]
32-
public Task DiagnosticIsReportedForRouteToThisInstance()
33-
{
34-
var source =
35-
$@"using NServiceBus;
36-
using System;
37-
using System.Threading.Tasks;
38-
class Foo
39-
{{
40-
void Bar()
41-
{{
42-
var options = new SendOptions();
43-
[|options.RouteToThisInstance()|];
44-
}}
45-
}}";
46-
47-
return Assert(AzureFunctionsDiagnostics.RouteToThisInstanceNotAllowedId, source);
48-
}
49-
50-
[Test]
51-
public Task DiagnosticIsReportedForRouteReplyToAnyInstance()
52-
{
53-
var source =
54-
$@"using NServiceBus;
55-
using System;
56-
using System.Threading.Tasks;
57-
class Foo
58-
{{
59-
void Bar()
60-
{{
61-
var options = new SendOptions();
62-
[|options.RouteReplyToAnyInstance()|];
63-
64-
var replyOptions = new ReplyOptions();
65-
[|replyOptions.RouteReplyToAnyInstance()|];
22+
[|options.{method}()|];
6623
}}
6724
}}";
6825

69-
return Assert(AzureFunctionsDiagnostics.RouteReplyToAnyInstanceNotAllowedId, source);
26+
return Assert(diagnosticId, source);
7027
}
7128
}
7229
}

0 commit comments

Comments
 (0)