Skip to content

Commit df50c2f

Browse files
committed
Add 'CSharpCodeFixTest<,>' type
1 parent 8524021 commit df50c2f

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/CommunityToolkit.DependencyPropertyGenerator.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<PackageReference Include="MSTest.TestAdapter" Version="3.6.3" />
2020
<PackageReference Include="MSTest.TestFramework" Version="3.6.3" />
2121
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
22-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0-3.final" />
22+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" />
23+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
2324
</ItemGroup>
2425

2526
<ItemGroup>

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/Helpers/CSharpAnalyzerTest{TAnalyzer}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using Windows.UI.Xaml;
1414
using CommunityToolkit.WinUI;
1515

16-
namespace CommunityToolkit.Mvvm.SourceGenerators.UnitTests.Helpers;
16+
namespace CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers;
1717

1818
/// <summary>
1919
/// A custom <see cref="CSharpAnalyzerTest{TAnalyzer, TVerifier}"/> that uses a specific C# language version to parse code.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.CodeAnalysis.CSharp;
6+
using Microsoft.CodeAnalysis.Diagnostics;
7+
using Microsoft.CodeAnalysis.Testing;
8+
using Microsoft.CodeAnalysis;
9+
using Microsoft.CodeAnalysis.CodeFixes;
10+
using Microsoft.CodeAnalysis.CSharp.Testing;
11+
12+
namespace CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers;
13+
14+
/// <summary>
15+
/// A custom <see cref="CSharpCodeFixTest{TAnalyzer, TCodeFix, TVerifier}"/> that uses a specific C# language version to parse code.
16+
/// </summary>
17+
/// <typeparam name="TAnalyzer">The type of the analyzer to produce diagnostics.</typeparam>
18+
/// <typeparam name="TCodeFixer">The type of code fix to test.</typeparam>
19+
internal sealed class CSharpCodeFixTest<TAnalyzer, TCodeFixer> : CSharpCodeFixTest<TAnalyzer, TCodeFixer, DefaultVerifier>
20+
where TAnalyzer : DiagnosticAnalyzer, new()
21+
where TCodeFixer : CodeFixProvider, new()
22+
{
23+
/// <summary>
24+
/// The C# language version to use to parse code.
25+
/// </summary>
26+
private readonly LanguageVersion languageVersion;
27+
28+
/// <summary>
29+
/// Creates a new <see cref="CSharpCodeFixWithLanguageVersionTest{TAnalyzer, TCodeFix, TVerifier}"/> instance with the specified parameters.
30+
/// </summary>
31+
/// <param name="languageVersion">The C# language version to use to parse code.</param>
32+
public CSharpCodeFixTest(LanguageVersion languageVersion)
33+
{
34+
this.languageVersion = languageVersion;
35+
}
36+
37+
/// <inheritdoc/>
38+
protected override ParseOptions CreateParseOptions()
39+
{
40+
return new CSharpParseOptions(this.languageVersion, DocumentationMode.Diagnose);
41+
}
42+
}

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/Test_Analyzers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Threading.Tasks;
6-
using CommunityToolkit.Mvvm.SourceGenerators.UnitTests.Helpers;
6+
using CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers;
77
using Microsoft.CodeAnalysis.CSharp;
88
using Microsoft.VisualStudio.TestTools.UnitTesting;
99

0 commit comments

Comments
 (0)