From 2522f46e31193e57b46b7d6db87a566d79172405 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 14:18:46 -0600 Subject: [PATCH 01/11] fix: use root xmlns --- .../src/GeneratePackageAppxManifest.cs | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index d9c4f98e..7d23aabe 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -17,8 +17,6 @@ public class GeneratePackageAppxManifest_v0 : Task const string ErrorVersionNumberCombination = "ApplicationDisplayVersion '{0}' was not a valid 3 part semver version number and/or ApplicationVersion '{1}' was not a valid integer."; - static readonly XNamespace xmlnsUap = "http://schemas.microsoft.com/appx/manifest/uap/windows10"; - [Required] public string IntermediateOutputPath { get; set; } = null!; @@ -181,7 +179,7 @@ void UpdateManifest(XDocument appx) } // - var xvisual = xmlnsUap + "VisualElements"; + var xvisual = xmlns + "VisualElements"; var visual = application.Element(xvisual); if (visual == null) { @@ -190,7 +188,7 @@ void UpdateManifest(XDocument appx) } // - var xtile = xmlnsUap + "DefaultTile"; + var xtile = xmlns + "DefaultTile"; var tile = visual.Element(xtile); if (tile == null) { @@ -199,7 +197,7 @@ void UpdateManifest(XDocument appx) } // - var xshowname = xmlnsUap + "ShowNameOnTiles"; + var xshowname = xmlns + "ShowNameOnTiles"; var showname = tile.Element(xshowname); if (showname == null) { @@ -226,7 +224,7 @@ void UpdateManifest(XDocument appx) UpdateDefaultTileSquare310Logo(tile, appIconInfo); // - var xshowon = xmlnsUap + "ShowOn"; + var xshowon = xmlns + "ShowOn"; var showons = showname.Elements(xshowon).ToArray(); if (showons.All(x => x.Attribute("Tile")?.Value != "square150x150Logo")) { @@ -242,7 +240,7 @@ void UpdateManifest(XDocument appx) if (splashInfo != null) { // - var xsplash = xmlnsUap + "SplashScreen"; + var xsplash = xmlns + "SplashScreen"; var splash = visual.Element(xsplash); if (splash == null) { @@ -523,19 +521,19 @@ private static void SetVersion(XElement target, XName attributeName, string vers } } - static bool IsVersionAttribute(XAttribute attribute, XName attributeName) - { - var currentAttributeName = attribute.Name.LocalName; - var expectedAttributeName = attributeName.LocalName; - - var currentAttributeNamespace = attribute.Name.Namespace.NamespaceName; - var expectedAttributeNamespace = attributeName.NamespaceName; - - // The Version may not have a current Namespace and should use the default namespace - if (string.IsNullOrEmpty(currentAttributeNamespace)) - return currentAttributeName == expectedAttributeName; - - return currentAttributeName == expectedAttributeName && currentAttributeNamespace == expectedAttributeNamespace; + static bool IsVersionAttribute(XAttribute attribute, XName attributeName) + { + var currentAttributeName = attribute.Name.LocalName; + var expectedAttributeName = attributeName.LocalName; + + var currentAttributeNamespace = attribute.Name.Namespace.NamespaceName; + var expectedAttributeNamespace = attributeName.NamespaceName; + + // The Version may not have a current Namespace and should use the default namespace + if (string.IsNullOrEmpty(currentAttributeNamespace)) + return currentAttributeName == expectedAttributeName; + + return currentAttributeName == expectedAttributeName && currentAttributeNamespace == expectedAttributeNamespace; } public static bool TryMergeVersionNumbers(string? displayVersion, string? version, out string? finalVersion) From 934a18cb4683b7fac9c632317858559157b1862f Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 15:42:51 -0600 Subject: [PATCH 02/11] test: updating AppxManifest Tests --- .../GeneratePackageAppxManifestTests.cs | 66 ++++++++++------ .../test/UnitTests/Mocks/MockTaskItem.cs | 76 +++++++++++++++++++ .../template.expected.appxmanifest | 32 ++++++++ .../appxmanifest/template.input.appxmanifest | 24 ++++++ 4 files changed, 175 insertions(+), 23 deletions(-) create mode 100644 src/Resizetizer/test/UnitTests/Mocks/MockTaskItem.cs create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.input.appxmanifest diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index 8ed738f1..f84ae6a2 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -1,8 +1,10 @@ #nullable enable using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Resizetizer.UnitTests.Mocks; using System; using System.Collections; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; @@ -29,7 +31,7 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( IntermediateOutputPath = DestinationDirectory, BuildEngine = this, GeneratedFilename = generatedFilename, - AppxManifest = new []{new TaskItem(manifest)}, + AppxManifest = [new TaskItem(manifest)], ApplicationId = applicationId, ApplicationDisplayVersion = displayVersion, ApplicationVersion = version, @@ -37,8 +39,8 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( AssemblyName = GetType().Assembly.FullName, Description = description, ApplicationPublisher = applicationPublisher, - AppIcon = appIcon == null ? null : new[] { appIcon }, - SplashScreen = splashScreen == null ? null : new[] { splashScreen }, + AppIcon = appIcon == null ? null : [appIcon], + SplashScreen = splashScreen == null ? null : [splashScreen], TargetFramework = "windows" }; } @@ -70,8 +72,8 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( Description = description, ApplicationPublisher = applicationPublisher, AssemblyName = GetType().Assembly.GetName().Name, - AppIcon = appIcon == null ? null : new[] { appIcon }, - SplashScreen = splashScreen == null ? null : new[] { splashScreen }, + AppIcon = appIcon == null ? null : [appIcon], + SplashScreen = splashScreen == null ? null : [splashScreen], TargetFramework = "windows", TargetPlatformVersion = targetPlatformVersion, TargetPlatformMinVersion = targetPlatformMinVersion @@ -95,12 +97,8 @@ public void FileIsGenerated(string? specificFn, string outputFn) [Fact] public void ManifestTakesPriority() { - var appIcon = new TaskItem("images/camera.svg"); - appIcon.SetMetadata("ForegroundFile", "images/loginbg.png"); - appIcon.SetMetadata("IsAppIcon", "true"); - - var splashScreen = new TaskItem("images/dotnet_logo.svg"); - splashScreen.SetMetadata("Color", "#FFFFFF"); + var appIcon = MockTaskItem.CreateAppIcon("images/camera.svg", "images/loginbg.png"); + var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_logo.svg", "#FFFFFF"); var inputFilename = $"testdata/appxmanifest/typical.appxmanifest"; var task = GetNewTask(inputFilename, @@ -131,14 +129,9 @@ public void CorrectGenerationWhenUserSpecifyBackgroundColor() { var input = "empty"; var expected = "typicalWithNoBackground"; - var appIcon = new TaskItem("images\\appicon.svg"); - appIcon.SetMetadata("ForegroundFile", "images\\appiconfg.svg"); - appIcon.SetMetadata("Link", "images\\appicon.svg"); - appIcon.SetMetadata("IsAppIcon", "true"); - - var splashScreen = new TaskItem("images/dotnet_bot.svg"); - splashScreen.SetMetadata("Color", "#FFFFFF"); + var appIcon = MockTaskItem.CreateAppIcon("images/appicon.svg", "images/appiconfg.svg"); appIcon.SetMetadata("Color", "#FFFFFF"); + var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_bot.svg", "#FFFFFF"); var inputFilename = $"testdata/appxmanifest/{input}.appxmanifest"; var task = GetNewTask(inputFilename, @@ -169,12 +162,9 @@ public void CorrectGenerationWhitOutBackgroundColor() { var input = "typical"; var expected = "typical"; - var appIcon = new TaskItem("images/appicon.svg"); - appIcon.SetMetadata("ForegroundFile", "images/appiconfg.svg"); - appIcon.SetMetadata("IsAppIcon", "true"); - var splashScreen = new TaskItem("images/dotnet_bot.svg"); - splashScreen.SetMetadata("Color", "#FFFFFF"); + var appIcon = MockTaskItem.CreateAppIcon("images/appicon.svg", "images/appiconfg.svg"); + var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_bot.svg", "#FFFFFF"); var inputFilename = $"testdata/appxmanifest/{input}.appxmanifest"; var task = GetNewTask(inputFilename, @@ -255,6 +245,36 @@ public void TaskShouldNotDuplicateTargetVersions() AssertExpectedManifest(task.GeneratedAppxManifest.ItemSpec, taskItem.ItemSpec); } + [Theory] + [InlineData("template")] + public void GeneratesExpectedAppxManifest(string manifestName) + { + // Arrange + var appIcon = MockTaskItem.CreateAppIcon("images/camera.svg", "images/loginbg.png"); + var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_logo.svg", "#FFFFFF"); + + var taskItem = new TaskItem($"testdata/appxmanifest/{manifestName}.input.appxmanifest"); + var task = GetNewTask( + appxManifests: [taskItem], + applicationId: "com.contoso.myapp", + displayVersion: "1.0.0", + version: "1", + displayName: "Sample App", + description: "This is a sample from the Unit Tests", + appIcon: appIcon, + splashScreen: splashScreen, + targetPlatformVersion: "10.0.19041.0", + targetPlatformMinVersion: "10.0.17763.0"); + + // Act + task.Execute(); + + // Assert + Assert.False(task.Log.HasLoggedErrors); + Assert.NotNull(task.GeneratedAppxManifest); + AssertExpectedManifest(task.GeneratedAppxManifest.ItemSpec, taskItem.ItemSpec); + } + [Fact] public void TaskShouldBeAbleToOverwriteAppxManifest() { diff --git a/src/Resizetizer/test/UnitTests/Mocks/MockTaskItem.cs b/src/Resizetizer/test/UnitTests/Mocks/MockTaskItem.cs new file mode 100644 index 00000000..060be676 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/Mocks/MockTaskItem.cs @@ -0,0 +1,76 @@ +using Microsoft.Build.Framework; +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace Resizetizer.UnitTests.Mocks; + +internal class MockTaskItem(string itemSpec, Dictionary metadata, bool useLink) : ITaskItem +{ + private readonly IDictionary _metadata = metadata; + + public string ItemSpec + { + get => itemSpec; + set => throw new NotImplementedException(); + } + + public ICollection MetadataNames => _metadata.Keys.ToArray(); + public int MetadataCount => MetadataNames.Count; + + public IDictionary CloneCustomMetadata() + { + throw new NotImplementedException(); + } + + public void CopyMetadataTo(ITaskItem destinationItem) + { + throw new NotImplementedException(); + } + + public string GetMetadata(string metadataName) + { + if (_metadata.ContainsKey(metadataName)) + { + return _metadata[metadataName]; + } + + return metadataName switch + { + "Link" => useLink ? ItemSpec : string.Empty, + "FullPath" => Path.GetFullPath(ItemSpec), + "DefiningProjectDirectory" => Environment.CurrentDirectory, + _ => string.Empty + }; + } + + public void RemoveMetadata(string metadataName) + { + throw new NotImplementedException(); + } + + public void SetMetadata(string metadataName, string metadataValue) + { + _metadata[metadataName] = metadataValue; + } + + public static ITaskItem CreateAppIcon(string itemSpec, string foregroundFile, bool useLink = true) + { + return new MockTaskItem(itemSpec, + new Dictionary + { + { "ForegroundFile", foregroundFile }, + { "IsAppIcon", "true" } + }, useLink); + } + + public static ITaskItem CreateSplashScreen(string itemSpec, string color = "#FFFFFF", bool useLink = true) + { + return new MockTaskItem(itemSpec, new Dictionary + { + { "Color", color } + }, useLink); + } +} diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest new file mode 100644 index 00000000..72875428 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest @@ -0,0 +1,32 @@ + + + + Uno Platform + Sample App + images\cameraStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.input.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.input.appxmanifest new file mode 100644 index 00000000..2f11a43a --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.input.appxmanifest @@ -0,0 +1,24 @@ + + + + + Uno Platform + + + + + + + + + + + + + + + + \ No newline at end of file From 8aa8f3682044879ab0b5b92d721a526e92eefb6f Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 16:27:36 -0600 Subject: [PATCH 03/11] chore: ensure document has XML declaration --- .../src/GeneratePackageAppxManifest.cs | 12 +++++- .../GeneratePackageAppxManifestTests.cs | 2 +- .../testdata/appxmanifest/empty.appxmanifest | 2 +- .../template.expected.appxmanifest | 3 +- .../typical.expected.appxmanifest | 42 +++++++++++++++++++ 5 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/typical.expected.appxmanifest diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index 7d23aabe..dc0b061e 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Linq; +using System.Xml; using System.Xml.Linq; namespace Uno.Resizetizer @@ -89,7 +90,16 @@ public override bool Execute() UpdateManifest(appx); - appx.Save(writer); + // Define the settings for the XmlWriter + var settings = new XmlWriterSettings + { + Indent = true, + Encoding = writer.Encoding, + OmitXmlDeclaration = false // Ensure the XML declaration is included + }; + + using var xmlWriter = XmlWriter.Create(writer, settings); + appx.Save(xmlWriter); }); GeneratedAppxManifest = new TaskItem(filename); diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index f84ae6a2..ff10c4fc 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -113,7 +113,7 @@ public void ManifestTakesPriority() Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); var outputFilename = Path.Combine(DestinationDirectory, "Package.appxmanifest"); - var expectedFilename = $"testdata/appxmanifest/typical.appxmanifest"; + var expectedFilename = $"testdata/appxmanifest/typical.expected.appxmanifest"; var outputDoc = XDocument.Load(outputFilename); var expectedDoc = XDocument.Load(expectedFilename); diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/empty.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/empty.appxmanifest index 2f11a43a..2377e8b4 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/empty.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/empty.appxmanifest @@ -1,4 +1,4 @@ - + + + Uno Platform diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typical.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typical.expected.appxmanifest new file mode 100644 index 00000000..86134363 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typical.expected.appxmanifest @@ -0,0 +1,42 @@ + + + + + Uno Platform + Sample App + images\appiconStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From c2878f2a46cf058c017ed1a62284d119d2abbdfd Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 17:16:22 -0600 Subject: [PATCH 04/11] test: Updating tests to correctly track expected outputs --- .../GeneratePackageAppxManifestTests.cs | 78 +++++++------------ ...ecifyBackgroundColor.expected.appxmanifest | 33 ++++++++ ...rSpecifyBackgroundColor.input.appxmanifest | 24 ++++++ ...hOutBackgroundColor.expected.appxmanifest} | 75 ++++++++---------- ...nWithOutBackgroundColor.input.appxmanifest | 36 +++++++++ .../duplicate-versions.expected.appxmanifest | 52 ++++++------- ...anifestTakesPriority.expected.appxmanifest | 35 +++++++++ .../manifestTakesPriority.input.appxmanifest | 36 +++++++++ .../template.expected.appxmanifest | 64 +++++++-------- 9 files changed, 284 insertions(+), 149 deletions(-) create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.input.appxmanifest rename src/Resizetizer/test/UnitTests/testdata/appxmanifest/{typical.expected.appxmanifest => correctGenerationWithOutBackgroundColor.expected.appxmanifest} (78%) create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.input.appxmanifest create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.input.appxmanifest diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index ff10c4fc..c05cd155 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -1,4 +1,6 @@ #nullable enable +//#define WRITE_EXPECTED + using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Resizetizer.UnitTests.Mocks; @@ -85,7 +87,7 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( [InlineData("GenPkg.appxmanifest", "GenPkg.appxmanifest")] public void FileIsGenerated(string? specificFn, string outputFn) { - var task = GetNewTask($"testdata/appxmanifest/typical.appxmanifest", generatedFilename: specificFn); + var task = GetNewTask($"testdata/appxmanifest/typical.input.appxmanifest", generatedFilename: specificFn); var success = task.Execute(); @@ -100,7 +102,7 @@ public void ManifestTakesPriority() var appIcon = MockTaskItem.CreateAppIcon("images/camera.svg", "images/loginbg.png"); var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_logo.svg", "#FFFFFF"); - var inputFilename = $"testdata/appxmanifest/typical.appxmanifest"; + var inputFilename = $"testdata/appxmanifest/manifestTakesPriority.input.appxmanifest"; var task = GetNewTask(inputFilename, applicationId: "com.contoso.myapp", displayVersion: "2.5", @@ -112,28 +114,17 @@ public void ManifestTakesPriority() var success = task.Execute(); Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); - var outputFilename = Path.Combine(DestinationDirectory, "Package.appxmanifest"); - var expectedFilename = $"testdata/appxmanifest/typical.expected.appxmanifest"; - - var outputDoc = XDocument.Load(outputFilename); - var expectedDoc = XDocument.Load(expectedFilename); - - if (!XNode.DeepEquals(outputDoc, expectedDoc)) - { - Assert.Equal(expectedDoc.ToString(), outputDoc.ToString()); - } + AssertExpectedManifest(task, inputFilename); } [Fact] public void CorrectGenerationWhenUserSpecifyBackgroundColor() { - var input = "empty"; - var expected = "typicalWithNoBackground"; var appIcon = MockTaskItem.CreateAppIcon("images/appicon.svg", "images/appiconfg.svg"); appIcon.SetMetadata("Color", "#FFFFFF"); var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_bot.svg", "#FFFFFF"); - var inputFilename = $"testdata/appxmanifest/{input}.appxmanifest"; + var inputFilename = $"testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.input.appxmanifest"; var task = GetNewTask(inputFilename, applicationId: "com.contoso.myapp", displayVersion: "1.0.0", @@ -143,30 +134,18 @@ public void CorrectGenerationWhenUserSpecifyBackgroundColor() splashScreen: splashScreen); var success = task.Execute(); - Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); - var outputFilename = Path.Combine(DestinationDirectory, "Package.appxmanifest"); - var expectedFilename = $"testdata/appxmanifest/{expected}.appxmanifest"; - - var outputDoc = XDocument.Load(outputFilename); - var expectedDoc = XDocument.Load(expectedFilename); - - if (!XNode.DeepEquals(outputDoc, expectedDoc)) - { - Assert.Equal(expectedDoc.ToString(), outputDoc.ToString()); - } + Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); + AssertExpectedManifest(task, inputFilename); } [Fact] - public void CorrectGenerationWhitOutBackgroundColor() + public void CorrectGenerationWithOutBackgroundColor() { - var input = "typical"; - var expected = "typical"; - var appIcon = MockTaskItem.CreateAppIcon("images/appicon.svg", "images/appiconfg.svg"); var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_bot.svg", "#FFFFFF"); - var inputFilename = $"testdata/appxmanifest/{input}.appxmanifest"; + var inputFilename = $"testdata/appxmanifest/correctGenerationWithOutBackgroundColor.input.appxmanifest"; var task = GetNewTask(inputFilename, applicationId: "com.contoso.myapp", displayVersion: "1.0.0", @@ -178,16 +157,7 @@ public void CorrectGenerationWhitOutBackgroundColor() var success = task.Execute(); Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); - var outputFilename = Path.Combine(DestinationDirectory, "Package.appxmanifest"); - var expectedFilename = $"testdata/appxmanifest/{expected}.appxmanifest"; - - var outputDoc = XDocument.Load(outputFilename); - var expectedDoc = XDocument.Load(expectedFilename); - - if (!XNode.DeepEquals(outputDoc, expectedDoc)) - { - Assert.Equal(expectedDoc.ToString(), outputDoc.ToString()); - } + AssertExpectedManifest(task, inputFilename); } [Theory] @@ -219,7 +189,7 @@ public void TaskShouldFileAWarningIfMoreThanOneManifestIsProvided() { // Arrange var taskItem = new TaskItem("testdata/appxmanifest/typical.appxmanifest"); - var task = GetNewTask(appxManifests: new [] {taskItem, taskItem}); + var task = GetNewTask(appxManifests: new[] { taskItem, taskItem }); // Act task.Execute(); @@ -242,7 +212,7 @@ public void TaskShouldNotDuplicateTargetVersions() task.Execute(); // Assert - AssertExpectedManifest(task.GeneratedAppxManifest.ItemSpec, taskItem.ItemSpec); + AssertExpectedManifest(task, taskItem); } [Theory] @@ -270,9 +240,7 @@ public void GeneratesExpectedAppxManifest(string manifestName) task.Execute(); // Assert - Assert.False(task.Log.HasLoggedErrors); - Assert.NotNull(task.GeneratedAppxManifest); - AssertExpectedManifest(task.GeneratedAppxManifest.ItemSpec, taskItem.ItemSpec); + AssertExpectedManifest(task, taskItem); } [Fact] @@ -310,12 +278,22 @@ public void TaskShouldBeAbleToOverwriteAppxManifest() } } - static void AssertExpectedManifest(string generatedManifestPath, string inputManifestPath) + static void AssertExpectedManifest(GeneratePackageAppxManifest_v0 task, string inputManifest) => + AssertExpectedManifest(task, new TaskItem(inputManifest)); + + static void AssertExpectedManifest(GeneratePackageAppxManifest_v0 task, ITaskItem inputManifest) { - var generated = XDocument.Load(generatedManifestPath).ToString(); - var expected = XDocument.Load(inputManifestPath.Replace(".input.", ".expected.")).ToString(); + Assert.False(task.Log.HasLoggedErrors); + Assert.NotNull(task.GeneratedAppxManifest); + + var generated = File.ReadAllText(task.GeneratedAppxManifest.ItemSpec); + var expectedFile = inputManifest.ItemSpec.Replace(".input.", ".expected."); +#if WRITE_EXPECTED + File.WriteAllText(expectedFile, generated); +#endif + var expected = File.ReadAllText(expectedFile); - Assert.Equal(expected, generated); + Assert.Equal(expected, generated, ignoreLineEndingDifferences: true, ignoreWhiteSpaceDifferences: true); } } } diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest new file mode 100644 index 00000000..98ecd530 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest @@ -0,0 +1,33 @@ + + + + + Uno Platform + Sample App + images\appiconStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.input.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.input.appxmanifest new file mode 100644 index 00000000..2377e8b4 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.input.appxmanifest @@ -0,0 +1,24 @@ + + + + + Uno Platform + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typical.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.expected.appxmanifest similarity index 78% rename from src/Resizetizer/test/UnitTests/testdata/appxmanifest/typical.expected.appxmanifest rename to src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.expected.appxmanifest index 86134363..1bc845aa 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/typical.expected.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.expected.appxmanifest @@ -1,42 +1,35 @@ - - - - - Uno Platform - Sample App - images\appiconStoreLogo.png - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Uno Platform + Sample App + images\appiconStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.input.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.input.appxmanifest new file mode 100644 index 00000000..458ae418 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.input.appxmanifest @@ -0,0 +1,36 @@ + + + + + Uno Platform + Sample App + images\appiconStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/duplicate-versions.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/duplicate-versions.expected.appxmanifest index 9b443c01..a43047d1 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/duplicate-versions.expected.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/duplicate-versions.expected.appxmanifest @@ -1,28 +1,28 @@ - + - - - Uno.Themes.WinUI.Samples - Uno.Themes.WinUI.Samples - - - - - - - - - - - - - - - - - - - - - + + + Uno.Themes.WinUI.Samples + Uno.Themes.WinUI.Samples + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest new file mode 100644 index 00000000..1bc845aa --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest @@ -0,0 +1,35 @@ + + + + + Uno Platform + Sample App + images\appiconStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.input.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.input.appxmanifest new file mode 100644 index 00000000..458ae418 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.input.appxmanifest @@ -0,0 +1,36 @@ + + + + + Uno Platform + Sample App + images\appiconStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest index ec1056a7..64afd5e1 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest @@ -1,33 +1,33 @@ - - - - - Uno Platform - Sample App - images\cameraStoreLogo.png - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Uno Platform + Sample App + images\cameraStoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From f563024cdc240664562aa2779905331400f720ea Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 17:16:40 -0600 Subject: [PATCH 05/11] fix: use correct uap namespace --- .../src/GeneratePackageAppxManifest.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index dc0b061e..52223c2f 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -16,6 +16,8 @@ public class GeneratePackageAppxManifest_v0 : Task const string PackageVersionPlaceholder = "0.0.0.0"; const string ImageExtension = ".png"; + const string UapNamespace = "http://schemas.microsoft.com/appx/manifest/uap/windows10"; + const string ErrorVersionNumberCombination = "ApplicationDisplayVersion '{0}' was not a valid 3 part semver version number and/or ApplicationVersion '{1}' was not a valid integer."; [Required] @@ -117,7 +119,11 @@ void UpdateManifest(XDocument appx) var appIconInfo = AppIcon?.Length > 0 ? ResizeImageInfo.Parse(AppIcon[0]) : null; var splashInfo = SplashScreen?.Length > 0 ? ResizeImageInfo.Parse(SplashScreen[0]) : null; - var xmlns = appx.Root!.GetDefaultNamespace(); + var uapXmlns = appx.Root.Attributes() + .Where(a => a.IsNamespaceDeclaration && a.Value == UapNamespace) + .Select(a => XNamespace.Get(a.Value)) + .FirstOrDefault(); + var xmlns = appx.Root!.GetDefaultNamespace(); // // @@ -189,7 +195,7 @@ void UpdateManifest(XDocument appx) } // - var xvisual = xmlns + "VisualElements"; + var xvisual = uapXmlns + "VisualElements"; var visual = application.Element(xvisual); if (visual == null) { @@ -198,7 +204,7 @@ void UpdateManifest(XDocument appx) } // - var xtile = xmlns + "DefaultTile"; + var xtile = uapXmlns + "DefaultTile"; var tile = visual.Element(xtile); if (tile == null) { @@ -207,7 +213,7 @@ void UpdateManifest(XDocument appx) } // - var xshowname = xmlns + "ShowNameOnTiles"; + var xshowname = uapXmlns + "ShowNameOnTiles"; var showname = tile.Element(xshowname); if (showname == null) { @@ -250,7 +256,7 @@ void UpdateManifest(XDocument appx) if (splashInfo != null) { // - var xsplash = xmlns + "SplashScreen"; + var xsplash = uapXmlns + "SplashScreen"; var splash = visual.Element(xsplash); if (splash == null) { From 789eeb186e4a997e0badd2f88596d91305e1c1b8 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 17:18:58 -0600 Subject: [PATCH 06/11] chore: normalize line endings --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index 52223c2f..d5ea0954 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -119,11 +119,11 @@ void UpdateManifest(XDocument appx) var appIconInfo = AppIcon?.Length > 0 ? ResizeImageInfo.Parse(AppIcon[0]) : null; var splashInfo = SplashScreen?.Length > 0 ? ResizeImageInfo.Parse(SplashScreen[0]) : null; - var uapXmlns = appx.Root.Attributes() - .Where(a => a.IsNamespaceDeclaration && a.Value == UapNamespace) + var uapXmlns = appx.Root.Attributes() + .Where(a => a.IsNamespaceDeclaration && a.Value == UapNamespace) .Select(a => XNamespace.Get(a.Value)) - .FirstOrDefault(); - var xmlns = appx.Root!.GetDefaultNamespace(); + .FirstOrDefault(); + var xmlns = appx.Root!.GetDefaultNamespace(); // // From 18915f1c528472290344770cd47c5e7e56d6283d Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 17:19:44 -0600 Subject: [PATCH 07/11] chore: revert naming --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index d5ea0954..73c334f8 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -119,7 +119,7 @@ void UpdateManifest(XDocument appx) var appIconInfo = AppIcon?.Length > 0 ? ResizeImageInfo.Parse(AppIcon[0]) : null; var splashInfo = SplashScreen?.Length > 0 ? ResizeImageInfo.Parse(SplashScreen[0]) : null; - var uapXmlns = appx.Root.Attributes() + var xmlnsUap = appx.Root.Attributes() .Where(a => a.IsNamespaceDeclaration && a.Value == UapNamespace) .Select(a => XNamespace.Get(a.Value)) .FirstOrDefault(); @@ -195,7 +195,7 @@ void UpdateManifest(XDocument appx) } // - var xvisual = uapXmlns + "VisualElements"; + var xvisual = xmlnsUap + "VisualElements"; var visual = application.Element(xvisual); if (visual == null) { @@ -204,7 +204,7 @@ void UpdateManifest(XDocument appx) } // - var xtile = uapXmlns + "DefaultTile"; + var xtile = xmlnsUap + "DefaultTile"; var tile = visual.Element(xtile); if (tile == null) { @@ -213,7 +213,7 @@ void UpdateManifest(XDocument appx) } // - var xshowname = uapXmlns + "ShowNameOnTiles"; + var xshowname = xmlnsUap + "ShowNameOnTiles"; var showname = tile.Element(xshowname); if (showname == null) { @@ -256,7 +256,7 @@ void UpdateManifest(XDocument appx) if (splashInfo != null) { // - var xsplash = uapXmlns + "SplashScreen"; + var xsplash = xmlnsUap + "SplashScreen"; var splash = visual.Element(xsplash); if (splash == null) { From dc0b2bdc140bce4a3b4afb0d64e449860dfac832 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 17:30:07 -0600 Subject: [PATCH 08/11] ci: adding GitHub logging --- .github/workflows/ci.yml | 4 ++-- src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bc28a239..82c6a1ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: - name: Build - CI run: | $adjustedPackageVersion="${{ steps.gitversion.outputs.semVer }}".ToLower(); - dotnet pack -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} -o .\artifacts src/Resizetizer/src/Resizetizer.csproj + dotnet pack -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} -o .\artifacts src/Resizetizer/src/Resizetizer.csproj - name: Upload Artifacts uses: actions/upload-artifact@v4 @@ -72,7 +72,7 @@ jobs: - name: Run UnitTests run: | - dotnet test src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj + dotnet test src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj -c Release -p:PackageVersion=$adjustedPackageVersion -p:Version=${{ steps.gitversion.outputs.assemblySemVer }} --logger GitHubActions --blame-crash --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover validation_5_2: name: Validate 5.2 Samples diff --git a/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj b/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj index a7bd72a0..475889be 100644 --- a/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj +++ b/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj @@ -10,6 +10,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From d00756a8828ab6bf5e1821ff67bdcca20339b924 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 20:59:23 -0600 Subject: [PATCH 09/11] chore: fixing ShowOn xmlns --- src/Resizetizer/src/GeneratePackageAppxManifest.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index 73c334f8..24d3dd0b 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -97,6 +97,7 @@ public override bool Execute() { Indent = true, Encoding = writer.Encoding, + NamespaceHandling = NamespaceHandling.OmitDuplicates, OmitXmlDeclaration = false // Ensure the XML declaration is included }; @@ -240,7 +241,7 @@ void UpdateManifest(XDocument appx) UpdateDefaultTileSquare310Logo(tile, appIconInfo); // - var xshowon = xmlns + "ShowOn"; + var xshowon = xmlnsUap + "ShowOn"; var showons = showname.Elements(xshowon).ToArray(); if (showons.All(x => x.Attribute("Tile")?.Value != "square150x150Logo")) { From 050e6b237d2552e69dd70d805073be5a0cea6684 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 21:02:28 -0600 Subject: [PATCH 10/11] chore: fixing expected output --- ...rationWhenUserSpecifyBackgroundColor.expected.appxmanifest | 4 ++-- ...rectGenerationWithOutBackgroundColor.expected.appxmanifest | 2 -- .../appxmanifest/manifestTakesPriority.expected.appxmanifest | 2 -- .../testdata/appxmanifest/template.expected.appxmanifest | 4 ++-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest index 98ecd530..e49f472a 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.expected.appxmanifest @@ -18,8 +18,8 @@ - - + + diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.expected.appxmanifest index 1bc845aa..645e66f0 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.expected.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/correctGenerationWithOutBackgroundColor.expected.appxmanifest @@ -20,8 +20,6 @@ - - diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest index 1bc845aa..645e66f0 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/manifestTakesPriority.expected.appxmanifest @@ -20,8 +20,6 @@ - - diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest index 64afd5e1..1a3e3f18 100644 --- a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/template.expected.appxmanifest @@ -18,8 +18,8 @@ - - + + From 91cdad50ff88bf33bf5614355a7877e1f2112d27 Mon Sep 17 00:00:00 2001 From: Dan Siegel Date: Tue, 18 Jun 2024 22:02:03 -0600 Subject: [PATCH 11/11] fix: uno 17199 --- .../Uno.Resizetizer.windows.skia.targets | 2 +- .../src/GeneratePackageAppxManifest.cs | 8 +- .../GeneratePackageAppxManifestTests.cs | 194 ++++++++++++------ .../test/UnitTests/MSBuildTaskFixture.cs | 43 +++- .../unoIssue17199.expected.appxmanifest | 32 +++ .../unoIssue17199.input.appxmanifest | 22 ++ 6 files changed, 226 insertions(+), 75 deletions(-) create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.expected.appxmanifest create mode 100644 src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.input.appxmanifest diff --git a/src/.nuspec/Uno.Resizetizer.windows.skia.targets b/src/.nuspec/Uno.Resizetizer.windows.skia.targets index 53264b3f..f2c28b26 100644 --- a/src/.nuspec/Uno.Resizetizer.windows.skia.targets +++ b/src/.nuspec/Uno.Resizetizer.windows.skia.targets @@ -21,7 +21,7 @@ diff --git a/src/Resizetizer/src/GeneratePackageAppxManifest.cs b/src/Resizetizer/src/GeneratePackageAppxManifest.cs index 24d3dd0b..b992a181 100644 --- a/src/Resizetizer/src/GeneratePackageAppxManifest.cs +++ b/src/Resizetizer/src/GeneratePackageAppxManifest.cs @@ -513,10 +513,10 @@ private static void SetDependencyTargetDeviceFamily(XDocument appx, string targe if (targetDeviceFamilyElements is null || !targetDeviceFamilyElements.Any()) { var universal = new XElement(xmlns + "TargetDeviceFamily"); - universal.SetAttributeValue(xmlns + "Name", "Windows.Universal"); + universal.SetAttributeValue("Name", "Windows.Universal"); var desktop = new XElement(xmlns + "TargetDeviceFamily"); - desktop.SetAttributeValue(xmlns + "Name", "Windows.Desktop"); + desktop.SetAttributeValue("Name", "Windows.Desktop"); dependencies.Add(universal, desktop); targetDeviceFamilyElements = [universal, desktop]; @@ -524,8 +524,8 @@ private static void SetDependencyTargetDeviceFamily(XDocument appx, string targe foreach (var target in targetDeviceFamilyElements) { - SetVersion(target, xmlns + "MinVersion", targetPlatformMinVersion); - SetVersion(target, xmlns + "MaxVersionTested", targetPlatformVersion); + SetVersion(target, "MinVersion", targetPlatformMinVersion); + SetVersion(target, "MaxVersionTested", targetPlatformVersion); } } diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index c05cd155..2517f4a5 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -4,62 +4,89 @@ using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using Resizetizer.UnitTests.Mocks; -using System; -using System.Collections; -using System.Collections.Generic; using System.IO; using System.Linq; using System.Xml.Linq; using Xunit; +using Xunit.Abstractions; namespace Uno.Resizetizer.Tests -{ - public class GeneratePackageAppxManifestTests : MSBuildTaskTestFixture - { +{ + public class GeneratePackageAppxManifestTests(ITestOutputHelper testOutput) : MSBuildTaskTestFixture(testOutput) + { + protected GeneratePackageAppxManifest_v0 GetNewTask( + string appxManifest, + string? generatedFilename = null, + string? applicationId = null, + string? applicationDisplayVersion = null, + string? applicationVersion = null, + string? applicationTitle = null, + string? description = null, + string? applicationPublisher = null, + ITaskItem? appIcon = null, + ITaskItem? splashScreen = null, + string? targetPlatformVersion = null, + string? targetPlatformMinVersion = null, + string? authors = null) => + GetNewTask( + [new TaskItem(appxManifest)], + generatedFilename, + applicationId, + applicationDisplayVersion, + applicationVersion, + applicationTitle, + description, + applicationPublisher, + appIcon, + splashScreen, + targetPlatformVersion, + targetPlatformMinVersion, + authors); + protected GeneratePackageAppxManifest_v0 GetNewTask( - string manifest, + ITaskItem appxManifest, string? generatedFilename = null, string? applicationId = null, - string? displayVersion = null, - string? version = null, - string? displayName = null, + string? applicationDisplayVersion = null, + string? applicationVersion = null, + string? applicationTitle = null, string? description = null, string? applicationPublisher = null, ITaskItem? appIcon = null, - ITaskItem? splashScreen = null) - { - return new() - { - IntermediateOutputPath = DestinationDirectory, - BuildEngine = this, - GeneratedFilename = generatedFilename, - AppxManifest = [new TaskItem(manifest)], - ApplicationId = applicationId, - ApplicationDisplayVersion = displayVersion, - ApplicationVersion = version, - ApplicationTitle = displayName, - AssemblyName = GetType().Assembly.FullName, - Description = description, - ApplicationPublisher = applicationPublisher, - AppIcon = appIcon == null ? null : [appIcon], - SplashScreen = splashScreen == null ? null : [splashScreen], - TargetFramework = "windows" - }; - } + ITaskItem? splashScreen = null, + string? targetPlatformVersion = null, + string? targetPlatformMinVersion = null, + string? authors = null) => + GetNewTask( + [appxManifest], + generatedFilename, + applicationId, + applicationDisplayVersion, + applicationVersion, + applicationTitle, + description, + applicationPublisher, + appIcon, + splashScreen, + targetPlatformVersion, + targetPlatformMinVersion, + authors); + protected GeneratePackageAppxManifest_v0 GetNewTask( - ITaskItem[] appxManifests, - string? generatedFilename = null, - string? applicationId = null, - string? displayVersion = null, - string? version = null, - string? displayName = null, - string? description = null, - string? applicationPublisher = null, - ITaskItem? appIcon = null, - ITaskItem? splashScreen = null, - string? targetPlatformVersion = null, - string? targetPlatformMinVersion = null) + ITaskItem[] appxManifests, + string? generatedFilename = null, + string? applicationId = null, + string? applicationDisplayVersion = null, + string? applicationVersion = null, + string? applicationTitle = null, + string? description = null, + string? applicationPublisher = null, + ITaskItem? appIcon = null, + ITaskItem? splashScreen = null, + string? targetPlatformVersion = null, + string? targetPlatformMinVersion = null, + string? authors = null) { return new() { @@ -68,15 +95,16 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( GeneratedFilename = generatedFilename, AppxManifest = appxManifests, ApplicationId = applicationId, - ApplicationDisplayVersion = displayVersion, - ApplicationVersion = version, - ApplicationTitle = displayName, + ApplicationDisplayVersion = applicationDisplayVersion, + ApplicationVersion = applicationVersion, + ApplicationTitle = applicationTitle, Description = description, ApplicationPublisher = applicationPublisher, AssemblyName = GetType().Assembly.GetName().Name, AppIcon = appIcon == null ? null : [appIcon], SplashScreen = splashScreen == null ? null : [splashScreen], TargetFramework = "windows", + Authors = authors, TargetPlatformVersion = targetPlatformVersion, TargetPlatformMinVersion = targetPlatformMinVersion }; @@ -87,7 +115,7 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( [InlineData("GenPkg.appxmanifest", "GenPkg.appxmanifest")] public void FileIsGenerated(string? specificFn, string outputFn) { - var task = GetNewTask($"testdata/appxmanifest/typical.input.appxmanifest", generatedFilename: specificFn); + var task = GetNewTask($"testdata/appxmanifest/typical.appxmanifest", generatedFilename: specificFn); var success = task.Execute(); @@ -105,9 +133,9 @@ public void ManifestTakesPriority() var inputFilename = $"testdata/appxmanifest/manifestTakesPriority.input.appxmanifest"; var task = GetNewTask(inputFilename, applicationId: "com.contoso.myapp", - displayVersion: "2.5", - version: "3", - displayName: "Fishy Things", + applicationDisplayVersion: "2.5", + applicationVersion: "3", + applicationTitle: "Fishy Things", appIcon: appIcon, splashScreen: splashScreen); @@ -127,9 +155,9 @@ public void CorrectGenerationWhenUserSpecifyBackgroundColor() var inputFilename = $"testdata/appxmanifest/correctGenerationWhenUserSpecifyBackgroundColor.input.appxmanifest"; var task = GetNewTask(inputFilename, applicationId: "com.contoso.myapp", - displayVersion: "1.0.0", - version: "1", - displayName: "Sample App", + applicationDisplayVersion: "1.0.0", + applicationVersion: "1", + applicationTitle: "Sample App", appIcon: appIcon, splashScreen: splashScreen); @@ -148,9 +176,9 @@ public void CorrectGenerationWithOutBackgroundColor() var inputFilename = $"testdata/appxmanifest/correctGenerationWithOutBackgroundColor.input.appxmanifest"; var task = GetNewTask(inputFilename, applicationId: "com.contoso.myapp", - displayVersion: "1.0.0", - version: "1", - displayName: "Sample App", + applicationDisplayVersion: "1.0.0", + applicationVersion: "1", + applicationTitle: "Sample App", appIcon: appIcon, splashScreen: splashScreen); @@ -189,7 +217,7 @@ public void TaskShouldFileAWarningIfMoreThanOneManifestIsProvided() { // Arrange var taskItem = new TaskItem("testdata/appxmanifest/typical.appxmanifest"); - var task = GetNewTask(appxManifests: new[] { taskItem, taskItem }); + var task = GetNewTask(appxManifests: [taskItem, taskItem]); // Act task.Execute(); @@ -223,13 +251,13 @@ public void GeneratesExpectedAppxManifest(string manifestName) var appIcon = MockTaskItem.CreateAppIcon("images/camera.svg", "images/loginbg.png"); var splashScreen = MockTaskItem.CreateSplashScreen("images/dotnet_logo.svg", "#FFFFFF"); - var taskItem = new TaskItem($"testdata/appxmanifest/{manifestName}.input.appxmanifest"); + var taskItem = $"testdata/appxmanifest/{manifestName}.input.appxmanifest"; var task = GetNewTask( - appxManifests: [taskItem], + appxManifest: taskItem, applicationId: "com.contoso.myapp", - displayVersion: "1.0.0", - version: "1", - displayName: "Sample App", + applicationDisplayVersion: "1.0.0", + applicationVersion: "1", + applicationTitle: "Sample App", description: "This is a sample from the Unit Tests", appIcon: appIcon, splashScreen: splashScreen, @@ -247,11 +275,11 @@ public void GeneratesExpectedAppxManifest(string manifestName) public void TaskShouldBeAbleToOverwriteAppxManifest() { // Arrange - var taskItem = new TaskItem("testdata/appxmanifest/empty.appxmanifest"); + var taskItem = "testdata/appxmanifest/empty.appxmanifest"; var task = GetNewTask( - appxManifests: [taskItem], - displayVersion: "1.0.0", - version: "1", + appxManifest: taskItem, + applicationDisplayVersion: "1.0.0", + applicationVersion: "1", targetPlatformVersion: "10.0.19041.0", targetPlatformMinVersion: "10.0.17763.0"); @@ -278,6 +306,42 @@ public void TaskShouldBeAbleToOverwriteAppxManifest() } } + [Fact] + public void UnoIssue17199() + { + var appIcon = MockTaskItem.CreateAppIcon(@"images\appicon.svg", @"images\appiconfg.svg"); + appIcon.SetMetadata("ForegroundScale", "0.65"); + appIcon.SetMetadata("Color", "#00000000"); + appIcon.SetMetadata("IsDefaultItem", "true"); + + var splashScreen = MockTaskItem.CreateSplashScreen(@"images\dotnet_bot.svg"); + splashScreen.SetMetadata("BaseSize", "128,128"); + + var inputFile = "testdata/appxmanifest/unoIssue17199.input.appxmanifest"; + + var task = GetNewTask( + appxManifest: inputFile, + applicationTitle: "Sample App", + description: "SampleApp powered by Uno Platform", + applicationVersion: "1", + applicationPublisher: "Uno Platform", + applicationDisplayVersion: "1.0", + targetPlatformVersion: "10.0.19041.0", + targetPlatformMinVersion: "10.0.18362.0", + applicationId: "com.contoso.sampleapp", + authors: "Uno Platform", + appIcon: appIcon, + splashScreen: splashScreen + ); + + // Act + task.Execute(); + + // Assert + AssertExpectedManifest(task, inputFile); + + } + static void AssertExpectedManifest(GeneratePackageAppxManifest_v0 task, string inputManifest) => AssertExpectedManifest(task, new TaskItem(inputManifest)); diff --git a/src/Resizetizer/test/UnitTests/MSBuildTaskFixture.cs b/src/Resizetizer/test/UnitTests/MSBuildTaskFixture.cs index eb20c49d..6cc57bc3 100644 --- a/src/Resizetizer/test/UnitTests/MSBuildTaskFixture.cs +++ b/src/Resizetizer/test/UnitTests/MSBuildTaskFixture.cs @@ -1,13 +1,24 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Reflection.Metadata.Ecma335; using Microsoft.Build.Framework; +using Xunit.Abstractions; namespace Uno.Resizetizer.Tests { public abstract class MSBuildTaskTestFixture : BaseTest, IBuildEngine - where TTask : Microsoft.Build.Framework.ITask + where TTask : Microsoft.Build.Framework.ITask, new() { + private readonly ITestOutputHelper? _testOutputHelper; + + protected MSBuildTaskTestFixture() { } + + protected MSBuildTaskTestFixture(ITestOutputHelper testOutputHelper) + { + _testOutputHelper = testOutputHelper; + } + protected readonly TestLogger Logger; protected List LogErrorEvents = new List(); @@ -27,12 +38,34 @@ public abstract class MSBuildTaskTestFixture : BaseTest, IBuildEngine bool IBuildEngine.BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs) => throw new NotImplementedException(); - void IBuildEngine.LogCustomEvent(CustomBuildEventArgs e) => LogCustomEvents.Add(e); + void IBuildEngine.LogCustomEvent(CustomBuildEventArgs e) + { + _testOutputHelper?.WriteLine("CUSTOM - ({0}) {1}: {2}", e.SenderName, e.Timestamp, e.Message); + LogCustomEvents.Add(e); + } + + void IBuildEngine.LogErrorEvent(BuildErrorEventArgs e) + { + _testOutputHelper?.WriteLine("ERROR - ({0}) {1}: {2}", e.SenderName, e.Timestamp, e.Message); + LogErrorEvents.Add(e); + } - void IBuildEngine.LogErrorEvent(BuildErrorEventArgs e) => LogErrorEvents.Add(e); + void IBuildEngine.LogMessageEvent(BuildMessageEventArgs e) + { + _testOutputHelper?.WriteLine("LOG - ({0}) {1}: {2}", e.SenderName, e.Timestamp, e.Message); + LogMessageEvents.Add(e); + } - void IBuildEngine.LogMessageEvent(BuildMessageEventArgs e) => LogMessageEvents.Add(e); + void IBuildEngine.LogWarningEvent(BuildWarningEventArgs e) + { + _testOutputHelper?.WriteLine("WARNING - ({0}) {1}: {2}", e.SenderName, e.Timestamp, e.Message); + LogWarningEvents.Add(e); + } - void IBuildEngine.LogWarningEvent(BuildWarningEventArgs e) => LogWarningEvents.Add(e); + protected TTask CreateTask() => + new() + { + BuildEngine = this, + }; } } \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.expected.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.expected.appxmanifest new file mode 100644 index 00000000..67489f2b --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.expected.appxmanifest @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + Sample App + Uno Platform + images\appiconStoreLogo.png + + \ No newline at end of file diff --git a/src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.input.appxmanifest b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.input.appxmanifest new file mode 100644 index 00000000..7d40f4b6 --- /dev/null +++ b/src/Resizetizer/test/UnitTests/testdata/appxmanifest/unoIssue17199.input.appxmanifest @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + +