Skip to content

Commit 9924f77

Browse files
committed
Add more code fixer tests
1 parent 191e386 commit 9924f77

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed

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

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,146 @@ public partial class MyControl : Control
373373

374374
await test.RunAsync();
375375
}
376+
377+
[TestMethod]
378+
public async Task MultipleProperties_HandlesSpacingCorrectly()
379+
{
380+
string original = $$"""
381+
using Windows.UI.Xaml;
382+
using Windows.UI.Xaml.Controls;
383+
384+
#nullable enable
385+
386+
namespace MyApp;
387+
388+
public partial class MyControl : Control
389+
{
390+
public static readonly DependencyProperty Name1Property = DependencyProperty.Register(
391+
name: "Name1",
392+
propertyType: typeof(string),
393+
ownerType: typeof(MyControl),
394+
typeMetadata: null);
395+
396+
public static readonly DependencyProperty Name2Property = DependencyProperty.Register(
397+
name: "Name2",
398+
propertyType: typeof(string),
399+
ownerType: typeof(MyControl),
400+
typeMetadata: null);
401+
402+
public string? [|Name1|]
403+
{
404+
get => (string?)GetValue(Name1Property);
405+
set => SetValue(Name1Property, value);
406+
}
407+
408+
public string? [|Name2|]
409+
{
410+
get => (string?)GetValue(Name2Property);
411+
set => SetValue(Name2Property, value);
412+
}
413+
}
414+
""";
415+
416+
string @fixed = $$"""
417+
using CommunityToolkit.WinUI;
418+
using Windows.UI.Xaml;
419+
using Windows.UI.Xaml.Controls;
420+
421+
#nullable enable
422+
423+
namespace MyApp;
424+
425+
public partial class MyControl : Control
426+
{
427+
[GeneratedDependencyProperty]
428+
public partial string? {|CS9248:Name1|} { get; set; }
429+
430+
[GeneratedDependencyProperty]
431+
public partial string? {|CS9248:Name2|} { get; set; }
432+
}
433+
""";
434+
435+
CSharpCodeFixTest test = new(LanguageVersion.Preview)
436+
{
437+
TestCode = original,
438+
FixedCode = @fixed
439+
};
440+
441+
await test.RunAsync();
442+
}
443+
444+
[TestMethod]
445+
public async Task MultipleProperties_WithInterspersedMembers_HandlesSpacingCorrectly()
446+
{
447+
string original = $$"""
448+
using Windows.UI.Xaml;
449+
using Windows.UI.Xaml.Controls;
450+
451+
#nullable enable
452+
453+
namespace MyApp;
454+
455+
public partial class MyControl : Control
456+
{
457+
public static readonly DependencyProperty Name1Property = DependencyProperty.Register(
458+
name: "Name1",
459+
propertyType: typeof(string),
460+
ownerType: typeof(MyControl),
461+
typeMetadata: null);
462+
463+
public static readonly DependencyProperty Name2Property = DependencyProperty.Register(
464+
name: "Name2",
465+
propertyType: typeof(string),
466+
ownerType: typeof(MyControl),
467+
typeMetadata: null);
468+
469+
/// <summary>This is another member</summary>
470+
public int Blah => 42;
471+
472+
public string? [|Name1|]
473+
{
474+
get => (string?)GetValue(Name1Property);
475+
set => SetValue(Name1Property, value);
476+
}
477+
478+
public string? [|Name2|]
479+
{
480+
get => (string?)GetValue(Name2Property);
481+
set => SetValue(Name2Property, value);
482+
}
483+
}
484+
""";
485+
486+
// There is an extra leading blank line here for now, likely a 'SyntaxEditor' bug
487+
string @fixed = $$"""
488+
using CommunityToolkit.WinUI;
489+
using Windows.UI.Xaml;
490+
using Windows.UI.Xaml.Controls;
491+
492+
#nullable enable
493+
494+
namespace MyApp;
495+
496+
public partial class MyControl : Control
497+
{
498+
499+
/// <summary>This is another member</summary>
500+
public int Blah => 42;
501+
502+
[GeneratedDependencyProperty]
503+
public partial string? {|CS9248:Name1|} { get; set; }
504+
505+
[GeneratedDependencyProperty]
506+
public partial string? {|CS9248:Name2|} { get; set; }
507+
}
508+
""";
509+
510+
CSharpCodeFixTest test = new(LanguageVersion.Preview)
511+
{
512+
TestCode = original,
513+
FixedCode = @fixed
514+
};
515+
516+
await test.RunAsync();
517+
}
376518
}

0 commit comments

Comments
 (0)