Skip to content

Commit 5e3c730

Browse files
committed
chore: try to use MAUI TestUtils
1 parent 18e78a5 commit 5e3c730

File tree

118 files changed

+5176
-849
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+5176
-849
lines changed

MauiTestUtils/Directory.Build.targets

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<Project>
2+
<PropertyGroup>
3+
<UseMaui>true</UseMaui>
4+
<MauiVersion>6.0.312</MauiVersion>
5+
</PropertyGroup>
6+
</Project>

MauiTestUtils/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Originally from https://github.com/dotnet/maui/tree/e9cd5a3736e2f4ce0b05d571489a158a2f0ed41e/src/TestUtils
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
4+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
5+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
7+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>UIDeviceFamily</key>
6+
<array>
7+
<integer>1</integer>
8+
<integer>2</integer>
9+
</array>
10+
<key>UIRequiredDeviceCapabilities</key>
11+
<array>
12+
<string>arm64</string>
13+
</array>
14+
<key>UISupportedInterfaceOrientations</key>
15+
<array>
16+
<string>UIInterfaceOrientationPortrait</string>
17+
<string>UIInterfaceOrientationLandscapeLeft</string>
18+
<string>UIInterfaceOrientationLandscapeRight</string>
19+
</array>
20+
<key>UISupportedInterfaceOrientations~ipad</key>
21+
<array>
22+
<string>UIInterfaceOrientationPortrait</string>
23+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
24+
<string>UIInterfaceOrientationLandscapeLeft</string>
25+
<string>UIInterfaceOrientationLandscapeRight</string>
26+
</array>
27+
<key>XSAppIconAssets</key>
28+
<string>Assets.xcassets/appicon.appiconset</string>
29+
</dict>
30+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<local:MiddleApp
2+
x:Class="Microsoft.Maui.TestUtils.DeviceTests.Sample.WinUI.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:Microsoft.Maui.TestUtils.DeviceTests.Sample.WinUI">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
10+
<!-- Other merged dictionaries here -->
11+
</ResourceDictionary.MergedDictionaries>
12+
<!-- Other app resources here -->
13+
</ResourceDictionary>
14+
</Application.Resources>
15+
</local:MiddleApp>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.Maui;
2+
using Microsoft.Maui.Hosting;
3+
using Microsoft.UI.Xaml;
4+
using Windows.ApplicationModel;
5+
6+
// To learn more about WinUI, the WinUI project structure,
7+
// and more about our project templates, see: http://aka.ms/winui-project-info.
8+
9+
namespace Microsoft.Maui.TestUtils.DeviceTests.Sample.WinUI
10+
{
11+
/// <summary>
12+
/// Provides application-specific behavior to supplement the default Application class.
13+
/// </summary>
14+
public partial class App : MiddleApp
15+
{
16+
/// <summary>
17+
/// Initializes the singleton application object. This is the first line of authored code
18+
/// executed, and as such is the logical equivalent of main() or WinMain().
19+
/// </summary>
20+
public App()
21+
{
22+
this.InitializeComponent();
23+
}
24+
}
25+
26+
public class MiddleApp : MauiWinUIApplication
27+
{
28+
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<Package
4+
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
5+
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
6+
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
7+
IgnorableNamespaces="uap rescap">
8+
9+
<Identity
10+
Name="F91A4766-67A8-413B-A652-7D2B96EEE218"
11+
Publisher="CN=User Name"
12+
Version="1.0.0.0" />
13+
14+
<Properties>
15+
<DisplayName>Tests Sample</DisplayName>
16+
<PublisherDisplayName>Microsoft</PublisherDisplayName>
17+
<Logo>appiconStoreLogo.png</Logo>
18+
</Properties>
19+
20+
<Dependencies>
21+
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
22+
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
23+
</Dependencies>
24+
25+
<Resources>
26+
<Resource Language="x-generate"/>
27+
</Resources>
28+
29+
<Applications>
30+
<Application Id="App"
31+
Executable="$targetnametoken$.exe"
32+
EntryPoint="$targetentrypoint$">
33+
<uap:VisualElements
34+
DisplayName="Tests Sample"
35+
Description="Tests Sample"
36+
BackgroundColor="transparent"
37+
Square150x150Logo="appiconMediumTile.png"
38+
Square44x44Logo="appiconLogo.png">
39+
<uap:DefaultTile
40+
Wide310x150Logo="appiconWideTile.png"
41+
Square71x71Logo="appiconSmallTile.png"
42+
Square310x310Logo="appiconLargeTile.png"
43+
ShortName="Tests Sample">
44+
<uap:ShowNameOnTiles>
45+
<uap:ShowOn Tile="square150x150Logo"/>
46+
<uap:ShowOn Tile="wide310x150Logo"/>
47+
</uap:ShowNameOnTiles>
48+
</uap:DefaultTile >
49+
<uap:SplashScreen Image="appiconfgSplashScreen.png" />
50+
</uap:VisualElements>
51+
</Application>
52+
</Applications>
53+
54+
<Capabilities>
55+
<rescap:Capability Name="runFullTrust" />
56+
</Capabilities>
57+
58+
</Package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
3+
<assemblyIdentity version="1.0.0.0" name="Microsoft.Maui.TestUtils.DeviceTests.Sample.WinUI.app"/>
4+
5+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
6+
<windowsSettings>
7+
<!-- The combination of below two tags have the following effect:
8+
1) Per-Monitor for >= Windows 10 Anniversary Update
9+
2) System < Windows 10 Anniversary Update
10+
-->
11+
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
12+
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
13+
</windowsSettings>
14+
</application>
15+
</assembly>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>LSRequiresIPhoneOS</key>
6+
<true/>
7+
<key>UIDeviceFamily</key>
8+
<array>
9+
<integer>1</integer>
10+
<integer>2</integer>
11+
</array>
12+
<key>UIRequiredDeviceCapabilities</key>
13+
<array>
14+
<string>arm64</string>
15+
</array>
16+
<key>UISupportedInterfaceOrientations</key>
17+
<array>
18+
<string>UIInterfaceOrientationPortrait</string>
19+
<string>UIInterfaceOrientationLandscapeLeft</string>
20+
<string>UIInterfaceOrientationLandscapeRight</string>
21+
</array>
22+
<key>UISupportedInterfaceOrientations~ipad</key>
23+
<array>
24+
<string>UIInterfaceOrientationPortrait</string>
25+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
26+
<string>UIInterfaceOrientationLandscapeLeft</string>
27+
<string>UIInterfaceOrientationLandscapeRight</string>
28+
</array>
29+
<key>XSAppIconAssets</key>
30+
<string>Assets.xcassets/appicon.appiconset</string>
31+
</dict>
32+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"profiles": {
3+
"Windows Machine": {
4+
"commandName": "MsixPackage"
5+
}
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.Maui.Hosting;
2+
using Microsoft.Maui.TestUtils.DeviceTests.Runners;
3+
4+
namespace Microsoft.Maui.TestUtils.DeviceTests.Sample
5+
{
6+
public static class MauiProgram
7+
{
8+
public static MauiApp CreateMauiApp()
9+
{
10+
var appBuilder = MauiApp.CreateBuilder();
11+
appBuilder
12+
.ConfigureTests(new TestOptions
13+
{
14+
Assemblies =
15+
{
16+
typeof(MauiProgram).Assembly
17+
},
18+
})
19+
.UseHeadlessRunner(new HeadlessRunnerOptions
20+
{
21+
RequiresUIContext = true,
22+
})
23+
.UseVisualRunner();
24+
25+
return appBuilder.Build();
26+
}
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>$(MauiPlatformsNoMacCat)</TargetFrameworks>
5+
<OutputType>Exe</OutputType>
6+
<SingleProject>true</SingleProject>
7+
<RootNamespace>Microsoft.Maui.TestUtils.DeviceTests.Sample</RootNamespace>
8+
<AssemblyName>Microsoft.Maui.TestUtils.DeviceTests.Sample</AssemblyName>
9+
</PropertyGroup>
10+
11+
<PropertyGroup>
12+
<ApplicationTitle>Tests Sample</ApplicationTitle>
13+
<ApplicationId>com.microsoft.maui.testutils.devicetests</ApplicationId>
14+
<ApplicationVersion>1</ApplicationVersion>
15+
</PropertyGroup>
16+
17+
<ItemGroup>
18+
<MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />
19+
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" BaseSize="128,128" />
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests\TestUtils.DeviceTests.csproj" />
24+
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests.Runners\TestUtils.DeviceTests.Runners.csproj" />
25+
<ProjectReference Include="..\..\..\TestUtils\src\DeviceTests.Runners.SourceGen\TestUtils.DeviceTests.Runners.SourceGen.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
26+
<ProjectReference Include="..\..\..\Compatibility\Core\src\Compatibility.csproj" />
27+
<ProjectReference Include="..\..\..\Core\src\Core.csproj" />
28+
<ProjectReference Include="..\..\..\Controls\src\Xaml\Controls.Xaml.csproj" />
29+
<ProjectReference Include="..\..\..\Controls\src\Core\Controls.Core.csproj" />
30+
</ItemGroup>
31+
32+
<Import Project="$(MauiSrcDirectory)Maui.InTree.props" Condition=" '$(UseMaui)' != 'true' " />
33+
34+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using Xunit;
3+
using Xunit.Abstractions;
4+
5+
namespace Microsoft.Maui.TestUtils.DeviceTests.Sample
6+
{
7+
public class UnitTests
8+
{
9+
readonly ITestOutputHelper _output;
10+
11+
public UnitTests(ITestOutputHelper output)
12+
{
13+
_output = output;
14+
}
15+
16+
[Fact]
17+
public void SuccessfulTest()
18+
{
19+
Assert.True(true);
20+
}
21+
22+
[Fact(Skip = "This test is skipped.")]
23+
public void SkippedTest()
24+
{
25+
}
26+
27+
[Fact]
28+
public void FailingTest()
29+
{
30+
throw new Exception("This is meant to fail.");
31+
}
32+
33+
[Theory]
34+
[InlineData(1)]
35+
[InlineData(2)]
36+
[InlineData(3)]
37+
public void ParameterizedTest(int number)
38+
{
39+
Assert.NotEqual(0, number);
40+
}
41+
42+
[Fact]
43+
public void OutputTest()
44+
{
45+
_output.WriteLine("This is test output.");
46+
}
47+
48+
[Fact]
49+
public void FailingOutputTest()
50+
{
51+
_output.WriteLine("This is test output.");
52+
throw new Exception("This is meant to fail.");
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project>
2+
3+
<Import Project="$(MauiSrcDirectory)Maui.InTree.targets" Condition=" '$(UseMaui)' != 'true' " />
4+
<Import Project="$(_MauiBuildTasksLocation)Microsoft.Maui.TestUtils.DeviceTests.Runners.targets" />
5+
<Import Project="$(MauiRootDirectory)Directory.Build.targets" />
6+
7+
</Project>

MauiTestUtils/src/DeviceTests.Runners.SourceGen/AnalyzerReleases.Shipped.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### New Rules
2+
3+
Rule ID | Category | Severity | Notes
4+
--------|----------|----------|--------------------
5+
TST1001 | Logging | Info | Logging messages
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Microsoft.CodeAnalysis;
2+
3+
namespace Microsoft.Maui.TestUtils.DeviceTests.Runners.SourceGen
4+
{
5+
[Generator]
6+
public class CodeBehindGenerator : ISourceGenerator
7+
{
8+
public void Initialize(GeneratorInitializationContext context)
9+
{
10+
//#if DEBUG
11+
//if (!System.Diagnostics.Debugger.IsAttached)
12+
// System.Diagnostics.Debugger.Launch();
13+
//#endif
14+
}
15+
16+
public void Execute(GeneratorExecutionContext context)
17+
{
18+
if (!context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.TargetFramework", out var targetFramework))
19+
return;
20+
21+
context.Log($"TargetFramework: {targetFramework}");
22+
23+
var generator = new RunnerGenerator(context, targetFramework);
24+
25+
generator?.Generate();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)