Skip to content

Commit b838835

Browse files
michael-hawkerArlodotexe
authored andcommitted
Add initial test case for FrameworkElementExtension.RelativeAncestor
Fixes malaligned namespaces in tests.
1 parent 0a7b623 commit b838835

8 files changed

+81
-5
lines changed

components/Extensions/src/Element/FrameworkElementExtensions.Mouse.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace CommunityToolkit.WinUI;
1515

1616
// TODO: Note: Windows App SDK doesn't support this (need to use Protected Cursor), but we still use this extension for Sizer controls.
17-
// For now rather than not porting, we'll just exclude on Windows App SDK platforms. Fenced other blocks below and support both equivelent types, but don't have a general way to set cursor on window yet in PointerEntered/Exited. If in end, FrameworkElement gets non-protected Cursor property like WPF, then this extension also isn't needed.
17+
// For now rather than not porting, we'll just exclude on Windows App SDK platforms. Fenced other blocks below and support both equivalent types, but don't have a general way to set cursor on window yet in PointerEntered/Exited. If in end, FrameworkElement gets non-protected Cursor property like WPF, then this extension also isn't needed.
1818
// See https://github.com/microsoft/microsoft-ui-xaml/issues/4834
1919
#if !WINAPPSDK
2020

components/Extensions/tests/BitmapIconExtensionTestPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Page x:Class="ExtensionsExperiment.Tests.BitmapIconExtensionTestPage"
1+
<Page x:Class="ExtensionsComponent.Tests.BitmapIconExtensionTestPage"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

components/Extensions/tests/BitmapIconExtensionTestPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +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-
namespace ExtensionsExperiment.Tests;
5+
namespace ExtensionsComponent.Tests;
66

77
/// <summary>
88
/// An empty page that can be used on its own or navigated to within a Frame.

components/Extensions/tests/BitmapIconExtensionTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
using CommunityToolkit.Tests;
66
using CommunityToolkit.Tooling.TestGen;
7-
using CommunityToolkit.WinUI;
8-
using ExtensionsExperiment.Tests;
97

108
namespace ExtensionsComponent.Tests;
119

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 CommunityToolkit.Tests;
6+
using CommunityToolkit.Tooling.TestGen;
7+
8+
namespace ExtensionsComponent.Tests;
9+
10+
[TestClass]
11+
public partial class FrameworkElementExtensionsTests : VisualUITestBase
12+
{
13+
[TestCategory("FrameworkElementExtension")]
14+
[UIThreadTestMethod]
15+
public void FrameworkElementExtension_RelativeAncestor_InDataTemplate(FrameworkElementRelativeAncestorDataTemplateTestPage page)
16+
{
17+
var list = page.FindDescendant<ListView>();
18+
19+
Assert.IsNotNull(list, "Couldn't find listview");
20+
21+
int count = 0;
22+
foreach (var item in list.FindDescendants().OfType<TextBlock>())
23+
{
24+
count++;
25+
Assert.AreEqual("Hello", item.Text, "Text didn't match binding of ancestor tag property");
26+
}
27+
28+
Assert.AreEqual(3, count, "Didn't find three textblocks");
29+
}
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Page x:Class="ExtensionsComponent.Tests.FrameworkElementRelativeAncestorDataTemplateTestPage"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:ui="using:CommunityToolkit.WinUI"
7+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
8+
mc:Ignorable="d">
9+
10+
<Grid>
11+
<ListView x:Name="ListViewControl"
12+
Tag="Hello">
13+
<ListView.ItemTemplate>
14+
<DataTemplate>
15+
<TextBlock ui:FrameworkElementExtensions.AncestorType="ListView"
16+
Text="{Binding (ui:FrameworkElementExtensions.Ancestor).Tag, RelativeSource={RelativeSource Self}}" />
17+
</DataTemplate>
18+
</ListView.ItemTemplate>
19+
<x:String>1</x:String>
20+
<x:String>2</x:String>
21+
<x:String>3</x:String>
22+
</ListView>
23+
</Grid>
24+
</Page>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
namespace ExtensionsComponent.Tests;
6+
7+
/// <summary>
8+
/// An empty page that can be used on its own or navigated to within a Frame.
9+
/// </summary>
10+
public sealed partial class FrameworkElementRelativeAncestorDataTemplateTestPage : Page
11+
{
12+
public FrameworkElementRelativeAncestorDataTemplateTestPage()
13+
{
14+
this.InitializeComponent();
15+
}
16+
}

components/Extensions/tests/Extensions.Tests.projitems

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,20 @@
1515
<Compile Include="$(MSBuildThisFileDirectory)BitmapIconExtensionTests.cs" />
1616
<Compile Include="$(MSBuildThisFileDirectory)DispatcherQueueExtensionTests.cs" />
1717
<Compile Include="$(MSBuildThisFileDirectory)DispatcherQueueTimerExtensionTests.cs" />
18+
<Compile Include="$(MSBuildThisFileDirectory)Element\FrameworkElementExtensionsTests.RelativeAncestor.cs" />
19+
<Compile Include="$(MSBuildThisFileDirectory)Element\FrameworkElementRelativeAncestorDataTemplateTestPage.xaml.cs">
20+
<DependentUpon>FrameworkElementRelativeAncestorDataTemplateTestPage.xaml</DependentUpon>
21+
</Compile>
1822
<Compile Include="$(MSBuildThisFileDirectory)Helpers\ObjectWithNullableBoolProperty.cs" />
1923
</ItemGroup>
2024
<ItemGroup>
2125
<Page Include="$(MSBuildThisFileDirectory)BitmapIconExtensionTestPage.xaml">
2226
<SubType>Designer</SubType>
2327
<Generator>MSBuild:Compile</Generator>
2428
</Page>
29+
<Page Include="$(MSBuildThisFileDirectory)Element\FrameworkElementRelativeAncestorDataTemplateTestPage.xaml">
30+
<SubType>Designer</SubType>
31+
<Generator>MSBuild:Compile</Generator>
32+
</Page>
2533
</ItemGroup>
2634
</Project>

0 commit comments

Comments
 (0)