Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Custom.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup>
<MinVerMinimumMajorMinor>5.0</MinVerMinimumMajorMinor>
<MinVerMinimumMajorMinor>6.0</MinVerMinimumMajorMinor>
<MinVerAutoIncrement>minor</MinVerAutoIncrement>
</PropertyGroup>

Expand Down
317 changes: 158 additions & 159 deletions src/IntegrationTests.HostV4/When_starting_the_function_host.cs

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests
{
using System.Threading.Tasks;
using NUnit.Framework;
using static AzureFunctionsDiagnostics;
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests;

using System.Threading.Tasks;
using NUnit.Framework;
using static AzureFunctionsDiagnostics;

[TestFixture]
public class ConfigurationAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
[TestFixture]
public class ConfigurationAnalyzerTests : AnalyzerTestFixture<ConfigurationAnalyzer>
{
[TestCase("DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)", DefineCriticalErrorActionNotAllowedId)]
[TestCase("LimitMessageProcessingConcurrencyTo(5)", LimitMessageProcessingToNotAllowedId)]
[TestCase("MakeInstanceUniquelyAddressable(null)", MakeInstanceUniquelyAddressableNotAllowedId)]
[TestCase("OverrideLocalAddress(null)", OverrideLocalAddressNotAllowedId)]
[TestCase("PurgeOnStartup(true)", PurgeOnStartupNotAllowedId)]
[TestCase("SetDiagnosticsPath(null)", SetDiagnosticsPathNotAllowedId)]
[TestCase("UseTransport(new AzureServiceBusTransport(null, default(TopicTopology)))", UseTransportNotAllowedId)]
public Task DiagnosticIsReportedForEndpointConfiguration(string configuration, string diagnosticId)
{
[TestCase("DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)", DefineCriticalErrorActionNotAllowedId)]
[TestCase("LimitMessageProcessingConcurrencyTo(5)", LimitMessageProcessingToNotAllowedId)]
[TestCase("MakeInstanceUniquelyAddressable(null)", MakeInstanceUniquelyAddressableNotAllowedId)]
[TestCase("OverrideLocalAddress(null)", OverrideLocalAddressNotAllowedId)]
[TestCase("PurgeOnStartup(true)", PurgeOnStartupNotAllowedId)]
[TestCase("SetDiagnosticsPath(null)", SetDiagnosticsPathNotAllowedId)]
[TestCase("UseTransport(new AzureServiceBusTransport(null, default(TopicTopology)))", UseTransportNotAllowedId)]
public Task DiagnosticIsReportedForEndpointConfiguration(string configuration, string diagnosticId)
{
var source =
$@"using NServiceBus;
var source =
$@"using NServiceBus;
using System;
using System.Threading.Tasks;
class Foo
Expand All @@ -31,20 +31,20 @@ void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
}}
}}";

return Assert(diagnosticId, source);
}
return Assert(diagnosticId, source);
}

[TestCase("DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)", DefineCriticalErrorActionNotAllowedId)]
[TestCase("LimitMessageProcessingConcurrencyTo(5)", LimitMessageProcessingToNotAllowedId)]
[TestCase("MakeInstanceUniquelyAddressable(null)", MakeInstanceUniquelyAddressableNotAllowedId)]
[TestCase("OverrideLocalAddress(null)", OverrideLocalAddressNotAllowedId)]
[TestCase("PurgeOnStartup(true)", PurgeOnStartupNotAllowedId)]
[TestCase("SetDiagnosticsPath(null)", SetDiagnosticsPathNotAllowedId)]
[TestCase("UseTransport(new AzureServiceBusTransport(null, default(TopicTopology)))", UseTransportNotAllowedId)]
public Task DiagnosticIsNotReportedForOtherEndpointConfiguration(string configuration, string diagnosticId)
{
var source =
$@"using NServiceBus;
[TestCase("DefineCriticalErrorAction((errorContext, cancellationToken) => Task.CompletedTask)", DefineCriticalErrorActionNotAllowedId)]
[TestCase("LimitMessageProcessingConcurrencyTo(5)", LimitMessageProcessingToNotAllowedId)]
[TestCase("MakeInstanceUniquelyAddressable(null)", MakeInstanceUniquelyAddressableNotAllowedId)]
[TestCase("OverrideLocalAddress(null)", OverrideLocalAddressNotAllowedId)]
[TestCase("PurgeOnStartup(true)", PurgeOnStartupNotAllowedId)]
[TestCase("SetDiagnosticsPath(null)", SetDiagnosticsPathNotAllowedId)]
[TestCase("UseTransport(new AzureServiceBusTransport(null, default(TopicTopology)))", UseTransportNotAllowedId)]
public Task DiagnosticIsNotReportedForOtherEndpointConfiguration(string configuration, string diagnosticId)
{
var source =
$@"using NServiceBus;
using System;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -68,7 +68,6 @@ void Bar(SomeOtherClass endpointConfig)
}}
}}";

return Assert(diagnosticId, source);
}
return Assert(diagnosticId, source);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests
{
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using NUnit.Framework;
using static AzureFunctionsDiagnostics;
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests;

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp;
using NUnit.Framework;
using static AzureFunctionsDiagnostics;

[TestFixture]
public class ConfigurationAnalyzerTestsCSharp8 : AnalyzerTestFixture<ConfigurationAnalyzer>
[TestFixture]
public class ConfigurationAnalyzerTestsCSharp8 : AnalyzerTestFixture<ConfigurationAnalyzer>
{
// HINT: In C# 7 this call is ambiguous with the LearningTransport version as the compiler cannot differentiate method calls via generic type constraints
[TestCase("UseTransport<AzureServiceBusTransport>(null)", UseTransportNotAllowedId)]
public Task DiagnosticIsReportedForEndpointConfiguration(string configuration, string diagnosticId)
{
// HINT: In C# 7 this call is ambiguous with the LearningTransport version as the compiler cannot differentiate method calls via generic type constraints
[TestCase("UseTransport<AzureServiceBusTransport>(null)", UseTransportNotAllowedId)]
public Task DiagnosticIsReportedForEndpointConfiguration(string configuration, string diagnosticId)
{
var source =
$@"using NServiceBus;
var source =
$@"using NServiceBus;
using System;
using System.Threading.Tasks;
class Foo
Expand All @@ -27,8 +27,7 @@ void Bar(ServiceBusTriggeredEndpointConfiguration endpointConfig)
}}
}}";

return Assert(diagnosticId, source);
}
protected override LanguageVersion AnalyzerLanguageVersion => LanguageVersion.CSharp8;
return Assert(diagnosticId, source);
}
protected override LanguageVersion AnalyzerLanguageVersion => LanguageVersion.CSharp8;
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,59 @@
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests;

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;

static class CompilationExtensions
{
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;

static class CompilationExtensions
public static void Compile(this Compilation compilation, bool throwOnFailure = true)
{
public static void Compile(this Compilation compilation, bool throwOnFailure = true)
using (var peStream = new MemoryStream())
{
using (var peStream = new MemoryStream())
{
var emitResult = compilation.Emit(peStream);
var emitResult = compilation.Emit(peStream);

if (!emitResult.Success)
if (!emitResult.Success)
{
if (throwOnFailure)
{
if (throwOnFailure)
{
throw new Exception("Compilation failed.");
}
else
{
Debug.WriteLine("Compilation failed.");
}
throw new Exception("Compilation failed.");
}
else
{
Debug.WriteLine("Compilation failed.");
}
}
}
}

public static async Task<IEnumerable<Diagnostic>> GetAnalyzerDiagnostics(this Compilation compilation, DiagnosticAnalyzer analyzer, CancellationToken cancellationToken = default)
{
var exceptions = new List<Exception>();

var analysisOptions = new CompilationWithAnalyzersOptions(
new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty),
(exception, _, __) => exceptions.Add(exception),
concurrentAnalysis: false,
logAnalyzerExecutionTime: false);
public static async Task<IEnumerable<Diagnostic>> GetAnalyzerDiagnostics(this Compilation compilation, DiagnosticAnalyzer analyzer, CancellationToken cancellationToken = default)
{
var exceptions = new List<Exception>();

var diagnostics = await compilation
.WithAnalyzers([analyzer], analysisOptions)
.GetAnalyzerDiagnosticsAsync(cancellationToken);
var analysisOptions = new CompilationWithAnalyzersOptions(
new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty),
(exception, _, __) => exceptions.Add(exception),
concurrentAnalysis: false,
logAnalyzerExecutionTime: false);

if (exceptions.Any())
{
throw new AggregateException(exceptions);
}
var diagnostics = await compilation
.WithAnalyzers([analyzer], analysisOptions)
.GetAnalyzerDiagnosticsAsync(cancellationToken);

return diagnostics
.OrderBy(diagnostic => diagnostic.Location.SourceSpan)
.ThenBy(diagnostic => diagnostic.Id);
if (exceptions.Any())
{
throw new AggregateException(exceptions);
}

return diagnostics
.OrderBy(diagnostic => diagnostic.Location.SourceSpan)
.ThenBy(diagnostic => diagnostic.Id);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests
namespace NServiceBus.AzureFunctions.InProcess.Analyzer.Tests;

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Simplification;

static class DocumentExtensions
{
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Simplification;
public static async Task<IEnumerable<Diagnostic>> GetCompilerDiagnostics(this Document document, CancellationToken cancellationToken = default) =>
(await document.GetSemanticModelAsync(cancellationToken))
.GetDiagnostics(cancellationToken: cancellationToken)
.Where(diagnostic => diagnostic.Severity != DiagnosticSeverity.Hidden)
.OrderBy(diagnostic => diagnostic.Location.SourceSpan)
.ThenBy(diagnostic => diagnostic.Id);

static class DocumentExtensions
public static async Task<(Document Document, CodeAction Action)[]> GetCodeActions(this Project project, CodeFixProvider codeFix, Diagnostic diagnostic, CancellationToken cancellationToken = default)
{
public static async Task<IEnumerable<Diagnostic>> GetCompilerDiagnostics(this Document document, CancellationToken cancellationToken = default) =>
(await document.GetSemanticModelAsync(cancellationToken))
.GetDiagnostics(cancellationToken: cancellationToken)
.Where(diagnostic => diagnostic.Severity != DiagnosticSeverity.Hidden)
.OrderBy(diagnostic => diagnostic.Location.SourceSpan)
.ThenBy(diagnostic => diagnostic.Id);

public static async Task<(Document Document, CodeAction Action)[]> GetCodeActions(this Project project, CodeFixProvider codeFix, Diagnostic diagnostic, CancellationToken cancellationToken = default)
var actions = new List<(Document, CodeAction)>();
foreach (var document in project.Documents)
{
var actions = new List<(Document, CodeAction)>();
foreach (var document in project.Documents)
{
var context = new CodeFixContext(document, diagnostic, (action, _) => actions.Add((document, action)), cancellationToken);
await codeFix.RegisterCodeFixesAsync(context);
}
return actions.ToArray();
var context = new CodeFixContext(document, diagnostic, (action, _) => actions.Add((document, action)), cancellationToken);
await codeFix.RegisterCodeFixesAsync(context);
}
return actions.ToArray();
}

public static async Task<Document> ApplyChanges(this Document document, CodeAction codeAction, CancellationToken cancellationToken = default)
{
var operations = await codeAction.GetOperationsAsync(cancellationToken);
var solution = operations.OfType<ApplyChangesOperation>().Single().ChangedSolution;
return solution.GetDocument(document.Id);
}
public static async Task<Document> ApplyChanges(this Document document, CodeAction codeAction, CancellationToken cancellationToken = default)
{
var operations = await codeAction.GetOperationsAsync(cancellationToken);
var solution = operations.OfType<ApplyChangesOperation>().Single().ChangedSolution;
return solution.GetDocument(document.Id);
}

public static async Task<string> GetCode(this Document document, CancellationToken cancellationToken = default)
{
var simplifiedDoc = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken);
var root = await simplifiedDoc.GetSyntaxRootAsync(cancellationToken);
root = Formatter.Format(root, Formatter.Annotation, simplifiedDoc.Project.Solution.Workspace, cancellationToken: cancellationToken);
return root.GetText().ToString();
}
public static async Task<string> GetCode(this Document document, CancellationToken cancellationToken = default)
{
var simplifiedDoc = await Simplifier.ReduceAsync(document, Simplifier.Annotation, cancellationToken: cancellationToken);
var root = await simplifiedDoc.GetSyntaxRootAsync(cancellationToken);
root = Formatter.Format(root, Formatter.Annotation, simplifiedDoc.Project.Solution.Workspace, cancellationToken: cancellationToken);
return root.GetText().ToString();
}
}
}
Loading