Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions UITests/UITests.App/App.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<Application
x:Class="UITests.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.App">

</Application>
<Application x:Class="UITests.App.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.App" />
22 changes: 21 additions & 1 deletion UITests/UITests.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.UI.Xaml;
Expand All @@ -13,6 +16,8 @@ namespace UITests.App
{
public sealed partial class App
{
internal Dictionary<string, Type> TestPages { get; } = new Dictionary<string, Type>();

public App()
{
this.InitializeComponent();
Expand All @@ -26,6 +31,21 @@ public App()
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
var pages = Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.IsSubclassOf(typeof(Page)));

foreach (var page in pages)
{
try
{
TestPages.Add(page.Name, page);
}
catch (ArgumentException ex)
{
throw new Exception("Two or more test pages share a name.", ex);
}
}

Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
Expand Down Expand Up @@ -53,7 +73,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
rootFrame.Navigate(typeof(MainTestHost), e.Arguments);
}

// Ensure the current window is active
Expand Down
19 changes: 0 additions & 19 deletions UITests/UITests.App/MainPage.xaml.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Page
x:Class="UITests.App.MainPage"
x:Class="UITests.App.MainTestHost"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:testhelpers="using:AppTestAutomationHelpers"
Expand All @@ -9,11 +9,16 @@
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<testhelpers:TestAutomationHelpersPanel />

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="Click Me" Click="Button_Click"/>
<TextBlock x:Name="textBlock"/>
<Frame x:Name="navigationFrame" />

<StackPanel Orientation="Horizontal" Grid.Row="1" >
<TextBox x:Name="PageName" KeyDown="PageName_KeyDown"/>
</StackPanel>
</Grid>
</Page>
46 changes: 46 additions & 0 deletions UITests/UITests.App/MainTestHost.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;

namespace UITests.App
{
/// <summary>
/// MainPage hosting all other test pages.
/// </summary>
public sealed partial class MainTestHost
{
private readonly Dictionary<string, Type> pageMap;

public MainTestHost()
{
InitializeComponent();
pageMap = ((App)Application.Current).TestPages;
}

private void PageName_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Enter && sender is TextBox s)
{
OpenPage(s.Text);
}
}

private void OpenPage(string pageName)
{
try
{
navigationFrame.Navigate(pageMap[pageName]);
}
catch (KeyNotFoundException ex)
{
throw new Exception("Cannot find page.", ex);
}
}
}
}
10 changes: 6 additions & 4 deletions UITests/UITests.App/UITests.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<AppxPackageSigningTimestampDigestAlgorithm>SHA256</AppxPackageSigningTimestampDigestAlgorithm>
<GenerateAppxPackageOnBuild>true</GenerateAppxPackageOnBuild>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<IsTestHost>true</IsTestHost>
</PropertyGroup>
<Target Name="Pack">
</Target>
Expand Down Expand Up @@ -130,8 +131,8 @@
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
<Compile Include="MainTestHost.xaml.cs">
<DependentUpon>MainTestHost.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand All @@ -155,7 +156,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainPage.xaml">
<Page Include="MainTestHost.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
Expand Down Expand Up @@ -252,4 +253,5 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
<Import Project="..\UITests.Tests.Shared\UITests.Tests.Shared.projitems" Label="Shared" />
</Project>
3 changes: 3 additions & 0 deletions UITests/UITests.Tests.MSTest/MSTestInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace UITests.Tests
// TAEF has a different terms for the same concepts as compared with MSTest.
// In order to allow both to use the same test files, we'll define these helper classes
// to translate TAEF into MSTest.
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649:File name should match first type name", Justification = "Shim helpers")]
public static class Log
{
public static void Comment(string format, params object[] args)
Expand Down Expand Up @@ -41,6 +42,7 @@ private static void LogMessage(string format, object[] args)
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Shim helpers.")]
public static class LogController
{
public static void InitializeLogging()
Expand All @@ -49,6 +51,7 @@ public static void InitializeLogging()
}
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "Shim helpers.")]
public static class Verify
{
// TODO: implement
Expand Down
4 changes: 3 additions & 1 deletion UITests/UITests.Tests.MSTest/UITests.Tests.MSTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<PlatformTarget>x86</PlatformTarget>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>

<IsTestHarness>true</IsTestHarness>
</PropertyGroup>

<ItemGroup>
Expand All @@ -27,5 +29,5 @@
<PackageReference Include="Microsoft.Windows.Apps.Test" Version="1.0.181205002" />
</ItemGroup>

<Import Project="..\UITests.Tests.Shared\UITests.Tests.Shared.projitems" />
<Import Project="..\UITests.Tests.Shared\UITests.Tests.Shared.projitems" Label="Shared" />
</Project>
56 changes: 56 additions & 0 deletions UITests/UITests.Tests.Shared/Controls/TextBoxMaskTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.Windows.Apps.Test.Foundation.Controls;
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Common;
using Windows.UI.Xaml.Tests.MUXControls.InteractionTests.Infra;

#if USING_TAEF
using WEX.Logging.Interop;
using WEX.TestExecution;
using WEX.TestExecution.Markup;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif

namespace UITests.Tests
{
[TestClass]
public class TextBoxMaskTest : UITestBase
{
[ClassInitialize]
[TestProperty("RunAs", "User")]
[TestProperty("Classification", "ScenarioTestSuite")]
[TestProperty("Platform", "Any")]
public static void ClassInitialize(TestContext testContext)
{
TestEnvironment.Initialize(testContext, WinUICsUWPSampleApp);
}

[ClassCleanup]
public static void ClassCleanup()
{
TestEnvironment.AssemblyCleanupWorker(WinUICsUWPSampleApp);
}

[TestMethod]
[TestPage("TextBoxMaskTestPage")]
public void TestTextBoxMaskBinding_Property()
{
var initialValue = FindElement.ById<TextBlock>("InitialValueTextBlock").GetText();
var textBox = FindElement.ById<Edit>("TextBox");

Verify.AreEqual(initialValue, textBox.GetText());

var changeButton = FindElement.ById<Button>("ChangeButton");

changeButton.Click();
Wait.ForIdle();

var newValue = FindElement.ById<TextBlock>("NewValueTextBlock").GetText();

Verify.AreEqual(newValue, textBox.GetText());
}
}
}
47 changes: 47 additions & 0 deletions UITests/UITests.Tests.Shared/Controls/TextBoxMaskTestPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Page x:Class="UITests.App.Pages.TextBoxMaskTestPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">
<Grid HorizontalAlignment="Center"
VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="10" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="10" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button x:Name="ChangeButton"
Grid.Row="0"
Grid.Column="0"
Click="ChangeButton_Click"
Content="Change Target Value" />
<TextBox x:Name="TextBox"
Grid.Row="0"
Grid.Column="2"
Width="120"
Padding="0,4,0,0"
VerticalAlignment="Center"
extensions:TextBoxMask.CustomMask="5:[0-5]"
extensions:TextBoxMask.Mask="99:59:59"
Text="{x:Bind Value, Mode=OneWay}"
TextAlignment="Center" />
<TextBlock x:Name="InitialValueTextBlock"
Grid.Row="2"
Grid.Column="0"
HorizontalAlignment="Center"
Text="{x:Bind InitialValue}" />
<TextBlock x:Name="NewValueTextBlock"
Grid.Row="2"
Grid.Column="2"
HorizontalAlignment="Center"
Text="{x:Bind NewValue}" />
</Grid>
</Page>
41 changes: 41 additions & 0 deletions UITests/UITests.Tests.Shared/Controls/TextBoxMaskTestPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace UITests.App.Pages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class TextBoxMaskTestPage : Page
{
private const string INITIAL_VALUE = "12:50:59";
private const string NEW_VALUE = "00:00:00";

public string InitialValue => INITIAL_VALUE;

public string NewValue => NEW_VALUE;

public string Value
{
get { return (string)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}

public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register(nameof(Value), typeof(string), typeof(TextBoxMaskTestPage), new PropertyMetadata(INITIAL_VALUE));

public TextBoxMaskTestPage()
{
this.InitializeComponent();
}

private void ChangeButton_Click(object sender, RoutedEventArgs e)
{
Value = NEW_VALUE;
}
}
}
Loading