From 10ded15eede002301dc07347a824490531d5a8e5 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Wed, 31 Jan 2024 18:42:30 -0300 Subject: [PATCH] test: create a test to validate the change --- .../GeneratePackageAppxManifestTests.cs | 50 ++++++++++++++-- .../UnitTests/Resizetizer.UnitTests.csproj | 59 ++++++++++--------- 2 files changed, 76 insertions(+), 33 deletions(-) diff --git a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs index 58966c12..3499f030 100644 --- a/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs +++ b/src/Resizetizer/test/UnitTests/GeneratePackageAppxManifestTests.cs @@ -1,7 +1,8 @@ #nullable enable using Microsoft.Build.Framework; using Microsoft.Build.Utilities; -using System.Collections.Generic; +using System; +using System.Collections; using System.IO; using System.Linq; using System.Xml.Linq; @@ -26,13 +27,39 @@ protected GeneratePackageAppxManifest_v0 GetNewTask( IntermediateOutputPath = DestinationDirectory, BuildEngine = this, GeneratedFilename = generatedFilename, - AppxManifest = new TaskItem(manifest), + AppxManifest = [new TaskItem(manifest)], ApplicationId = guid, ApplicationDisplayVersion = displayVersion, ApplicationVersion = version, ApplicationTitle = displayName, - AppIcon = appIcon == null ? null : new[] { appIcon }, - SplashScreen = splashScreen == null ? null : new[] { splashScreen }, + AppIcon = appIcon == null ? null : [appIcon], + SplashScreen = splashScreen == null ? null : [splashScreen], + TargetFramework = "windows" + }; + } + + protected GeneratePackageAppxManifest_v0 GetNewTask( + ITaskItem[] appxManifests, + string? generatedFilename = null, + string? guid = null, + string? displayVersion = null, + string? version = null, + string? displayName = null, + ITaskItem? appIcon = null, + ITaskItem? splashScreen = null) + { + return new() + { + IntermediateOutputPath = DestinationDirectory, + BuildEngine = this, + GeneratedFilename = generatedFilename, + AppxManifest = appxManifests, + ApplicationId = guid, + ApplicationDisplayVersion = displayVersion, + ApplicationVersion = version, + ApplicationTitle = displayName, + AppIcon = appIcon == null ? null : [appIcon], + SplashScreen = splashScreen == null ? null : [splashScreen], TargetFramework = "windows" }; } @@ -45,6 +72,7 @@ public void FileIsGenerated(string? specificFn, string outputFn) var task = GetNewTask($"testdata/appxmanifest/typical.appxmanifest", generatedFilename: specificFn); var success = task.Execute(); + Assert.True(success, $"{task.GetType()}.Execute() failed: " + LogErrorEvents.FirstOrDefault()?.Message); Assert.True(File.Exists(Path.Combine(DestinationDirectory, outputFn)), "Package.appxmanifest file was not generated."); @@ -183,5 +211,19 @@ public void InvalidMergeVersionNumbers(string displayVersion, string appVersion) var result = GeneratePackageAppxManifest_v0.TryMergeVersionNumbers(displayVersion, appVersion, out var merged); Assert.False(result); } + + [Fact] + public void TaskShouldFileAWarningIfMoreThanOneManifestIsProvided() + { + // Arrange + var taskItem = new TaskItem("testdata/appxmanifest/typical.appxmanifest"); + var task = GetNewTask(appxManifests: [taskItem, taskItem]); + + // Act + task.Execute(); + + // Assert + Assert.True(LogWarningEvents.Count > 0, "Warnings should be greater than zero"); + } } } diff --git a/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj b/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj index 44545ef8..17fee812 100644 --- a/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj +++ b/src/Resizetizer/test/UnitTests/Resizetizer.UnitTests.csproj @@ -1,36 +1,37 @@  - - net7.0 - Uno.Resizetizer.UnitTests - false - $(DefineConstants);WINDOWS - Debug;Release;DEBUG_RESIZETIZER - + + net7.0 + Uno.Resizetizer.UnitTests + false + $(DefineConstants);WINDOWS + Debug;Release;DEBUG_RESIZETIZER + latest + - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - - + + + - - - - - + + + + +