diff --git a/components/Behaviors/tests/Behaviors.Tests.projitems b/components/Behaviors/tests/Behaviors.Tests.projitems index c21c6464..82889e91 100644 --- a/components/Behaviors/tests/Behaviors.Tests.projitems +++ b/components/Behaviors/tests/Behaviors.Tests.projitems @@ -9,7 +9,6 @@ BehaviorsExperiment.Tests - ExampleBehaviorsTestPage.xaml diff --git a/components/Behaviors/tests/ExampleBehaviorsTestClass.cs b/components/Behaviors/tests/ExampleBehaviorsTestClass.cs deleted file mode 100644 index c22c3397..00000000 --- a/components/Behaviors/tests/ExampleBehaviorsTestClass.cs +++ /dev/null @@ -1,41 +0,0 @@ -// 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 CommunityToolkit.Tests; -using CommunityToolkit.Tests.Internal; -using CommunityToolkit.Tooling.TestGen; - -namespace BehaviorsExperiment.Tests; - -[TestClass] -public partial class ExampleBehaviorsTestClass : VisualUITestBase -{ - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. - // This lets us actually test a control as it would behave within an actual application. - // The page will already be loaded by the time your test is called. - [UIThreadTestMethod] - public void SimpleUIExamplePageTest(ExampleBehaviorsTestPage page) - { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: - /*var component = page.FindDescendant(); - - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("BehaviorsControl"); - - Assert.IsNotNull(componentByName);*/ - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(ExampleBehaviorsTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - - /*var component = page.FindDescendant(); - - Assert.IsNotNull(component);*/ - } -} diff --git a/components/Behaviors/tests/ExampleBehaviorsTestPage.xaml b/components/Behaviors/tests/ExampleBehaviorsTestPage.xaml deleted file mode 100644 index b577b8ec..00000000 --- a/components/Behaviors/tests/ExampleBehaviorsTestPage.xaml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/components/Behaviors/tests/ExampleBehaviorsTestPage.xaml.cs b/components/Behaviors/tests/ExampleBehaviorsTestPage.xaml.cs deleted file mode 100644 index b9bface8..00000000 --- a/components/Behaviors/tests/ExampleBehaviorsTestPage.xaml.cs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -namespace BehaviorsExperiment.Tests; - -/// -/// An empty page that can be used on its own or navigated to within a Frame. -/// -public sealed partial class ExampleBehaviorsTestPage : Page -{ - public ExampleBehaviorsTestPage() - { - this.InitializeComponent(); - } -} diff --git a/components/HeaderedControls/tests/HeaderedContentControlTestClass.cs b/components/HeaderedControls/tests/HeaderedContentControlTestClass.cs index 56329212..2f2468c4 100644 --- a/components/HeaderedControls/tests/HeaderedContentControlTestClass.cs +++ b/components/HeaderedControls/tests/HeaderedContentControlTestClass.cs @@ -10,95 +10,13 @@ namespace HeaderedControls.Tests; [TestClass] public partial class HeaderedContentControlTestClass : VisualUITestBase { - // If you don't need access to UI objects directly or async code, use this pattern. - [TestMethod] - public void SimpleSynchronousExampleTest() - { - var assembly = typeof(HeaderedContentControl).Assembly; - var type = assembly.GetType(typeof(HeaderedContentControl).FullName ?? string.Empty); - - Assert.IsNotNull(type, "Could not find HeaderedContentControl type."); - Assert.AreEqual(typeof(HeaderedContentControl), type, "Type of HeaderedContentControl does not match expected type."); - } - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. // This lets us actually test a control as it would behave within an actual application. // The page will already be loaded by the time your test is called. [UIThreadTestMethod] public void SimpleUIExamplePageTest(HeaderedContentControlTestPage page) { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: - var component = page.FindDescendant(); - - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("HeaderedContentControl"); - - Assert.IsNotNull(componentByName); - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(HeaderedContentControlTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - var component = page.FindDescendant(); - Assert.IsNotNull(component); } - - //// ----------------------------- ADVANCED TEST SCENARIOS ----------------------------- - - // If you need to use DataRow, you can use this pattern with the UI dispatch still. - // Otherwise, checkout the UIThreadTestMethod attribute above. - // See https://github.com/CommunityToolkit/Labs-Windows/issues/186 - [TestMethod] - public async Task ComplexAsyncUIExampleTest() - { - await EnqueueAsync(() => - { - var component = new HeaderedContentControl(); - Assert.IsNotNull(component); - }); - } - - // If you want to load other content not within a XAML page using the UIThreadTestMethod above. - // Then you can do that using the Load/UnloadTestContentAsync methods. - [TestMethod] - public async Task ComplexAsyncLoadUIExampleTest() - { - await EnqueueAsync(async () => - { - var component = new HeaderedContentControl(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - }); - } - - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [UIThreadTestMethod] - public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() - { - var component = new HeaderedContentControl(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - } } diff --git a/components/HeaderedControls/tests/HeaderedItemsControlTestClass.cs b/components/HeaderedControls/tests/HeaderedItemsControlTestClass.cs index d7213490..2d101db9 100644 --- a/components/HeaderedControls/tests/HeaderedItemsControlTestClass.cs +++ b/components/HeaderedControls/tests/HeaderedItemsControlTestClass.cs @@ -10,103 +10,10 @@ namespace HeaderedControls.Tests; [TestClass] public partial class HeaderedItemsControlTestClass : VisualUITestBase { - // If you don't need access to UI objects directly or async code, use this pattern. - [TestMethod] - public void SimpleSynchronousExampleTest() - { - var assembly = typeof(HeaderedItemsControl).Assembly; - var type = assembly.GetType(typeof(HeaderedItemsControl).FullName ?? string.Empty); - - Assert.IsNotNull(type, "Could not find HeaderedItemsControl type."); - Assert.AreEqual(typeof(HeaderedItemsControl), type, "Type of HeaderedItemsControl does not match expected type."); - } - - // The UIThreadTestMethod automatically dispatches to the UI for us to work with UI objects. - [UIThreadTestMethod] - public void SimpleUIAttributeExampleTest() - { - var component = new HeaderedItemsControl(); - Assert.IsNotNull(component); - } - - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. - // This lets us actually test a control as it would behave within an actual application. - // The page will already be loaded by the time your test is called. [UIThreadTestMethod] public void SimpleUIExamplePageTest(HeaderedItemsControlTestPage page) { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: - var component = page.FindDescendant(); - - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("HeaderedItemsControl"); - - Assert.IsNotNull(componentByName); - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(HeaderedItemsControlTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - var component = page.FindDescendant(); - Assert.IsNotNull(component); } - - //// ----------------------------- ADVANCED TEST SCENARIOS ----------------------------- - - // If you need to use DataRow, you can use this pattern with the UI dispatch still. - // Otherwise, checkout the UIThreadTestMethod attribute above. - // See https://github.com/CommunityToolkit/Labs-Windows/issues/186 - [TestMethod] - public async Task ComplexAsyncUIExampleTest() - { - await EnqueueAsync(() => - { - var component = new HeaderedItemsControl(); - Assert.IsNotNull(component); - }); - } - - // If you want to load other content not within a XAML page using the UIThreadTestMethod above. - // Then you can do that using the Load/UnloadTestContentAsync methods. - [TestMethod] - public async Task ComplexAsyncLoadUIExampleTest() - { - await EnqueueAsync(async () => - { - var component = new HeaderedItemsControl(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - }); - } - - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [UIThreadTestMethod] - public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() - { - var component = new HeaderedItemsControl(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - } } diff --git a/components/HeaderedControls/tests/HeaderedTreeViewTestClass.cs b/components/HeaderedControls/tests/HeaderedTreeViewTestClass.cs index 61caf983..2fb2b2ba 100644 --- a/components/HeaderedControls/tests/HeaderedTreeViewTestClass.cs +++ b/components/HeaderedControls/tests/HeaderedTreeViewTestClass.cs @@ -10,103 +10,10 @@ namespace HeaderedControls.Tests; [TestClass] public partial class HeaderedTreeViewTestClass : VisualUITestBase { - // If you don't need access to UI objects directly or async code, use this pattern. - [TestMethod] - public void SimpleSynchronousExampleTest() - { - var assembly = typeof(HeaderedTreeView).Assembly; - var type = assembly.GetType(typeof(HeaderedTreeView).FullName ?? string.Empty); - - Assert.IsNotNull(type, "Could not find HeaderedTreeView type."); - Assert.AreEqual(typeof(HeaderedTreeView), type, "Type of HeaderedTreeView does not match expected type."); - } - - // The UIThreadTestMethod automatically dispatches to the UI for us to work with UI objects. - [UIThreadTestMethod] - public void SimpleUIAttributeExampleTest() - { - var component = new HeaderedTreeView(); - Assert.IsNotNull(component); - } - - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. - // This lets us actually test a control as it would behave within an actual application. - // The page will already be loaded by the time your test is called. [UIThreadTestMethod] public void SimpleUIExamplePageTest(HeaderedTreeViewTestPage page) { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: - var component = page.FindDescendant(); - - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("HeaderedTreeView"); - - Assert.IsNotNull(componentByName); - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(HeaderedTreeViewTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - var component = page.FindDescendant(); - Assert.IsNotNull(component); } - - //// ----------------------------- ADVANCED TEST SCENARIOS ----------------------------- - - // If you need to use DataRow, you can use this pattern with the UI dispatch still. - // Otherwise, checkout the UIThreadTestMethod attribute above. - // See https://github.com/CommunityToolkit/Labs-Windows/issues/186 - [TestMethod] - public async Task ComplexAsyncUIExampleTest() - { - await EnqueueAsync(() => - { - var component = new HeaderedTreeView(); - Assert.IsNotNull(component); - }); - } - - // If you want to load other content not within a XAML page using the UIThreadTestMethod above. - // Then you can do that using the Load/UnloadTestContentAsync methods. - [TestMethod] - public async Task ComplexAsyncLoadUIExampleTest() - { - await EnqueueAsync(async () => - { - var component = new HeaderedTreeView(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - }); - } - - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [UIThreadTestMethod] - public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() - { - var component = new HeaderedTreeView(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - } } diff --git a/components/Segmented/tests/ExampleSegmentedTestClass.cs b/components/Segmented/tests/ExampleSegmentedTestClass.cs index c2e040b9..a6703b98 100644 --- a/components/Segmented/tests/ExampleSegmentedTestClass.cs +++ b/components/Segmented/tests/ExampleSegmentedTestClass.cs @@ -11,123 +11,10 @@ namespace SegmentedExperiment.Tests; [TestClass] public partial class ExampleSegmentedTestClass : VisualUITestBase { - // If you don't need access to UI objects directly or async code, use this pattern. - [TestMethod] - public void SimpleSynchronousExampleTest() - { - var assembly = typeof(Segmented).Assembly; - var type = assembly.GetType(typeof(Segmented).FullName ?? string.Empty); - - Assert.IsNotNull(type, "Could not find Segmented control type."); - Assert.AreEqual(typeof(Segmented), type, "Type of Segmented control does not match expected type."); - } - - // If you don't need access to UI objects directly, use this pattern. - [TestMethod] - public async Task SimpleAsyncExampleTest() - { - await Task.Delay(250); - - Assert.IsTrue(true); - } - - // Example that shows how to check for exception throwing. - [TestMethod] - public void SimpleExceptionCheckTest() - { - // If you need to check exceptions occur for invalid inputs, etc... - // Use Assert.ThrowsException to limit the scope to where you expect the error to occur. - // Otherwise, using the ExpectedException attribute could swallow or - // catch other issues in setup code. - Assert.ThrowsException(() => throw new NotImplementedException()); - } - - // The UIThreadTestMethod automatically dispatches to the UI for us to work with UI objects. - [UIThreadTestMethod] - public void SimpleUIAttributeExampleTest() - { - var component = new Segmented(); - Assert.IsNotNull(component); - } - - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. - // This lets us actually test a control as it would behave within an actual application. - // The page will already be loaded by the time your test is called. [UIThreadTestMethod] public void SimpleUIExamplePageTest(ExampleSegmentedTestPage page) { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: var component = page.FindDescendant(); - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("SegmentedControl"); - - Assert.IsNotNull(componentByName); - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(ExampleSegmentedTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - - var component = page.FindDescendant(); - - Assert.IsNotNull(component); - } - - //// ----------------------------- ADVANCED TEST SCENARIOS ----------------------------- - - // If you need to use DataRow, you can use this pattern with the UI dispatch still. - // Otherwise, checkout the UIThreadTestMethod attribute above. - // See https://github.com/CommunityToolkit/Labs-Windows/issues/186 - [TestMethod] - public async Task ComplexAsyncUIExampleTest() - { - await EnqueueAsync(() => - { - var component = new Segmented(); - Assert.IsNotNull(component); - }); - } - - // If you want to load other content not within a XAML page using the UIThreadTestMethod above. - // Then you can do that using the Load/UnloadTestContentAsync methods. - [TestMethod] - public async Task ComplexAsyncLoadUIExampleTest() - { - await EnqueueAsync(async () => - { - var component = new Segmented(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - }); - } - - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [UIThreadTestMethod] - public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() - { - var component = new Segmented(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); } } diff --git a/components/SettingsControls/tests/Test_SettingsCard.cs b/components/SettingsControls/tests/Test_SettingsCard.cs index 3ba535b6..6ca65096 100644 --- a/components/SettingsControls/tests/Test_SettingsCard.cs +++ b/components/SettingsControls/tests/Test_SettingsCard.cs @@ -25,124 +25,10 @@ public void EmptyDescriptionTest(SettingsCard card) card.Description = string.Empty; } - // If you don't need access to UI objects directly or async code, use this pattern. - [TestMethod] - public void SimpleSynchronousExampleTest() - { - var assembly = typeof(SettingsCard).Assembly; - var type = assembly.GetType(typeof(SettingsCard).FullName ?? string.Empty); - - Assert.IsNotNull(type, "Could not find SettingsControls type."); - Assert.AreEqual(typeof(SettingsCard), type, "Type of SettingsCard does not match expected type."); - } - - // If you don't need access to UI objects directly, use this pattern. - [TestMethod] - public async Task SimpleAsyncExampleTest() - { - await Task.Delay(250); - - Assert.IsTrue(true); - } - - // Example that shows how to check for exception throwing. - [TestMethod] - public void SimpleExceptionCheckTest() - { - // If you need to check exceptions occur for invalid inputs, etc... - // Use Assert.ThrowsException to limit the scope to where you expect the error to occur. - // Otherwise, using the ExpectedException attribute could swallow or - // catch other issues in setup code. - Assert.ThrowsException(() => throw new NotImplementedException()); - } - - // The UIThreadTestMethod automatically dispatches to the UI for us to work with UI objects. - [UIThreadTestMethod] - public void SimpleUIAttributeExampleTest() - { - var component = new SettingsCard(); - Assert.IsNotNull(component); - } - - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. - // This lets us actually test a control as it would behave within an actual application. - // The page will already be loaded by the time your test is called. [UIThreadTestMethod] public void SimpleUIExamplePageTest(SettingsCardTestPage page) { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: var component = page.FindDescendant(); - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("settingsCard"); - - Assert.IsNotNull(componentByName); - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(SettingsCardTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - // Note, this is already done by loading a Page with the [UIThreadTestMethod] helper. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - - var component = page.FindDescendant(); - - Assert.IsNotNull(component); - } - - //// ----------------------------- ADVANCED TEST SCENARIOS ----------------------------- - - // If you need to use DataRow, you can use this pattern with the UI dispatch still. - // Otherwise, checkout the UIThreadTestMethod attribute above. - // See https://github.com/CommunityToolkit/Labs-Windows/issues/186 - [TestMethod] - public async Task ComplexAsyncUIExampleTest() - { - await EnqueueAsync(() => - { - var component = new SettingsCard(); - Assert.IsNotNull(component); - }); - } - - // If you want to load other content not within a XAML page using the UIThreadTestMethod above. - // Then you can do that using the Load/UnloadTestContentAsync methods. - [TestMethod] - public async Task ComplexAsyncLoadUIExampleTest() - { - await EnqueueAsync(async () => - { - var component = new SettingsCard(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - }); - } - - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [UIThreadTestMethod] - public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() - { - var component = new SettingsCard(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); } } diff --git a/components/SettingsControls/tests/Test_SettingsExpander.cs b/components/SettingsControls/tests/Test_SettingsExpander.cs index 6347fcd4..0cc81678 100644 --- a/components/SettingsControls/tests/Test_SettingsExpander.cs +++ b/components/SettingsControls/tests/Test_SettingsExpander.cs @@ -11,124 +11,10 @@ namespace SettingsControlsExperiment.Tests; [TestClass] public partial class SettingsExpanderTestClass : VisualUITestBase { - // If you don't need access to UI objects directly or async code, use this pattern. - [TestMethod] - public void SimpleSynchronousExampleTest() - { - var assembly = typeof(SettingsExpander).Assembly; - var type = assembly.GetType(typeof(SettingsExpander).FullName ?? string.Empty); - - Assert.IsNotNull(type, "Could not find SettingsControls type."); - Assert.AreEqual(typeof(SettingsExpander), type, "Type of SettingsExpander does not match expected type."); - } - - // If you don't need access to UI objects directly, use this pattern. - [TestMethod] - public async Task SimpleAsyncExampleTest() - { - await Task.Delay(250); - - Assert.IsTrue(true); - } - - // Example that shows how to check for exception throwing. - [TestMethod] - public void SimpleExceptionCheckTest() - { - // If you need to check exceptions occur for invalid inputs, etc... - // Use Assert.ThrowsException to limit the scope to where you expect the error to occur. - // Otherwise, using the ExpectedException attribute could swallow or - // catch other issues in setup code. - Assert.ThrowsException(() => throw new NotImplementedException()); - } - - // The UIThreadTestMethod automatically dispatches to the UI for us to work with UI objects. - [UIThreadTestMethod] - public void SimpleUIAttributeExampleTest() - { - var component = new SettingsExpander(); - Assert.IsNotNull(component); - } - - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. - // This lets us actually test a control as it would behave within an actual application. - // The page will already be loaded by the time your test is called. [UIThreadTestMethod] public void SimpleUIExamplePageTest(SettingsExpanderTestPage page) { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: var component = page.FindDescendant(); - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("settingsExpander"); - - Assert.IsNotNull(componentByName); - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(SettingsExpanderTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - // Note, this is already done by loading a Page with the [UIThreadTestMethod] helper. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - - var component = page.FindDescendant(); - - Assert.IsNotNull(component); - } - - //// ----------------------------- ADVANCED TEST SCENARIOS ----------------------------- - - // If you need to use DataRow, you can use this pattern with the UI dispatch still. - // Otherwise, checkout the UIThreadTestMethod attribute above. - // See https://github.com/CommunityToolkit/Labs-Windows/issues/186 - [TestMethod] - public async Task ComplexAsyncUIExampleTest() - { - await EnqueueAsync(() => - { - var component = new SettingsExpander(); - Assert.IsNotNull(component); - }); - } - - // If you want to load other content not within a XAML page using the UIThreadTestMethod above. - // Then you can do that using the Load/UnloadTestContentAsync methods. - [TestMethod] - public async Task ComplexAsyncLoadUIExampleTest() - { - await EnqueueAsync(async () => - { - var component = new SettingsExpander(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - }); - } - - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [UIThreadTestMethod] - public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() - { - var component = new SettingsExpander(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); } } diff --git a/components/TabbedCommandBar/tests/ExampleTabbedCommandBarTestClass.cs b/components/TabbedCommandBar/tests/ExampleTabbedCommandBarTestClass.cs index 934f9eec..1a25700c 100644 --- a/components/TabbedCommandBar/tests/ExampleTabbedCommandBarTestClass.cs +++ b/components/TabbedCommandBar/tests/ExampleTabbedCommandBarTestClass.cs @@ -11,124 +11,10 @@ namespace TabbedCommandBarExperiment.Tests; [TestClass] public partial class ExampleTabbedCommandBarTestClass : VisualUITestBase { - // If you don't need access to UI objects directly or async code, use this pattern. - [TestMethod] - public void SimpleSynchronousExampleTest() - { - var assembly = typeof(TabbedCommandBar).Assembly; - var type = assembly.GetType(typeof(TabbedCommandBar).FullName ?? string.Empty); - - Assert.IsNotNull(type, "Could not find TabbedCommandBar type."); - Assert.AreEqual(typeof(TabbedCommandBar), type, "Type of TabbedCommandBar does not match expected type."); - } - - // If you don't need access to UI objects directly, use this pattern. - [TestMethod] - public async Task SimpleAsyncExampleTest() - { - await Task.Delay(250); - - Assert.IsTrue(true); - } - - // Example that shows how to check for exception throwing. - [TestMethod] - public void SimpleExceptionCheckTest() - { - // If you need to check exceptions occur for invalid inputs, etc... - // Use Assert.ThrowsException to limit the scope to where you expect the error to occur. - // Otherwise, using the ExpectedException attribute could swallow or - // catch other issues in setup code. - Assert.ThrowsException(() => throw new NotImplementedException()); - } - - // The UIThreadTestMethod automatically dispatches to the UI for us to work with UI objects. - [UIThreadTestMethod] - public void SimpleUIAttributeExampleTest() - { - var component = new TabbedCommandBar(); - Assert.IsNotNull(component); - } - - // The UIThreadTestMethod can also easily grab a XAML Page for us by passing its type as a parameter. - // This lets us actually test a control as it would behave within an actual application. - // The page will already be loaded by the time your test is called. [UIThreadTestMethod] public void SimpleUIExamplePageTest(ExampleTabbedCommandBarTestPage page) { - // You can use the Toolkit Visual Tree helpers here to find the component by type or name: var component = page.FindDescendant(); - Assert.IsNotNull(component); - - var componentByName = page.FindDescendant("TabbedCommandBarControl"); - - Assert.IsNotNull(componentByName); - } - - // You can still do async work with a UIThreadTestMethod as well. - [UIThreadTestMethod] - public async Task SimpleAsyncUIExamplePageTest(ExampleTabbedCommandBarTestPage page) - { - // This helper can be used to wait for a rendering pass to complete. - // Note, this is already done by loading a Page with the [UIThreadTestMethod] helper. - await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { }); - - var component = page.FindDescendant(); - - Assert.IsNotNull(component); - } - - //// ----------------------------- ADVANCED TEST SCENARIOS ----------------------------- - - // If you need to use DataRow, you can use this pattern with the UI dispatch still. - // Otherwise, checkout the UIThreadTestMethod attribute above. - // See https://github.com/CommunityToolkit/Labs-Windows/issues/186 - [TestMethod] - public async Task ComplexAsyncUIExampleTest() - { - await EnqueueAsync(() => - { - var component = new TabbedCommandBar(); - Assert.IsNotNull(component); - }); - } - - // If you want to load other content not within a XAML page using the UIThreadTestMethod above. - // Then you can do that using the Load/UnloadTestContentAsync methods. - [TestMethod] - public async Task ComplexAsyncLoadUIExampleTest() - { - await EnqueueAsync(async () => - { - var component = new TabbedCommandBar(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); - }); - } - - // You can still use the UIThreadTestMethod to remove the extra layer for the dispatcher as well: - [UIThreadTestMethod] - public async Task ComplexAsyncLoadUIExampleWithoutDispatcherTest() - { - var component = new TabbedCommandBar(); - Assert.IsNotNull(component); - Assert.IsFalse(component.IsLoaded); - - await LoadTestContentAsync(component); - - Assert.IsTrue(component.IsLoaded); - - await UnloadTestContentAsync(component); - - Assert.IsFalse(component.IsLoaded); } }