Skip to content

Commit 7524a0c

Browse files
committed
Simplify code fixer tests
1 parent b65e899 commit 7524a0c

File tree

2 files changed

+16
-51
lines changed

2 files changed

+16
-51
lines changed

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/Helpers/CSharpCodeFixerTest{TAnalyzer,TCodeFixer}.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using CommunityToolkit.WinUI;
56
using Microsoft.CodeAnalysis.CSharp;
67
using Microsoft.CodeAnalysis.Diagnostics;
78
using Microsoft.CodeAnalysis.Testing;
89
using Microsoft.CodeAnalysis;
910
using Microsoft.CodeAnalysis.CodeFixes;
1011
using Microsoft.CodeAnalysis.CSharp.Testing;
12+
using Windows.Foundation;
13+
using Windows.UI.ViewManagement;
14+
using Windows.UI.Xaml;
1115

1216
namespace CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers;
1317

@@ -32,6 +36,13 @@ internal sealed class CSharpCodeFixTest<TAnalyzer, TCodeFixer> : CSharpCodeFixTe
3236
public CSharpCodeFixTest(LanguageVersion languageVersion)
3337
{
3438
this.languageVersion = languageVersion;
39+
40+
ReferenceAssemblies = ReferenceAssemblies.Net.Net80;
41+
TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(Point).Assembly.Location));
42+
TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(ApplicationView).Assembly.Location));
43+
TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(DependencyProperty).Assembly.Location));
44+
TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(typeof(GeneratedDependencyPropertyAttribute).Assembly.Location));
45+
TestState.AnalyzerConfigFiles.Add(("/.editorconfig", "[*]\nend_of_line = lf"));
3546
}
3647

3748
/// <inheritdoc/>

components/DependencyPropertyGenerator/CommunityToolkit.DependencyPropertyGenerator.Tests/Test_UseGeneratedDependencyPropertyOnManualPropertyCodeFixer.cs

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.Threading.Tasks;
6-
using CommunityToolkit.WinUI;
7-
using Microsoft.CodeAnalysis;
86
using Microsoft.CodeAnalysis.CSharp;
9-
using Microsoft.CodeAnalysis.Testing;
107
using Microsoft.VisualStudio.TestTools.UnitTesting;
11-
using Windows.Foundation;
12-
using Windows.UI.ViewManagement;
13-
using Windows.UI.Xaml;
148
using CSharpCodeFixTest = CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers.CSharpCodeFixTest<
159
CommunityToolkit.GeneratedDependencyProperty.UseGeneratedDependencyPropertyOnManualPropertyAnalyzer,
1610
CommunityToolkit.GeneratedDependencyProperty.UseGeneratedDependencyPropertyOnManualPropertyCodeFixer>;
@@ -110,15 +104,7 @@ public class MyClass { }
110104
CSharpCodeFixTest test = new(LanguageVersion.Preview)
111105
{
112106
TestCode = original,
113-
FixedCode = @fixed,
114-
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
115-
TestState = { AdditionalReferences =
116-
{
117-
MetadataReference.CreateFromFile(typeof(Point).Assembly.Location),
118-
MetadataReference.CreateFromFile(typeof(ApplicationView).Assembly.Location),
119-
MetadataReference.CreateFromFile(typeof(DependencyProperty).Assembly.Location),
120-
MetadataReference.CreateFromFile(typeof(GeneratedDependencyPropertyAttribute).Assembly.Location)
121-
}}
107+
FixedCode = @fixed
122108
};
123109

124110
await test.RunAsync();
@@ -178,15 +164,7 @@ public enum MyEnum { A, B, C }
178164
CSharpCodeFixTest test = new(LanguageVersion.Preview)
179165
{
180166
TestCode = original,
181-
FixedCode = @fixed,
182-
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
183-
TestState = { AdditionalReferences =
184-
{
185-
MetadataReference.CreateFromFile(typeof(Point).Assembly.Location),
186-
MetadataReference.CreateFromFile(typeof(ApplicationView).Assembly.Location),
187-
MetadataReference.CreateFromFile(typeof(DependencyProperty).Assembly.Location),
188-
MetadataReference.CreateFromFile(typeof(GeneratedDependencyPropertyAttribute).Assembly.Location)
189-
}}
167+
FixedCode = @fixed
190168
};
191169

192170
await test.RunAsync();
@@ -270,15 +248,7 @@ public partial class MyControl : Control
270248
CSharpCodeFixTest test = new(LanguageVersion.Preview)
271249
{
272250
TestCode = original,
273-
FixedCode = @fixed,
274-
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
275-
TestState = { AdditionalReferences =
276-
{
277-
MetadataReference.CreateFromFile(typeof(Point).Assembly.Location),
278-
MetadataReference.CreateFromFile(typeof(ApplicationView).Assembly.Location),
279-
MetadataReference.CreateFromFile(typeof(DependencyProperty).Assembly.Location),
280-
MetadataReference.CreateFromFile(typeof(GeneratedDependencyPropertyAttribute).Assembly.Location)
281-
}}
251+
FixedCode = @fixed
282252
};
283253

284254
await test.RunAsync();
@@ -345,15 +315,7 @@ public enum MyEnum { A }
345315
CSharpCodeFixTest test = new(LanguageVersion.Preview)
346316
{
347317
TestCode = original,
348-
FixedCode = @fixed,
349-
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
350-
TestState = { AdditionalReferences =
351-
{
352-
MetadataReference.CreateFromFile(typeof(Point).Assembly.Location),
353-
MetadataReference.CreateFromFile(typeof(ApplicationView).Assembly.Location),
354-
MetadataReference.CreateFromFile(typeof(DependencyProperty).Assembly.Location),
355-
MetadataReference.CreateFromFile(typeof(GeneratedDependencyPropertyAttribute).Assembly.Location)
356-
}}
318+
FixedCode = @fixed
357319
};
358320

359321
await test.RunAsync();
@@ -406,15 +368,7 @@ public partial class MyControl : Control
406368
CSharpCodeFixTest test = new(LanguageVersion.Preview)
407369
{
408370
TestCode = original,
409-
FixedCode = @fixed,
410-
ReferenceAssemblies = ReferenceAssemblies.Net.Net80,
411-
TestState = { AdditionalReferences =
412-
{
413-
MetadataReference.CreateFromFile(typeof(Point).Assembly.Location),
414-
MetadataReference.CreateFromFile(typeof(ApplicationView).Assembly.Location),
415-
MetadataReference.CreateFromFile(typeof(DependencyProperty).Assembly.Location),
416-
MetadataReference.CreateFromFile(typeof(GeneratedDependencyPropertyAttribute).Assembly.Location)
417-
}}
371+
FixedCode = @fixed
418372
};
419373

420374
await test.RunAsync();

0 commit comments

Comments
 (0)