Skip to content

Commit b6da782

Browse files
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>
1 parent 55b3ecf commit b6da782

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

components/ColorPicker/tests/ExampleColorPickerTestClass.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using CommunityToolkit.Tooling.TestGen;
66
using CommunityToolkit.Tests;
77
using CommunityToolkit.WinUI.Controls;
8+
using CommunityToolkit.WinUI.Helpers;
89
using ColorPicker = CommunityToolkit.WinUI.Controls.ColorPicker;
910

1011
namespace ColorPickerTests;
@@ -97,23 +98,22 @@ await EnqueueAsync(() =>
9798

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

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

111-
Assert.IsTrue(component.IsLoaded);
111+
Assert.IsTrue(component.IsLoaded);
112112

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

115-
Assert.IsFalse(component.IsLoaded);
116-
});
116+
Assert.IsFalse(component.IsLoaded);
117117
}
118118

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

0 commit comments

Comments
 (0)