From 443919cf6679b4681b641dc5196b8b74bbd20c4e Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Tue, 6 Aug 2024 23:32:55 +0800 Subject: [PATCH] Tests --- .../TemplateTests.cs | 65 +++++++++++++++---- 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs index 566cfa949d61..6585240c8d25 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs @@ -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"); @@ -200,18 +200,23 @@ public void BuildUnpackaged(string id, string framework, string config) EnableTizen(projectFile); FileUtilities.ReplaceInFile(projectFile, - "true", - "trueNone"); + "None", + ""); 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."); @@ -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, - "true", + "None", $""" - true {wasdkself} {netself} + {packageType} """); 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."); } @@ -254,9 +259,8 @@ public void BuildWindowsRidGraph(string id, bool useridgraph, string packageType $"Unable to create template {id}. Check test output for errors."); FileUtilities.ReplaceInFile(projectFile, - "true", + "None", $""" - true {useridgraph} {packageType} """); @@ -264,7 +268,7 @@ public void BuildWindowsRidGraph(string id, bool useridgraph, string packageType 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."); } @@ -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) @@ -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, + "None", + ""); + + 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}"); + } + } + /// /// Tests the scenario where a .NET MAUI Library specifically uses UseMauiCore instead of UseMaui. ///