Skip to content

Commit 79ea866

Browse files
committed
Added change to rd.xml and cleaned up carousel test
1 parent ddea9ce commit 79ea866

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

UnitTests/UnitTests.UWP/Properties/UnitTestApp.rd.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@
3737
<Type Name="Microsoft.Toolkit.Uwp.UI.Extensions.SymbolIconSourceExtension" Dynamic="Required All" Serialize="Required All"/>
3838
<Type Name="Microsoft.Toolkit.Uwp.UI.Extensions.EnumValuesExtension" Dynamic="Required All" Serialize="Required All"/>
3939

40+
<Type Name="System.Collections.Generic.IList{Windows.UI.Xaml.Automation.Peers.AutomationPeer}" MarshalObject="Required All"/>
41+
4042
</Application>
4143
</Directives>

UnitTests/UnitTests.UWP/UI/Controls/Test_Carousel.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
using Windows.UI.Xaml.Automation;
99
using Microsoft.VisualStudio.TestTools.UnitTesting;
1010
using Windows.UI.Xaml.Automation.Peers;
11-
using Windows.UI.Xaml.Controls;
12-
using Windows.UI.Xaml.Markup;
1311
using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
1412
using Microsoft.Toolkit.Uwp.Extensions;
15-
using Carousel = Microsoft.Toolkit.Uwp.UI.Controls.Carousel;
13+
using Microsoft.Toolkit.Uwp.UI.Controls;
1614

1715
namespace UnitTests.UWP.UI.Controls
1816
{
@@ -25,44 +23,49 @@ public async Task ShouldConfigureCarouselAutomationPeerAsync()
2523
{
2624
await App.DispatcherQueue.EnqueueAsync(async () =>
2725
{
28-
const int selectedIndex = 1;
26+
const int expectedSelectedIndex = 1;
27+
const string expectedCarouselAutomationName = "MyAutomationPhotoItems";
28+
const string expectedCarouselName = "MyPhotoItems";
29+
2930
var items = new ObservableCollection<PhotoDataItem> { new PhotoDataItem { Title = "Hello" }, new PhotoDataItem { Title = "World" } };
31+
3032
var carousel = new Carousel { ItemsSource = items };
3133

3234
await SetTestContentAsync(carousel);
3335

34-
// Sets the selected item to "World" from the XAML above.
35-
carousel.SelectedIndex = selectedIndex;
36-
37-
const string automationName = "MyAutomationPhotoItems";
38-
const string name = "MyPhotoItems";
39-
36+
// Sets the selected item to "World" from the items above.
37+
carousel.SelectedIndex = expectedSelectedIndex;
38+
4039
var carouselAutomationPeer =
4140
FrameworkElementAutomationPeer.CreatePeerForElement(carousel) as CarouselAutomationPeer;
4241

4342
Assert.IsNotNull(carouselAutomationPeer, "Verify that the AutomationPeer is CarouselAutomationPeer.");
4443
Assert.IsFalse(carouselAutomationPeer.CanSelectMultiple, "Verify that CarouselAutomationPeer.CanSelectMultiple is false.");
4544
Assert.IsTrue(carouselAutomationPeer.IsSelectionRequired, "Verify that CarouselAutomationPeer.IsSelectionRequired is true.");
4645

47-
carousel.SetValue(AutomationProperties.NameProperty, automationName);
48-
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(automationName), "Verify that the UIA name contains the given AutomationProperties.Name of the Carousel.");
46+
// Asserts the automation peer name based on the Automation Property Name value.
47+
carousel.SetValue(AutomationProperties.NameProperty, expectedCarouselAutomationName);
48+
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(expectedCarouselAutomationName), "Verify that the UIA name contains the given AutomationProperties.Name of the Carousel.");
4949

50-
carousel.Name = name;
51-
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the Carousel.");
50+
// Asserts the automation peer name based on the element Name property.
51+
carousel.Name = expectedCarouselName;
52+
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(expectedCarouselName), "Verify that the UIA name contains the given Name of the Carousel.");
5253

5354
var carouselItemAutomationPeers = carouselAutomationPeer.GetChildren().Cast<CarouselItemAutomationPeer>().ToList();
5455
Assert.AreEqual(items.Count, carouselItemAutomationPeers.Count);
5556

57+
// Asserts the default calculated position in set and size of set values
5658
for (var i = 0; i < carouselItemAutomationPeers.Count; i++)
5759
{
5860
var peer = carouselItemAutomationPeers[i];
5961
Assert.AreEqual(i + 1, peer.GetPositionInSet());
6062
Assert.AreEqual(items.Count, peer.GetSizeOfSet());
6163
}
6264

63-
var selected = carouselItemAutomationPeers.FirstOrDefault(peer => peer.IsSelected);
64-
Assert.IsNotNull(selected);
65-
Assert.IsTrue(selected.GetName().Contains(items[selectedIndex].ToString()));
65+
// Asserts the CarouselItemAutomationPeer properties
66+
var selectedItemPeer = carouselItemAutomationPeers.FirstOrDefault(peer => peer.IsSelected);
67+
Assert.IsNotNull(selectedItemPeer);
68+
Assert.IsTrue(selectedItemPeer.GetName().Contains(items[expectedSelectedIndex].ToString()));
6669
});
6770
}
6871

0 commit comments

Comments
 (0)