Skip to content

Commit a9cc874

Browse files
Add a new combined test
1 parent 376c9f8 commit a9cc874

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.Linq;
6+
using System.Threading.Tasks;
7+
using Microsoft.Toolkit.Uwp;
8+
using Microsoft.Toolkit.Uwp.UI;
9+
using Microsoft.Toolkit.Uwp.UI.Controls;
10+
using Microsoft.Toolkit.Uwp.UI.Helpers;
11+
using Microsoft.VisualStudio.TestTools.UnitTesting;
12+
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
13+
using Windows.Foundation;
14+
using Windows.UI.Xaml;
15+
using Windows.UI.Xaml.Controls;
16+
using Windows.UI.Xaml.Markup;
17+
18+
namespace UnitTests.UWP.UI.Controls
19+
{
20+
public partial class Test_ConstrainedBox : VisualUITestBase
21+
{
22+
[TestCategory("ConstrainedBox")]
23+
[TestMethod]
24+
public async Task Test_ConstrainedBox_Combined_All()
25+
{
26+
await App.DispatcherQueue.EnqueueAsync(async () =>
27+
{
28+
// We turn LayoutRounding off as we're doing between pixel calculation here to test.
29+
var treeRoot = XamlReader.Load(@"<Page
30+
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
31+
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
32+
xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">
33+
<Grid x:Name=""ParentGrid"" Width=""100"" Height=""100"">
34+
<controls:ConstrainedBox x:Name=""ConstrainedBox"" ScaleX=""0.9"" ScaleY=""0.9""
35+
MultipleX=""32"" MultipleY=""32""
36+
AspectRatio=""3:1""
37+
UseLayoutRounding=""False""
38+
HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch"">
39+
<Border HorizontalAlignment=""Stretch"" VerticalAlignment=""Stretch"" Background=""Red""/>
40+
</controls:ConstrainedBox>
41+
</Grid>
42+
</Page>") as FrameworkElement;
43+
44+
Assert.IsNotNull(treeRoot, "Could not load XAML tree.");
45+
46+
// Initialize Visual Tree
47+
await SetTestContentAsync(treeRoot);
48+
49+
var grid = treeRoot.FindChild("ParentGrid") as Grid;
50+
51+
var panel = treeRoot.FindChild("ConstrainedBox") as ConstrainedBox;
52+
53+
Assert.IsNotNull(panel, "Could not find ConstrainedBox in tree.");
54+
55+
// Force Layout calculations
56+
panel.UpdateLayout();
57+
58+
var child = panel.Content as Border;
59+
60+
Assert.IsNotNull(child, "Could not find inner Border");
61+
62+
// Check Size
63+
Assert.AreEqual(64, child.ActualWidth, 0.01, "Actual width does not meet expected value of 64");
64+
Assert.AreEqual(21.333, child.ActualHeight, 0.01, "Actual height does not meet expected value of 21.33");
65+
66+
// Check inner Positioning, we do this from the Grid as the ConstainedBox also modifies its own size
67+
// and is hugging the child.
68+
var position = grid.CoordinatesTo(child);
69+
70+
Assert.AreEqual(18, position.X, 0.01, "X position does not meet expected value of 18");
71+
Assert.AreEqual(39.333, position.Y, 0.01, "Y position does not meet expected value of 39.33");
72+
73+
// Update Aspect Ratio and Re-check
74+
panel.AspectRatio = new AspectRatio(1, 3);
75+
76+
// Wait to ensure we've redone layout
77+
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() =>
78+
{
79+
// Check Size
80+
Assert.AreEqual(21.333, child.ActualWidth, 0.01, "Actual width does not meet expected value of 21.33");
81+
Assert.AreEqual(64, child.ActualHeight, 0.01, "Actual height does not meet expected value of 64");
82+
83+
// Check inner Positioning, we do this from the Grid as the ConstainedBox also modifies its own size
84+
// and is hugging the child.
85+
position = grid.CoordinatesTo(child);
86+
87+
Assert.AreEqual(39.333, position.X, 0.01, "X position does not meet expected value of 39.33");
88+
Assert.AreEqual(18, position.Y, 0.01, "Y position does not meet expected value of 18");
89+
});
90+
});
91+
}
92+
}
93+
}

UnitTests/UnitTests.UWP/UnitTests.UWP.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
<Compile Include="UI\Controls\Test_BladeView.cs" />
222222
<Compile Include="UI\Controls\Test_ConstrainedBox.AspectRatio.cs" />
223223
<Compile Include="UI\Controls\Test_ConstrainedBox.Multiple.cs" />
224+
<Compile Include="UI\Controls\Test_ConstrainedBox.Combined.cs" />
224225
<Compile Include="UI\Controls\Test_ImageEx.cs" />
225226
<Compile Include="UI\Controls\Test_RadialGauge.cs" />
226227
<Compile Include="UI\Controls\Test_TextToolbar_Localization.cs" />

0 commit comments

Comments
 (0)