Skip to content

Commit d30f407

Browse files
Convert tests to UIThreadTestMethod pattern (#764)
* Convert ShouldConfigureGridSplitterAutomationPeer test to UIThreadTestMethod - Changed [TestMethod] to [UIThreadTestMethod] - Removed EnqueueAsync wrapper - Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after gridSplitter.Name assignment - Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after gridSplitter.SetValue call - Added using CommunityToolkit.WinUI.Helpers for CompositionTargetHelper Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com> * Remove using * Convert ComplexAsyncLoadUIExampleTest to UIThreadTestMethod - Changed [TestMethod] to [UIThreadTestMethod] - Removed EnqueueAsync wrapper - Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after LoadTestContentAsync - Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after UnloadTestContentAsync - Added using CommunityToolkit.WinUI.Helpers for CompositionTargetHelper Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com> * Remove unnecessary using statement from ColorPicker test The using CommunityToolkit.WinUI.Helpers is not needed as CompositionTargetHelper is already available through the test base class. Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
1 parent ff39924 commit d30f407

File tree

2 files changed

+22
-24
lines changed

2 files changed

+22
-24
lines changed

components/ColorPicker/tests/ExampleColorPickerTestClass.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,22 @@ await EnqueueAsync(() =>
9797

9898
// If you want to load other content not within a XAML page using the UIThreadTestMethod above.
9999
// Then you can do that using the Load/UnloadTestContentAsync methods.
100-
[TestMethod]
100+
[UIThreadTestMethod]
101101
public async Task ComplexAsyncLoadUIExampleTest()
102102
{
103-
await EnqueueAsync(async () =>
104-
{
105-
var component = new ColorPicker();
106-
Assert.IsNotNull(component);
107-
Assert.IsFalse(component.IsLoaded);
103+
var component = new ColorPicker();
104+
Assert.IsNotNull(component);
105+
Assert.IsFalse(component.IsLoaded);
108106

109-
await LoadTestContentAsync(component);
107+
await LoadTestContentAsync(component);
108+
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
110109

111-
Assert.IsTrue(component.IsLoaded);
110+
Assert.IsTrue(component.IsLoaded);
112111

113-
await UnloadTestContentAsync(component);
112+
await UnloadTestContentAsync(component);
113+
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
114114

115-
Assert.IsFalse(component.IsLoaded);
116-
});
115+
Assert.IsFalse(component.IsLoaded);
117116
}
118117

119118
// You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well:

components/Sizers/tests/ExampleSizerBaseTestClass.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,24 @@ namespace SizersTests;
1212
[TestClass]
1313
public partial class ExampleSizerBaseTestClass : VisualUITestBase
1414
{
15-
[TestMethod]
15+
[UIThreadTestMethod]
1616
public async Task ShouldConfigureGridSplitterAutomationPeer()
1717
{
18-
await EnqueueAsync(() =>
19-
{
20-
const string automationName = "MyCustomAutomationName";
21-
const string name = "Sizer";
18+
const string automationName = "MyCustomAutomationName";
19+
const string name = "Sizer";
2220

23-
var gridSplitter = new GridSplitter();
24-
var gridSplitterAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(gridSplitter) as SizerAutomationPeer;
21+
var gridSplitter = new GridSplitter();
22+
var gridSplitterAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(gridSplitter) as SizerAutomationPeer;
2523

26-
Assert.IsNotNull(gridSplitterAutomationPeer, "Verify that the AutomationPeer is SizerAutomationPeer.");
24+
Assert.IsNotNull(gridSplitterAutomationPeer, "Verify that the AutomationPeer is SizerAutomationPeer.");
2725

28-
gridSplitter.Name = name;
29-
Assert.IsTrue(gridSplitterAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the GridSplitter (Sizer).");
26+
gridSplitter.Name = name;
27+
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
28+
Assert.IsTrue(gridSplitterAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the GridSplitter (Sizer).");
3029

31-
gridSplitter.SetValue(AutomationProperties.NameProperty, automationName);
32-
Assert.IsTrue(gridSplitterAutomationPeer.GetName().Contains(automationName), "Verify that the UIA name contains the customized AutomationProperties.Name of the GridSplitter.");
33-
});
30+
gridSplitter.SetValue(AutomationProperties.NameProperty, automationName);
31+
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
32+
Assert.IsTrue(gridSplitterAutomationPeer.GetName().Contains(automationName), "Verify that the UIA name contains the customized AutomationProperties.Name of the GridSplitter.");
3433
}
3534

3635
[UIThreadTestMethod]

0 commit comments

Comments
 (0)