Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Aug 6, 2024
1 parent e8404e2 commit 443919c
Showing 1 changed file with 52 additions and 13 deletions.
65 changes: 52 additions & 13 deletions src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void BuildWithMauiVersion(string id, string framework, string config, boo
[TestCase("maui-blazor", DotNetPrevious, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Debug")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
public void BuildUnpackaged(string id, string framework, string config)
public void BuildPackaged(string id, string framework, string config)
{
var projectDir = TestDirectory;
var projectFile = Path.Combine(projectDir, $"{Path.GetFileName(projectDir)}.csproj");
Expand All @@ -200,18 +200,23 @@ public void BuildUnpackaged(string id, string framework, string config)

EnableTizen(projectFile);
FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
"<UseMaui>true</UseMaui><WindowsPackageType>None</WindowsPackageType>");
"<WindowsPackageType>None</WindowsPackageType>",
"");

Assert.IsTrue(DotnetInternal.Build(projectFile, config, properties: BuildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

[Test]
[TestCase("maui", true, true)]
[TestCase("maui", true, false)]
[TestCase("maui", false, true)]
public void BuildWindowsAppSDKSelfContained(string id, bool wasdkself, bool netself)
[TestCase("maui", true, true, "None")]
[TestCase("maui", true, true, "MSIX")]
[TestCase("maui", true, false, "None")]
[TestCase("maui", true, false, "MSIX")]
[TestCase("maui", false, true, "None")]
[TestCase("maui", false, true, "MSIX")]
[TestCase("maui", false, false, "None")]
[TestCase("maui", false, false, "MSIX")]
public void BuildWindowsAppSDKSelfContained(string id, bool wasdkself, bool netself, string packageType)
{
if (TestEnvironment.IsMacOS)
Assert.Ignore("This test is designed for testing a windows build.");
Expand All @@ -223,17 +228,17 @@ public void BuildWindowsAppSDKSelfContained(string id, bool wasdkself, bool nets
$"Unable to create template {id}. Check test output for errors.");

FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
"<WindowsPackageType>None</WindowsPackageType>",
$"""
<UseMaui>true</UseMaui>
<WindowsAppSDKSelfContained>{wasdkself}</WindowsAppSDKSelfContained>
<SelfContained>{netself}</SelfContained>
<WindowsPackageType>{packageType}</WindowsPackageType>
""");

var extendedBuildProps = BuildProps;
extendedBuildProps.Add($"TargetFramework={DotNetCurrent}-windows10.0.19041.0");

Assert.IsTrue(DotnetInternal.Build(projectFile, "Release", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
Assert.IsTrue(DotnetInternal.Build(projectFile, "Debug", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

Expand All @@ -254,17 +259,16 @@ public void BuildWindowsRidGraph(string id, bool useridgraph, string packageType
$"Unable to create template {id}. Check test output for errors.");

FileUtilities.ReplaceInFile(projectFile,
"<UseMaui>true</UseMaui>",
"<WindowsPackageType>None</WindowsPackageType>",
$"""
<UseMaui>true</UseMaui>
<UseRidGraph>{useridgraph}</UseRidGraph>
<WindowsPackageType>{packageType}</WindowsPackageType>
""");

var extendedBuildProps = BuildProps;
extendedBuildProps.Add($"TargetFramework={DotNetCurrent}-windows10.0.19041.0");

Assert.IsTrue(DotnetInternal.Build(projectFile, "Release", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
Assert.IsTrue(DotnetInternal.Build(projectFile, "Debug", properties: extendedBuildProps, msbuildWarningsAsErrors: true),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");
}

Expand Down Expand Up @@ -321,6 +325,7 @@ public void PublishNativeAOTCheckWarnings(string id, string framework, string ru

[Test]
[TestCase("maui", DotNetCurrent, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
public void PublishUnpackaged(string id, string framework, string config)
{
if (!TestEnvironment.IsWindows)
Expand Down Expand Up @@ -353,6 +358,40 @@ void AssetExists(string filename)
}
}

[Test]
[TestCase("maui", DotNetCurrent, "Release")]
[TestCase("maui-blazor", DotNetCurrent, "Release")]
public void PublishPackaged(string id, string framework, string config)
{
if (!TestEnvironment.IsWindows)
Assert.Ignore("Running Windows templates is only supported on Windows.");

var projectDir = TestDirectory;
var name = Path.GetFileName(projectDir);
var projectFile = Path.Combine(projectDir, $"{name}.csproj");

Assert.IsTrue(DotnetInternal.New(id, projectDir, framework),
$"Unable to create template {id}. Check test output for errors.");

FileUtilities.ReplaceInFile(projectFile,
"<WindowsPackageType>None</WindowsPackageType>",
"");

Assert.IsTrue(DotnetInternal.Publish(projectFile, config, framework: $"{framework}-windows10.0.19041.0", properties: BuildProps),
$"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors.");

var assetsRoot = Path.Combine(projectDir, $"bin/{config}/{framework}-windows10.0.19041.0/win10-x64/AppPackages/{name}_1.0.0.1_Test");

AssetExists($"{name}_1.0.0.1_x64.msi");

void AssetExists(string filename)
{
var fullpath = Path.Combine(assetsRoot!, filename);
Assert.IsTrue(File.Exists(fullpath),
$"Unable to find expected asset: {fullpath}");
}
}

/// <summary>
/// Tests the scenario where a .NET MAUI Library specifically uses UseMauiCore instead of UseMaui.
/// </summary>
Expand Down

0 comments on commit 443919c

Please sign in to comment.