Skip to content

Commit f42f236

Browse files
committed
Fixed carousel automation tests
1 parent ba3c81f commit f42f236

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/Carousel/CarouselAutomationPeer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ protected override string GetClassNameCore()
8282
/// </returns>
8383
protected override string GetNameCore()
8484
{
85-
string name = AutomationProperties.GetName(this.OwningCarousel);
85+
string name = this.OwningCarousel.Name;
8686
if (!string.IsNullOrEmpty(name))
8787
{
8888
return name;
8989
}
9090

91-
name = this.OwningCarousel.Name;
91+
name = AutomationProperties.GetName(this.OwningCarousel);
9292
if (!string.IsNullOrEmpty(name))
9393
{
9494
return name;

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.ObjectModel;
77
using System.Diagnostics;
88
using System.Linq;
9+
using Windows.UI.Xaml.Automation;
910
using Microsoft.Toolkit.Uwp.UI.Controls;
1011
using Microsoft.VisualStudio.TestTools.UnitTesting;
1112
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
@@ -21,18 +22,23 @@ public class Test_Carousel
2122
[UITestMethod]
2223
public void ShouldConfigureCarouselAutomationPeer()
2324
{
25+
const string automationName = "MyAutomationPhotoItems";
26+
const string name = "MyPhotoItems";
27+
2428
var items = new ObservableCollection<PhotoDataItem> { new PhotoDataItem { Title = "Hello" }, new PhotoDataItem { Title = "World" } };
2529
var carousel = new Carousel { ItemsSource = items };
2630

27-
var carouselPeer = FrameworkElementAutomationPeer.CreatePeerForElement(carousel) as CarouselAutomationPeer;
31+
var carouselAutomationPeer = FrameworkElementAutomationPeer.CreatePeerForElement(carousel) as CarouselAutomationPeer;
32+
33+
Assert.IsNotNull(carouselAutomationPeer, "Verify that the AutomationPeer is CarouselAutomationPeer.");
34+
Assert.IsFalse(carouselAutomationPeer.CanSelectMultiple, "Verify that CarouselAutomationPeer.CanSelectMultiple is false.");
35+
Assert.IsTrue(carouselAutomationPeer.IsSelectionRequired, "Verify that CarouselAutomationPeer.IsSelectionRequired is false.");
2836

29-
Assert.IsNotNull(carouselPeer, "Verify that the AutomationPeer is CarouselAutomationPeer.");
30-
Assert.IsFalse(carouselPeer.CanSelectMultiple, "Verify that CarouselAutomationPeer.CanSelectMultiple is false.");
31-
Assert.IsFalse(carouselPeer.IsSelectionRequired, "Verify that CarouselAutomationPeer.IsSelectionRequired is false.");
37+
carousel.SetValue(AutomationProperties.NameProperty, automationName);
38+
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(automationName), "Verify that the UIA name contains the given AutomationProperties.Name of the Carousel.");
3239

33-
Assert.IsTrue(carouselPeer.GetName().Contains(nameof(Carousel)), "Verify that the UIA name contains the class name of the Carousel.");
34-
carousel.Name = "TextItems";
35-
Assert.IsTrue(carouselPeer.GetName().Contains(carousel.Name), "Verify that the UIA name contains the given name of the Carousel.");
40+
carousel.Name = name;
41+
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the Carousel.");
3642
}
3743

3844
public class PhotoDataItem

0 commit comments

Comments
 (0)