Skip to content

Commit 411e39d

Browse files
committed
Added test for Carousel automation peer.
1 parent 662e501 commit 411e39d

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,18 @@ protected override string GetClassNameCore()
8282
/// </returns>
8383
protected override string GetNameCore()
8484
{
85-
string name = base.GetNameCore();
86-
if (!string.IsNullOrEmpty(name))
87-
{
88-
return name;
89-
}
85+
string name = string.Empty;
9086

9187
if (this.OwningCarousel != null)
9288
{
9389
name = this.OwningCarousel.Name;
9490
}
9591

92+
if (string.IsNullOrEmpty(name))
93+
{
94+
name = base.GetNameCore();
95+
}
96+
9697
if (string.IsNullOrEmpty(name))
9798
{
9899
name = this.GetClassName();
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System.Collections.Generic;
6+
using System.Collections.ObjectModel;
7+
using System.Diagnostics;
8+
using System.Linq;
9+
using Microsoft.Toolkit.Uwp.UI.Controls;
10+
using Microsoft.VisualStudio.TestTools.UnitTesting;
11+
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
12+
using Windows.UI.Xaml.Automation.Peers;
13+
using Microsoft.Toolkit.Uwp.UI.Automation.Peers;
14+
15+
namespace UnitTests.UWP.UI.Controls
16+
{
17+
[TestClass]
18+
[TestCategory("Test_Carousel")]
19+
public class Test_Carousel
20+
{
21+
[UITestMethod]
22+
public void ShouldConfigureCarouselAutomationPeer()
23+
{
24+
var items = new ObservableCollection<PhotoDataItem> { new PhotoDataItem { Title = "Hello" }, new PhotoDataItem { Title = "World" } };
25+
var carousel = new Carousel { ItemsSource = items };
26+
27+
var carouselPeer = FrameworkElementAutomationPeer.CreatePeerForElement(carousel) as CarouselAutomationPeer;
28+
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.");
32+
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.");
36+
}
37+
38+
public class PhotoDataItem
39+
{
40+
public string Title { get; set; }
41+
42+
public string Category { get; set; }
43+
44+
public string Thumbnail { get; set; }
45+
46+
public override string ToString()
47+
{
48+
return Title;
49+
}
50+
}
51+
}
52+
}

UnitTests/UnitTests.UWP/UnitTests.UWP.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<Compile Include="PrivateType.cs" />
180180
<Compile Include="Properties\AssemblyInfo.cs" />
181181
<Compile Include="Helpers\Test_WeakEventListener.cs" />
182+
<Compile Include="UI\Controls\Test_Carousel.cs" />
182183
<Compile Include="UI\Controls\Test_RadialGauge.cs" />
183184
<Compile Include="UI\Controls\Test_TextToolbar_Localization.cs" />
184185
<Compile Include="UI\Controls\Test_InfiniteCanvas_Regression.cs" />

0 commit comments

Comments
 (0)