Skip to content

Commit ddea9ce

Browse files
committed
Updated carousel test to not use parsed XAML string
1 parent 4dbba32 commit ddea9ce

File tree

1 file changed

+23
-39
lines changed

1 file changed

+23
-39
lines changed

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

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Collections.ObjectModel;
56
using System.Linq;
67
using System.Threading.Tasks;
78
using Windows.UI.Xaml.Automation;
@@ -24,45 +25,14 @@ public async Task ShouldConfigureCarouselAutomationPeerAsync()
2425
{
2526
await App.DispatcherQueue.EnqueueAsync(async () =>
2627
{
27-
var treeRoot = XamlReader.Load(@"<Page
28-
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
29-
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
30-
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls""
31-
xmlns:data=""using:UnitTests.UWP.UI.Controls"">
32-
<Grid>
33-
<controls:Carousel InvertPositive=""True"">
34-
<controls:Carousel.EasingFunction>
35-
<CubicEase EasingMode=""EaseOut"" />
36-
</controls:Carousel.EasingFunction>
28+
const int selectedIndex = 1;
29+
var items = new ObservableCollection<PhotoDataItem> { new PhotoDataItem { Title = "Hello" }, new PhotoDataItem { Title = "World" } };
30+
var carousel = new Carousel { ItemsSource = items };
3731

38-
<controls:CarouselItem>
39-
Hello
40-
</controls:CarouselItem>
41-
<controls:CarouselItem>
42-
World
43-
</controls:CarouselItem>
44-
</controls:Carousel>
45-
</Grid>
46-
</Page>") as Page;
47-
48-
// This is based on the XAML above.
49-
var expectedNumItems = 2;
50-
var expectedSelectedItem = "World";
51-
52-
Assert.IsNotNull(treeRoot, "XAML for test failed to load");
53-
54-
await SetTestContentAsync(treeRoot);
55-
56-
var outerGrid = treeRoot.Content as Grid;
57-
58-
Assert.IsNotNull(outerGrid, "Couldn't find Page content.");
59-
60-
var carousel = outerGrid.Children.FirstOrDefault() as Carousel;
61-
62-
Assert.IsNotNull(carousel, "Couldn't find Target Carousel.");
32+
await SetTestContentAsync(carousel);
6333

6434
// Sets the selected item to "World" from the XAML above.
65-
carousel.SelectedIndex = 1;
35+
carousel.SelectedIndex = selectedIndex;
6636

6737
const string automationName = "MyAutomationPhotoItems";
6838
const string name = "MyPhotoItems";
@@ -81,19 +51,33 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
8151
Assert.IsTrue(carouselAutomationPeer.GetName().Contains(name), "Verify that the UIA name contains the given Name of the Carousel.");
8252

8353
var carouselItemAutomationPeers = carouselAutomationPeer.GetChildren().Cast<CarouselItemAutomationPeer>().ToList();
84-
Assert.AreEqual(expectedNumItems, carouselItemAutomationPeers.Count);
54+
Assert.AreEqual(items.Count, carouselItemAutomationPeers.Count);
8555

8656
for (var i = 0; i < carouselItemAutomationPeers.Count; i++)
8757
{
8858
var peer = carouselItemAutomationPeers[i];
8959
Assert.AreEqual(i + 1, peer.GetPositionInSet());
90-
Assert.AreEqual(expectedNumItems, peer.GetSizeOfSet());
60+
Assert.AreEqual(items.Count, peer.GetSizeOfSet());
9161
}
9262

9363
var selected = carouselItemAutomationPeers.FirstOrDefault(peer => peer.IsSelected);
9464
Assert.IsNotNull(selected);
95-
Assert.IsTrue(selected.GetName().Contains(expectedSelectedItem));
65+
Assert.IsTrue(selected.GetName().Contains(items[selectedIndex].ToString()));
9666
});
9767
}
68+
69+
public class PhotoDataItem
70+
{
71+
public string Title { get; set; }
72+
73+
public string Category { get; set; }
74+
75+
public string Thumbnail { get; set; }
76+
77+
public override string ToString()
78+
{
79+
return Title;
80+
}
81+
}
9882
}
9983
}

0 commit comments

Comments
 (0)