-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df50c2f
commit 7f57e6c
Showing
3 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...cyPropertyGenerator.Tests/Test_UseGeneratedDependencyPropertyOnManualPropertyCodeFixer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Threading.Tasks; | ||
using CommunityToolkit.WinUI; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.Testing; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Windows.UI.ViewManagement; | ||
using Windows.UI.Xaml; | ||
using CSharpCodeFixTest = CommunityToolkit.GeneratedDependencyProperty.Tests.Helpers.CSharpCodeFixTest< | ||
CommunityToolkit.GeneratedDependencyProperty.UseGeneratedDependencyPropertyOnManualPropertyAnalyzer, | ||
CommunityToolkit.GeneratedDependencyProperty.UseGeneratedDependencyPropertyOnManualPropertyCodeFixer>; | ||
using VerifyCS = Microsoft.CodeAnalysis.CSharp.Testing.CSharpCodeFixVerifier< | ||
CommunityToolkit.GeneratedDependencyProperty.UseGeneratedDependencyPropertyOnManualPropertyAnalyzer, | ||
CommunityToolkit.GeneratedDependencyProperty.UseGeneratedDependencyPropertyOnManualPropertyCodeFixer, | ||
Microsoft.CodeAnalysis.Testing.DefaultVerifier>; | ||
|
||
namespace CommunityToolkit.GeneratedDependencyProperty.Tests; | ||
|
||
[TestClass] | ||
public class Test_UseGeneratedDependencyPropertyOnManualPropertyCodeFixer | ||
{ | ||
[TestMethod] | ||
[DataRow("string", "string")] | ||
[DataRow("string", "string?")] | ||
[DataRow("object", "object")] | ||
[DataRow("object", "object?")] | ||
[DataRow("int", "int")] | ||
[DataRow("int?", "int?")] | ||
public async Task SimpleProperty(string underlyingType, string propertyType) | ||
{ | ||
string original = $$""" | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
namespace MyApp; | ||
public class MyControl : Control | ||
{ | ||
public static readonly DependencyProperty NameProperty = DependencyProperty.Register( | ||
name: nameof(Name), | ||
propertyType: typeof({{underlyingType}}), | ||
ownerType: typeof(MyControl), | ||
typeMetadata: null); | ||
public {{propertyType}} [|Name|] | ||
{ | ||
get => ({{propertyType}})GetValue(NameProperty); | ||
set => SetValue(NameProperty, value); | ||
} | ||
} | ||
"""; | ||
|
||
string @fixed = $$""" | ||
using CommunityToolkit.WinUI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
namespace MyApp; | ||
public partial class MyControl : Control | ||
{ | ||
[GeneratedDependencyProperty] | ||
public partial {{propertyType}} {|CS9248:Name|} { get; set; } | ||
} | ||
"""; | ||
|
||
CSharpCodeFixTest test = new(LanguageVersion.Preview) | ||
{ | ||
TestCode = original, | ||
FixedCode = @fixed, | ||
ReferenceAssemblies = ReferenceAssemblies.Net.Net80, | ||
TestState = { AdditionalReferences = | ||
{ | ||
MetadataReference.CreateFromFile(typeof(ApplicationView).Assembly.Location), | ||
MetadataReference.CreateFromFile(typeof(DependencyProperty).Assembly.Location), | ||
MetadataReference.CreateFromFile(typeof(GeneratedDependencyPropertyAttribute).Assembly.Location) | ||
}} | ||
}; | ||
|
||
await test.RunAsync(); | ||
} | ||
} |