Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method ordering, xmldoc, and remove obsolete XUnit verifiers #367

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/Analyzers/Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<IncludeShared>false</IncludeShared>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
jviau marked this conversation as resolved.
Show resolved Hide resolved
<!-- Do not publish it until it is ready to release -->
<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Analyzers/Orchestration/OrchestrationContextFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.DurableTask.Analyzers.Orchestration;
/// </summary>
/// <param name="semanticModel">The Semantic Model retrieved from the Document.</param>
/// <param name="knownTypeSymbols">Well-known types that are used by the Durable analyzers.</param>
/// <param name="oldRoot">The root Syntax Node retrieved from the Document.</param>
/// <param name="root">The root Syntax Node retrieved from the Document.</param>
/// <param name="syntaxNodeWithDiagnostic">Syntax Node that contains the diagnostic.</param>
/// <param name="taskOrchestrationContextSymbol">The 'TaskOrchestrationContext' symbol.</param>
public readonly struct OrchestrationCodeFixContext(
Expand Down
26 changes: 13 additions & 13 deletions src/Client/AzureManaged/DurableTaskSchedulerClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public static DurableTaskSchedulerClientOptions FromConnectionString(string conn
return FromConnectionString(new DurableTaskSchedulerConnectionString(connectionString));
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerClientOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerClientOptions"/>.</returns>
internal static DurableTaskSchedulerClientOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

/// <summary>
/// Creates a gRPC channel for communicating with the Durable Task Scheduler service.
/// </summary>
Expand Down Expand Up @@ -96,19 +109,6 @@ this.Credential is not null
});
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerClientOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerClientOptions"/>.</returns>
internal static DurableTaskSchedulerClientOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

static TokenCredential? GetCredentialFromConnectionString(DurableTaskSchedulerConnectionString connectionString)
{
string authType = connectionString.Authentication;
Expand Down
26 changes: 13 additions & 13 deletions src/Worker/AzureManaged/DurableTaskSchedulerWorkerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public static DurableTaskSchedulerWorkerOptions FromConnectionString(string conn
return FromConnectionString(new DurableTaskSchedulerConnectionString(connectionString));
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerWorkerOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerWorkerOptions"/>.</returns>
internal static DurableTaskSchedulerWorkerOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

/// <summary>
/// Creates a gRPC channel for communicating with the Durable Task Scheduler service.
/// </summary>
Expand Down Expand Up @@ -103,19 +116,6 @@ this.Credential is not null
});
}

/// <summary>
/// Creates a new instance of <see cref="DurableTaskSchedulerWorkerOptions"/> from a parsed connection string.
/// </summary>
/// <param name="connectionString">The connection string to parse.</param>
/// <returns>A new instance of <see cref="DurableTaskSchedulerWorkerOptions"/>.</returns>
internal static DurableTaskSchedulerWorkerOptions FromConnectionString(
DurableTaskSchedulerConnectionString connectionString) => new()
{
EndpointAddress = connectionString.Endpoint,
TaskHubName = connectionString.TaskHubName,
Credential = GetCredentialFromConnectionString(connectionString),
};

static TokenCredential? GetCredentialFromConnectionString(DurableTaskSchedulerConnectionString connectionString)
{
string authType = connectionString.Authentication;
Expand Down
4 changes: 2 additions & 2 deletions test/Analyzers.Tests/Analyzers.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing.XUnit" Version="1.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,11 @@ static DateTime MyRunAsync(TaskOrchestrationContext context)

DiagnosticResult expected = BuildDiagnostic().WithLocation(0).WithArguments("MyRunAsync", "System.DateTime.Now", "MyRun");

await VerifyCS.VerifyDurableTaskCodeFixAsync(code, expected, fix);
await VerifyCS.VerifyDurableTaskCodeFixAsync(code, expected, fix, test =>
{
// TODO: CodeFixBehaviors.SkipLocalDiagnosticCheck is failing this test. This is apparently a bad analyzer practice.
test.CodeFixTestBehaviors |= CodeFixTestBehaviors.SkipLocalDiagnosticCheck;
jviau marked this conversation as resolved.
Show resolved Hide resolved
});
}


Expand Down
9 changes: 4 additions & 5 deletions test/Analyzers.Tests/Verifiers/CSharpAnalyzerVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace Microsoft.DurableTask.Analyzers.Tests.Verifiers;

Expand All @@ -14,15 +13,15 @@ public static partial class CSharpAnalyzerVerifier<TAnalyzer>
{
/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.Diagnostic()"/>
public static DiagnosticResult Diagnostic()
=> CSharpAnalyzerVerifier<TAnalyzer, XUnitVerifier>.Diagnostic();
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic();

/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.Diagnostic(string)"/>
public static DiagnosticResult Diagnostic(string diagnosticId)
=> CSharpAnalyzerVerifier<TAnalyzer, XUnitVerifier>.Diagnostic(diagnosticId);
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(diagnosticId);

/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.Diagnostic(DiagnosticDescriptor)"/>
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> CSharpAnalyzerVerifier<TAnalyzer, XUnitVerifier>.Diagnostic(descriptor);
=> CSharpAnalyzerVerifier<TAnalyzer, DefaultVerifier>.Diagnostic(descriptor);

/// <inheritdoc cref="AnalyzerVerifier{TAnalyzer, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
Expand All @@ -36,7 +35,7 @@ public static async Task VerifyAnalyzerAsync(string source, params DiagnosticRes
await test.RunAsync(CancellationToken.None);
}

public class Test : CSharpAnalyzerTest<TAnalyzer, XUnitVerifier>
public class Test : CSharpAnalyzerTest<TAnalyzer, DefaultVerifier>
{
}
}
14 changes: 9 additions & 5 deletions test/Analyzers.Tests/Verifiers/CSharpCodeFixVerifier.Durable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,30 @@ public static Task VerifyDurableTaskAnalyzerAsync(string source, params Diagnost
return VerifyDurableTaskAnalyzerAsync(source, null, expected);
}

public static async Task VerifyDurableTaskAnalyzerAsync(string source, Action<Test>? configureTest = null, params DiagnosticResult[] expected)
public static async Task VerifyDurableTaskAnalyzerAsync(
string source, Action<Test>? configureTest = null, params DiagnosticResult[] expected)
{
await RunAsync(expected, new Test()
{
TestCode = source,
}, configureTest);
}

public static Task VerifyDurableTaskCodeFixAsync(string source, DiagnosticResult expected, string fixedSource)
public static Task VerifyDurableTaskCodeFixAsync(
string source, DiagnosticResult expected, string fixedSource, Action<Test>? configureTest = null)
{
return VerifyDurableTaskCodeFixAsync(source, [expected], fixedSource);
return VerifyDurableTaskCodeFixAsync(source, [expected], fixedSource, configureTest);
}

public static async Task VerifyDurableTaskCodeFixAsync(string source, DiagnosticResult[] expected, string fixedSource)
public static async Task VerifyDurableTaskCodeFixAsync(
string source, DiagnosticResult[] expected, string fixedSource, Action<Test>? configureTest = null)
{
await RunAsync(expected, new Test()
{
TestCode = source,
FixedCode = fixedSource,
});
},
configureTest);
}

static async Task RunAsync(DiagnosticResult[] expected, Test test, Action<Test>? configureTest = null)
Expand Down
9 changes: 4 additions & 5 deletions test/Analyzers.Tests/Verifiers/CSharpCodeFixVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace Microsoft.DurableTask.Analyzers.Tests.Verifiers;

Expand All @@ -16,15 +15,15 @@ public static partial class CSharpCodeFixVerifier<TAnalyzer, TCodeFix>
{
/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic()"/>
public static DiagnosticResult Diagnostic()
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic();
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic();

/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(string)"/>
public static DiagnosticResult Diagnostic(string diagnosticId)
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic(diagnosticId);
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(diagnosticId);

/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(DiagnosticDescriptor)"/>
public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, XUnitVerifier>.Diagnostic(descriptor);
=> CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(descriptor);

/// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
public static async Task VerifyAnalyzerAsync(string source, params DiagnosticResult[] expected)
Expand Down Expand Up @@ -59,7 +58,7 @@ public static async Task VerifyCodeFixAsync(string source, DiagnosticResult[] ex
await test.RunAsync(CancellationToken.None);
}

public class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, XUnitVerifier>
public class Test : CSharpCodeFixTest<TAnalyzer, TCodeFix, DefaultVerifier>
{
}
}
2 changes: 1 addition & 1 deletion test/Generators.Tests/Generators.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit" Version="1.1.*" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.9.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.9.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="3.9.0" PrivateAssets="all" />
Expand Down
3 changes: 1 addition & 2 deletions test/Generators.Tests/Utils/CSharpSourceGeneratorVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Testing;
using Microsoft.CodeAnalysis.Testing.Verifiers;

namespace Microsoft.DurableTask.Generators.Tests.Utils;

// Mostly copy/pasted from the Microsoft Source Generators testing documentation
public static class CSharpSourceGeneratorVerifier<TSourceGenerator> where TSourceGenerator : ISourceGenerator, new()
{
public class Test : CSharpSourceGeneratorTest<TSourceGenerator, XUnitVerifier>
public class Test : CSharpSourceGeneratorTest<TSourceGenerator, DefaultVerifier>
{
public Test()
{
Expand Down
Loading